pecotamic / sitemap

Sitemap for Statamic v3
6 stars 9 forks source link

Possibility to exclude url by blueprint config? #26

Closed Aquive closed 8 months ago

Aquive commented 9 months ago

Is it possible t o exclude urls based on input from a blueprint?

E.g. when blueprint has set no index = true? If yes, how?

PS: i know i can exclude urls with code, but i want a way for admins to manage it automatically.

werner-freytag commented 9 months ago

An example to exclude noindex entries from the sitemap is already in the comment of the config:

    'filter' => static function ($entry): bool {
        $augmented = $entry->newAugmentedInstance();
        if (!($metaRobots = $augmented->get('meta_robots')) || !is_array($metaRobotsArray = $metaRobots->raw())) {
            return true;
        }

        return !in_array('noindex', $metaRobotsArray, true);
    }

This function checks whether a meta_robots field exists, is an array type, and if it contains 'noindex' as an array value.

Here the page itself is checked. If you want to filter based on the blueprint, you have to adjust the code to read the blueprint of the page.

Aquive commented 8 months ago

Thanks, exactly what I was looking for!