diff --git a/composer.json b/composer.json index 338dac0..181b901 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "fof/sitemap", + "name": "sergiorodenas/flarum-sitemap", "description": "Generate a sitemap", "keywords": [ "extension", diff --git a/extend.php b/extend.php index f87eb82..d5f2ef0 100644 --- a/extend.php +++ b/extend.php @@ -59,4 +59,7 @@ (new Extend\Event()) ->subscribe(Listeners\SettingsListener::class), + + (new Extend\Frontend('forum')) + ->content(Listeners\NoIndexListener::class), ]; diff --git a/src/Listeners/NoIndexListener.php b/src/Listeners/NoIndexListener.php new file mode 100644 index 0000000..776edee --- /dev/null +++ b/src/Listeners/NoIndexListener.php @@ -0,0 +1,49 @@ +extensionManager->isEnabled('flarum-tags')){ + return; + } + + $type = Arr::get($document->getForumApiDocument(), 'data.type'); + + if($type != 'discussions'){ + return; + } + + $tags = Arr::get($document->getForumApiDocument(), 'data.relationships.tags.data'); + + foreach($tags as $tag){ + if(in_array($tag['id'], $noIndexTags)){ + $document->head[] = ''; + return; + } + } + } +} diff --git a/src/Resources/Discussion.php b/src/Resources/Discussion.php index 39e4922..57bd820 100644 --- a/src/Resources/Discussion.php +++ b/src/Resources/Discussion.php @@ -24,6 +24,12 @@ public function query(): Builder { $query = Model::whereVisibleTo(new Guest()); + if(static::$extensionManager->isEnabled('flarum-tags')){ + $query->whereDoesntHave('tags', function($query){ + $query->whereIn('id', [38, 33, 35, 36]); // Add tags here so their discussions aren't included in sitemap + }); + } + if (static::$settings->get('fof-sitemap.riskyPerformanceImprovements')) { // Limiting the number of columns to fetch improves query time // This is a risky optimization because of 2 reasons: