Skip to content

Commit

Permalink
Merge pull request #120 from Geta/feature/default-content-filter
Browse files Browse the repository at this point in the history
Feature/default content filter
  • Loading branch information
Nikola117 authored Jan 10, 2025
2 parents 26a2b34 + 9d8d2f2 commit 469efc8
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Geta.Optimizely.Sitemaps.Configuration
{
public enum SiteArchitecture
{
Mvc,
Headless
}
}
12 changes: 12 additions & 0 deletions src/Geta.Optimizely.Sitemaps/Configuration/SitemapOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ public class SitemapOptions
public bool EnableRealtimeCaching { get; set; } = true;
public bool EnableLanguageDropDownInAdmin { get; set; } = false;

/// <summary>
/// The default is Mvc, this runs a check in the default content filter to ensure there's a page for every piece of content
/// Set this to headless if you are running a headless site to skip the check that ensures the content has an accompanying view
/// </summary>
public SiteArchitecture SiteArchitecture { get; set; } = SiteArchitecture.Mvc;

/// <summary>
/// Enabled by default, this will, when using the default Content Filter, assume that any content that can't be cast to IVersionable is unpublished and not add it to the Sitemap
/// Consider disabling if you are finding that the default content filter is not generating content you're expecting to see in your sitemap
/// </summary>
public bool IsStrictPublishCheckingEnabled { get; set; } = true;

public Type UriAugmenterService { get; set; } = typeof(DefaultUriAugmenterService);

public void SetAugmenterService<T>() where T : class, IUriAugmenterService
Expand Down
23 changes: 15 additions & 8 deletions src/Geta.Optimizely.Sitemaps/Utils/ContentFilter.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
// Copyright (c) Geta Digital. All rights reserved.
// Copyright (c) Geta Digital. All rights reserved.
// Licensed under Apache-2.0. See the LICENSE file in the project root for more information

using System;
using AspNetCore;
using EPiServer.Core;
using EPiServer.Framework.Web;
using EPiServer.Security;
using EPiServer.Web;
using Geta.Optimizely.Sitemaps.Configuration;
using Geta.Optimizely.Sitemaps.Entities;
using Geta.Optimizely.Sitemaps.SpecializedProperties;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;

namespace Geta.Optimizely.Sitemaps.Utils
{
public class ContentFilter : IContentFilter
{
private readonly TemplateResolver _templateResolver;
private readonly ILogger<ContentFilter> _logger;
private readonly SitemapOptions _sitemapOptions;

public ContentFilter(TemplateResolver templateResolver, ILogger<ContentFilter> logger)
public ContentFilter(TemplateResolver templateResolver, ILogger<ContentFilter> logger, IOptions<SitemapOptions> sitemapOptions)
{
_templateResolver = templateResolver;
_logger = logger;
_sitemapOptions = sitemapOptions.Value;
}

public virtual bool ShouldExcludeContent(IContent content)
Expand Down Expand Up @@ -51,9 +56,12 @@ public virtual bool ShouldExcludeContent(IContent content)
return true;
}

if (!IsVisibleOnSite(content))
if (_sitemapOptions.SiteArchitecture == SiteArchitecture.Mvc)
{
return true;
if (!IsVisibleOnSite(content))
{
return true;
}
}

if (content.ContentLink.CompareToIgnoreWorkID(ContentReference.WasteBasket))
Expand All @@ -76,8 +84,7 @@ public virtual bool ShouldExcludeContent(IContent content)
return false;
}

public virtual bool ShouldExcludeContent(
CurrentLanguageContent languageContentInfo, SiteDefinition siteSettings, SitemapData sitemapData)
public virtual bool ShouldExcludeContent(CurrentLanguageContent languageContentInfo, SiteDefinition siteSettings, SitemapData sitemapData)
{
return ShouldExcludeContent(languageContentInfo.Content);
}
Expand Down Expand Up @@ -141,7 +148,7 @@ private bool IsAccessibleToEveryone(IContent content)
return false;
}

private static bool IsPublished(IContent content)
private bool IsPublished(IContent content)
{
if (content is IVersionable versionableContent)
{
Expand All @@ -164,7 +171,7 @@ private static bool IsPublished(IContent content)
return true;
}

return false;
return !_sitemapOptions.IsStrictPublishCheckingEnabled;
}
}
}

0 comments on commit 469efc8

Please sign in to comment.