Search code examples
episerver

How do I exclude specific subfolders within an included folder using Geta Sitemap?


How do I exclude subfolders that match a specific pattern from a sitemap that sit inside an included folder?

For example, I wish to exclude all subfolders matching the following criteria: /Research/Content/Short-reports/*pptx/

While still including all other folders within: /Research/Content/Short-reports/

Geta seems to ignore my wildcard and treats it as literal text.

TIA


Solution

  • Unfortunately Geta only does string matching and won't handle any wildcard/regex.

    Geta does recommend you implement your own IContentFilter for custom filtering.

    If the folders in question are Content Folders in the CMS, one option could be to create a ContentArea property in global settings to hold references to all the folders you wish to exclude. Then, in the ShouldExcludeContent method of your IContentFilter implementation, you can perform a check to see if the content is a descendant of one of the folders you added to the global setting.

    public class MyCustomSitemapContentFilter : Geta.SEO.Sitemaps.Utils.ContentFilter
    {
        public override bool ShouldExcludeContent(IContent content)
        {
            var baseEvaluation = base.ShouldExcludeContent(content);
    
            var shouldExclude = false;
    
            //shouldExclude = code to check if content is 
            //   is descendant of any of the folders referenced
            //   in global setting property
    
            return shouldExclude || baseEvaluation;
        }
    }