From 4942d7d59ea98e33db9846b996f23e0d324ee2f8 Mon Sep 17 00:00:00 2001 From: Tobias Klika Date: Wed, 22 Apr 2026 14:56:00 +0200 Subject: [PATCH] automatically disable search indexing when not in production --- Finch/Metadata/MetadataService.cs | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/Finch/Metadata/MetadataService.cs b/Finch/Metadata/MetadataService.cs index 6d81f1e8..d0acab70 100644 --- a/Finch/Metadata/MetadataService.cs +++ b/Finch/Metadata/MetadataService.cs @@ -1,23 +1,11 @@ -using Microsoft.Extensions.Logging; -using System.Reflection; +using System.Reflection; using System.Text; +using Microsoft.Extensions.Hosting; namespace Finch.Metadata; -public class MetadataService : IMetadataService +public class MetadataService(ILocalizer localizer, IHostEnvironment env) : IMetadataService { - protected ILogger Logger { get; private set; } - - protected ILocalizer Localizer { get; } - - - public MetadataService(ILogger logger, ILocalizer localizer) - { - Logger = logger; - Localizer = localizer; - } - - /// public virtual Metadata Generate(string pageName, MetadataOptions options) { @@ -33,7 +21,13 @@ public class MetadataService : IMetadataService // generate robots bool noIndex = options.NoIndex ?? false; bool noFollow = options.NoFollow ?? false; - model.Robots = string.Format("{0},{1}", noIndex ? "noindex" : "index", noFollow ? "nofollow" : "follow"); + // noindex+nofollow when not in production + if (!env.IsProduction()) + { + noIndex = true; + noFollow = true; + } + model.Robots = $"{(noIndex ? "noindex" : "index")},{(noFollow ? "nofollow" : "follow")}"; // title HashSet fragments = options.TitleFragments.Where(x => !x.IsNullOrWhiteSpace()).Reverse().ToHashSet(); @@ -58,7 +52,7 @@ public class MetadataService : IMetadataService if (fragments.Count != 0) { - sb.Append(string.Join(options.TitleFragmentsSeparator, fragments.Select(fragment => Localizer.Maybe(fragment)))); + sb.Append(string.Join(options.TitleFragmentsSeparator, fragments.Select(localizer.Maybe))); if (!options.HidePageName) {