/// <summary><![CDATA[ /// Wrapper method for restrieving a development or staging page banner. /// Styling is in the application.scss file. /// ]]></summary> /// <example> /// Requires the following Carbide config items: /// <code><![CDATA[ /// <add key = "Domain.Staging" value="staging.example.com" /> /// <add key = "Banner.Development.Show" value="true" /> /// <add key = "Banner.Development.Message" value="DEVELOPMENT SITE" /> /// <add key = "Banner.Staging.Show" value="true" /> /// <add key = "Banner.Staging.Message" value="STAGING SITE" /> /// ]]></code> /// Use in a Razor page: /// <code><![CDATA[ /// @Html.Raw(OutputDevelopmentBanner()) /// ]]></code> /// </example> public static string OutputDevelopmentBanner() { var debugging = AppStateHelpers.IsDebugging(); var domain = HttpHelpers.GetSeoHost(); var showBanner = false; var result = ""; if (debugging) { showBanner = Config.GetKeyValue <bool>("Banner.Development.Show", true, "Fynydd.Carbide"); if (domain.Contains(Config.GetKeyValue("Domain.Staging", "{not found}", "Fynydd.Carbide"))) { showBanner = Config.GetKeyValue <bool>("Banner.Staging.Show", true, "Fynydd.Carbide"); } } if (showBanner) { var debugId = "debug-banner"; var debugMessage = Config.GetKeyValue("Banner.Development.Message", "DEVELOPMENT", "Fynydd.Carbide"); if (domain.Contains(Config.GetKeyValue("Domain.Staging", "{not found}", "Fynydd.Carbide"))) { debugId = "staging-banner"; debugMessage = Config.GetKeyValue("Banner.Staging.Message", "STAGING", "Fynydd.Carbide"); } result = "<section id=\"" + debugId + "\"><span>" + debugMessage + "</span></section>"; } return(result); }
/// <summary><![CDATA[ /// Output a meta tag to prevent page indexing in current context. /// ]]></summary> /// <example> /// Use in a Razor page. /// <code><![CDATA[ /// @Html.Raw(SeoHelpers.PreventSearchIndexingWhenDebug()) /// ]]></code> /// </example> public static string PreventSearchIndexingWhenDebug() { if (AppStateHelpers.IsDebugging()) { return(Metadata.DoNotIndex); } else { return(""); } }
/// <summary><![CDATA[ /// Return a meta tag to prevent browser page caching in current context. /// Use in a Razor page. /// ]]></summary> /// <example> /// Use in a Razor page. /// <code><![CDATA[ /// @Html.Raw(SeoHelpers.PreventBrowserCachingWhenDebug()) /// ]]></code> /// </example> public static string PreventBrowserCachingWhenDebug() { if (AppStateHelpers.IsDebugging()) { return(Metadata.DoNotCache); } else { return(""); } }
/// <summary><![CDATA[ /// Wrapper method for building CSS from SCSS files, with partial injection. /// Will check and build every "Scss.BuildCheck.Seconds" when debug=true if there are file changes (production). /// Will check and build every page load when debug=true if there are file changes. /// Requires the following Carbide config items: /// ]]></summary> /// <example> /// <code><![CDATA[ /// <add key="Scss.BuildCheck.Seconds" value="3600" /> /// <add key="Scss.Root" value="/scss/" /> /// <add key="Scss.Partials.Root" value="/scss/custom/" /> /// <add key="Scss.Filename.Base" value="application" /> /// <add key="Scss.Output.Root" value="/css/" /> /// ]]></code> /// </example> public static void RunConfiguredScssBuild() { var scssPath = Config.GetKeyValue("Scss.Root", "/scss/", "Fynydd.Carbide"); var scssPartialsPath = Config.GetKeyValue("Scss.Partials.Root", "/scss/custom/", "Fynydd.Carbide"); var scssFilenameBase = Config.GetKeyValue("Scss.Filename.Base", "application", "Fynydd.Carbide"); var scssOutputPath = Config.GetKeyValue("Scss.Output.Root", "/css/", "Fynydd.Carbide"); var debugging = AppStateHelpers.IsDebugging(); var buildScss = debugging; // Always run in debug mode if (debugging == false) { // Only run the check periodically on production unless the file doesn't exist if (FileExists(scssOutputPath + scssFilenameBase + ".css") == false) { buildScss = true; } TemporalHelpers.TaskIntervalInit("ScssProductionBuild", Config.GetKeyValue <double>("Scss.BuildCheck.Seconds", 60 * 60 * 24, "Fynydd.Carbide")); if (TemporalHelpers.TaskShouldBeRun("ScssProductionBuild")) { buildScss = true; } } if (buildScss == true) { if (debugging == false) { TemporalHelpers.TaskIntervalStart("ScssProductionBuild"); } StorageHelpers.InjectScssPartials(scssPath, scssFilenameBase + ".scss", scssPartialsPath); StorageHelpers.BuildScss(scssPath + scssFilenameBase + ".scss", scssOutputPath + scssFilenameBase + ".css", debugMode: debugging); if (debugging == false) { TemporalHelpers.TaskIntervalStop("ScssProductionBuild"); } } }