Example #1
0
        /// <summary>
        /// Loads and fixes up configuration values from the configuraton.
        /// </summary>
        /// <remarks>
        /// Note we're custom loading this to allow for not overly string command line syntax
        /// </remarks>
        /// <param name="Configuration">.NET Core Configuration Provider</param>
        public bool LoadFromConfiguration(IConfiguration Configuration)
        {
            Current = this;

            WebRoot = Configuration["WebRoot"];
            if (string.IsNullOrEmpty(WebRoot))
            {
                WebRoot = Environment.CurrentDirectory;
            }
            else
            {
                WebRoot = Path.GetFullPath(WebRoot, Environment.CurrentDirectory);
            }

            Port         = Helpers.GetIntegerSetting("Port", Configuration, Port);
            UseSsl       = Helpers.GetLogicalSetting("UseSsl", Configuration, UseSsl);
            Host         = Helpers.GetStringSetting("Host", Configuration, Host);
            DefaultFiles = Helpers.GetStringSetting("DefaultFiles", Configuration, DefaultFiles);
            Extensions   = Helpers.GetStringSetting("Extensions", Configuration, Extensions);


            UseLiveReload = Helpers.GetLogicalSetting("UseLiveReload", Configuration, UseLiveReload);
            UseRazor      = Helpers.GetLogicalSetting("UseRazor", Configuration);
            ShowUrls      = Helpers.GetLogicalSetting("ShowUrls", Configuration, ShowUrls);
            OpenBrowser   = Helpers.GetLogicalSetting("OpenBrowser", Configuration, OpenBrowser);

            FolderNotFoundFallbackPath = Helpers.GetStringSetting("FolderNotFoundFallbackPath", Configuration, null);

            // Enables Markdown Middleware and optionally copies Markdown Templates into output folder
            UseMarkdown = Helpers.GetLogicalSetting("UseMarkdown", Configuration, false);
            if (UseMarkdown)
            {
                // defaults to true but only if Markdown is enabled!
                CopyMarkdownResources = Helpers.GetLogicalSetting("CopyMarkdownResources", Configuration, CopyMarkdownResources);
            }
            MarkdownTemplate    = Helpers.GetStringSetting("MarkdownTemplate", Configuration, MarkdownTemplate);
            MarkdownTheme       = Helpers.GetStringSetting("MarkdownTheme", Configuration, MarkdownTheme);
            MarkdownSyntaxTheme = Helpers.GetStringSetting("MarkdownSyntaxTheme", Configuration, MarkdownSyntaxTheme);

            return(true);
        }
        /// <summary>
        /// Loads and fixes up configuration values from the configuraton.
        /// </summary>
        /// <remarks>
        /// Note we're custom loading this to allow for not overly string command line syntax
        /// </remarks>
        /// <param name="Configuration">.NET Core Configuration Provider</param>
        public bool LoadFromConfiguration(IConfiguration Configuration)
        {
            Current = this;

            WebRoot = Configuration["WebRoot"];
            if (string.IsNullOrEmpty(WebRoot))
            {
                // if not set but the first arg does not start with the - it's the folder
                var args = Environment.GetCommandLineArgs();
                if (args.Length > 1 && !args[1].StartsWith("-"))
                {
                    WebRoot = args[1];
                }
            }
            if (string.IsNullOrEmpty(WebRoot))
            {
                WebRoot = Environment.CurrentDirectory;
            }
            else
            {
                var expandedPath = FileUtils.ExpandPathEnvironmentVariables(WebRoot);
                WebRoot = Path.GetFullPath(expandedPath, Environment.CurrentDirectory);
            }

            Port         = Helpers.GetIntegerSetting("Port", Configuration, Port);
            UseSsl       = Helpers.GetLogicalSetting("UseSsl", Configuration, UseSsl);
            Host         = Helpers.GetStringSetting("Host", Configuration, Host);
            DefaultFiles = Helpers.GetStringSetting("DefaultFiles", Configuration, DefaultFiles);
            Extensions   = Helpers.GetStringSetting("Extensions", Configuration, Extensions);

            UseLiveReload = Helpers.GetLogicalSetting("UseLiveReload", Configuration, UseLiveReload);
            UseRazor      = Helpers.GetLogicalSetting("UseRazor", Configuration);
            ShowUrls      = Helpers.GetLogicalSetting("ShowUrls", Configuration, ShowUrls);

            OpenBrowser         = Helpers.GetLogicalSetting("OpenBrowser", Configuration, OpenBrowser);
            OpenEditor          = Helpers.GetLogicalSetting("OpenEditor", Configuration, OpenEditor);
            EditorLaunchCommand = Helpers.GetStringSetting("EditorLaunchCommand", Configuration, EditorLaunchCommand);


            DetailedErrors = Helpers.GetLogicalSetting("DetailedErrors", Configuration, DetailedErrors);

            FolderNotFoundFallbackPath = Helpers.GetStringSetting("FolderNotFoundFallbackPath", Configuration, null);

            // Enables Markdown Middleware and optionally copies Markdown Templates into output folder
            UseMarkdown = Helpers.GetLogicalSetting("UseMarkdown", Configuration, false);
            if (UseMarkdown)
            {
                // defaults to true but only if Markdown is enabled!
                CopyMarkdownResources = Helpers.GetLogicalSetting("CopyMarkdownResources", Configuration, CopyMarkdownResources);
            }
            MarkdownTemplate    = Helpers.GetStringSetting("MarkdownTemplate", Configuration, MarkdownTemplate);
            MarkdownTheme       = Helpers.GetStringSetting("MarkdownTheme", Configuration, MarkdownTheme);
            MarkdownSyntaxTheme = Helpers.GetStringSetting("MarkdownSyntaxTheme", Configuration, MarkdownSyntaxTheme);


            // Fix ups
            if (Extensions is null)
            {
                Extensions = string.Empty;
            }

            if (UseMarkdown)
            {
                if (!Extensions.Contains(".md"))
                {
                    Extensions += ",.md";
                }
                if (!Extensions.Contains(".markdown"))
                {
                    Extensions += ",.markdown";
                }

                if (!DefaultFiles.Contains(".md"))
                {
                    DefaultFiles = DefaultFiles.Trim(',') + ",README.md,index.md";
                }
            }

            return(true);
        }