Geta / geta-optimizely-sitemaps

Search engine sitemaps.xml for Optimizely CMS 12 and Commerce 14
Apache License 2.0
10 stars 14 forks source link

Custom ContentFilter is never called #110

Closed bata03 closed 6 months ago

bata03 commented 6 months ago

I've created a custom ContentFilter as described in the documentation:

public class SitemapContentFilter : ContentFilter 
 {

    public SitemapContentFilter(TemplateResolver templateResolver, ILogger<ContentFilter> logger) : base(templateResolver, logger)
    {
    }

    public override bool ShouldExcludeContent(IContent content)
    {
        if (base.ShouldExcludeContent(content))
        {
            return true;
        }

        bool excludeContent = false;

        if (content is BasePageData)
        {
            var basePageData = content as BasePageData;
            excludeContent = basePageData?.DisableIndexing ?? false;
        }

        if (content is DocumentFile)
        {
            var documentFile = content as DocumentFile;
            excludeContent = documentFile?.DisableIndexing ?? false;
        }

        return excludeContent;
    }
}

And I've registered it for DI:

services.AddTransient<IContentFilter, SitemapContentFilter>();

However, the custom filter is never called. What am not seeing? :)

bata03 commented 6 months ago

Sorry, my bad. I called services.AddTransient<IContentFilter, SitemapContentFilter>() before calling services.AddSitemaps() which meant that my ContentFilter DI-entry got overwritten.