<?php

    use Eae\Support\SitemapGenerator;

    class SitemapController extends Controller
    {
        /**
         * Display the specified resource.
         *
         * @param  string $slug
         * @return Response
         */
        public function index()
        {
            $sitemapFilename = Config::get('path.internal.sitemap') . '/sitemap.xml';

            if (!file_exists($sitemapFilename) || (File::lastModified($sitemapFilename) + 24 * 60 * 60) < time()) {
                $entities = ['Entry', 'Occurrence', 'Story'];
                $sitemapGenerator = new SitemapGenerator($entities);
                $sitemapGenerator->start();
            }

            return Response::make(File::get($sitemapFilename), '200')
                ->header('Content-Type', 'application/xml');
        }
    }
