diff --git a/.env.example b/.env.example index 48288c0..e6b3b32 100644 --- a/.env.example +++ b/.env.example @@ -3,6 +3,8 @@ ConnectionStrings__umbracoDbDSN="Data Source=|DataDirectory|/Umbraco.sqlite.db;C SGFDevs__AzureBlobStorageKey= SGFDevs__NewsletterEndpoint= SGFDevs__NewsletterListId= +SGFDevs__Site__AnalyticsEnabled=false +SGFDevs__Site__SearchIndexingEnabled=false Umbraco__CMS__Global__Smtp__From="Sgf Devs " Umbraco__CMS__Global__Smtp__Host= Umbraco__CMS__Global__Smtp__Port= diff --git a/SgfDevs/Dev/SiteFeaturesOptions.cs b/SgfDevs/Dev/SiteFeaturesOptions.cs new file mode 100644 index 0000000..6c4e0d2 --- /dev/null +++ b/SgfDevs/Dev/SiteFeaturesOptions.cs @@ -0,0 +1,7 @@ +namespace SgfDevs.Dev; + +public class SiteFeaturesOptions +{ + public bool AnalyticsEnabled { get; set; } + public bool SearchIndexingEnabled { get; set; } +} diff --git a/SgfDevs/Program.cs b/SgfDevs/Program.cs index ab93106..ff9b4e0 100644 --- a/SgfDevs/Program.cs +++ b/SgfDevs/Program.cs @@ -4,9 +4,11 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Diagnostics.HealthChecks; using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Http; using Microsoft.Data.Sqlite; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Options; using SGFDevs.Controllers; using SgfDevs.Dev; using SgfDevs.Dev.EventSync; @@ -51,6 +53,7 @@ .AddCheck("ready", tags: ["ready"]); builder.Services.AddHttpClient(); builder.Services.Configure(builder.Configuration.GetSection("SGFDevs")); +builder.Services.Configure(builder.Configuration.GetSection("SGFDevs:Site")); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); @@ -90,6 +93,14 @@ Predicate = static check => check.Tags.Contains("ready"), ResponseWriter = healthCheckOptions.ResponseWriter }).AllowAnonymous(); +app.MapGet("/robots.txt", (IOptions siteFeatures) => + Results.Text( + siteFeatures.Value.SearchIndexingEnabled + ? "User-agent: *\nAllow: /\n" + : "User-agent: *\nDisallow: /\n", + "text/plain" + ) +).AllowAnonymous(); app.UseUmbraco() .WithMiddleware(u => diff --git a/SgfDevs/Views/Shared/_Layout.cshtml b/SgfDevs/Views/Shared/_Layout.cshtml index 157086a..7c620d0 100644 --- a/SgfDevs/Views/Shared/_Layout.cshtml +++ b/SgfDevs/Views/Shared/_Layout.cshtml @@ -1,4 +1,7 @@ @using Umbraco.Cms.Web.Common.PublishedModels; +@using Microsoft.Extensions.Options +@using SgfDevs.Dev +@inject IOptions SiteFeatures @* @inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage *@ @using ContentModels = Umbraco.Cms.Web.Common.PublishedModels; @@ -18,6 +21,10 @@ @**@ + @if (!SiteFeatures.Value.SearchIndexingEnabled) + { + + } @pageTitle @@ -25,14 +32,15 @@ @RenderSection("TopScripts", required: false) - + @if (SiteFeatures.Value.AnalyticsEnabled) + { - + }