From 498913806182905cc0c14bd12a61f9af26fa16b4 Mon Sep 17 00:00:00 2001 From: "David T. Sadler" Date: Mon, 17 Feb 2020 19:59:15 +0000 Subject: Switch over to Jigsaw --- listeners/GenerateSitemap.php | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 listeners/GenerateSitemap.php (limited to 'listeners/GenerateSitemap.php') diff --git a/listeners/GenerateSitemap.php b/listeners/GenerateSitemap.php new file mode 100644 index 0000000..6a439a6 --- /dev/null +++ b/listeners/GenerateSitemap.php @@ -0,0 +1,43 @@ +getConfig('baseUrl'); + + if (! $baseUrl) { + echo("\nTo generate a sitemap.xml file, please specify a 'baseUrl' in config.php.\n\n"); + + return; + } + + $sitemap = new Sitemap($jigsaw->getDestinationPath() . '/sitemap.xml'); + + collect($jigsaw->getOutputPaths()) + ->reject(function ($path) { + return $this->isExcluded($path); + })->each(function ($path) use ($baseUrl, $sitemap) { + $sitemap->addItem(rtrim($baseUrl, '/') . $path, time(), Sitemap::DAILY); + }); + + $sitemap->write(); + } + + public function isExcluded($path) + { + return Str::is($this->exclude, $path); + } +} -- cgit v1.2.3-13-gbd6f