diff --git a/src/Http/Controllers/SettingsController.php b/src/Http/Controllers/SettingsController.php index 840599b..b4d2159 100644 --- a/src/Http/Controllers/SettingsController.php +++ b/src/Http/Controllers/SettingsController.php @@ -171,6 +171,13 @@ protected function formBlueprint() 'display' => __('seotamic::general.settings_preview_domain_title'), 'instructions' => __('seotamic::general.settings_preview_domain_instructions'), ], + 'headless_mode' => [ + 'type' => 'text', + 'character_limit' => '50', + 'prepend' => 'https://', + 'display' => "Headless Mode", + 'instructions' => "If set this domain will replace the domain for canonical and social url tags. Image links will still be linked to the CMS domain.", + ], 'robots_none' => [ 'type' => 'toggle', 'display' => __('seotamic::general.settings_robots_title'), diff --git a/src/Http/Controllers/SitemapController.php b/src/Http/Controllers/SitemapController.php index ccbd462..bf373dd 100644 --- a/src/Http/Controllers/SitemapController.php +++ b/src/Http/Controllers/SitemapController.php @@ -15,34 +15,34 @@ public function __invoke() $addon = Addon::get('cnj/seotamic'); abort_unless(config('seotamic.sitemap') && $addon->edition() === 'pro', 404); - $entries = Collection::all() - ->flatMap(function ($collection) { - return $collection->cascade('seo') !== false && $collection->cascade('social') !== false - ? $collection->queryEntries()->get() - : collect(); - }) - ->filter(function (Entry $entry) { - return self::shouldBeIndexed($entry); - }) - ->map(function (Entry $entry) { - return [ - 'loc' => $entry->absoluteUrl(), - 'lastmod' => $entry->lastModified()->toAtomString(), - 'alternates' => $entry->sites() - ->map(fn ($site) => $entry->in($site)) - ->filter(function (?Entry $entry) { - return $entry && self::shouldBeIndexed($entry); - }) - ->map(function (Entry $entry) { - return array( - 'lang' => $entry->locale, - 'href' => $entry->absoluteUrl() - ); - }) - ]; - }); + $content = Cache::rememberForever('seotamic_sitemap', function () { + $entries = Collection::all() + ->flatMap(function ($collection) { + return $collection->cascade('seo') !== false && $collection->cascade('social') !== false + ? $collection->queryEntries()->get() + : collect(); + }) + ->filter(function (Entry $entry) { + return self::shouldBeIndexed($entry); + }) + ->map(function (Entry $entry) { + return [ + 'loc' => $entry->absoluteUrl(), + 'lastmod' => $entry->lastModified()->toAtomString(), + 'alternates' => $entry->sites() + ->map(fn ($site) => $entry->in($site)) + ->filter(function (?Entry $entry) { + return $entry && self::shouldBeIndexed($entry); + }) + ->map(function (Entry $entry) { + return array( + 'lang' => $entry->locale, + 'href' => $entry->absoluteUrl() + ); + }) + ]; + }); - $content = Cache::remember('seotamic_sitemap', 1, function () use ($entries) { return view('seotamic::sitemap', [ 'header' => '', 'entries' => $entries, diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php index 957dcbd..2016cfb 100644 --- a/src/ServiceProvider.php +++ b/src/ServiceProvider.php @@ -16,7 +16,7 @@ class ServiceProvider extends AddonServiceProvider { - protected $subscribe = [Subscriber::class]; + protected $subscribe = [Subscriber::class, SitemapSubscriber::class]; protected $commands = [MigrateCommand::class]; diff --git a/src/SitemapSubscriber.php b/src/SitemapSubscriber.php new file mode 100644 index 0000000..5d1b11c --- /dev/null +++ b/src/SitemapSubscriber.php @@ -0,0 +1,35 @@ + + */ + public function subscribe(Dispatcher $events): array + { + return [ + EntrySaved::class => 'flushSitemapCache', + EntryCreated::class => 'flushSitemapCache', + EntryDeleted::class => 'flushSitemapCache', + ]; + } + + /** + * Flush the sitemap cache + * + */ + public function flushSitemapCache() + { + Cache::forget('seotamic_sitemap'); + } +}