MakeAbsolutePath() public static méthode

Makes toMakeAbsolute an absolute path, if it's not already a rooted path. If it's not a rooted path it's assumed it's relative to rootPath and is combined with that.
public static MakeAbsolutePath ( string rootPath, string toMakeAbsolute ) : string
rootPath string The root path.
toMakeAbsolute string To make absolute.
Résultat string
Exemple #1
0
        private string GenerateContent(SimpleNavigationElement element, Config config, NavigationContext navigationContext)
        {
            var stringBuilder = new StringBuilder();

            stringBuilder.AppendLine("# Page not found (404)");
            stringBuilder.AppendLine();

            stringBuilder.AppendLine("Unfortunately the page you were looking for does not exist. In order to help you out ");
            stringBuilder.AppendLine("in the best way possible, below is the table of contents:");
            stringBuilder.AppendLine();

            foreach (var sibling in this.ParentContainer.Value)
            {
                if (sibling == this)
                {
                    continue;
                }

                stringBuilder.AppendFormat("* [{0}]({1}{2}){3}", sibling.Name, "/" /* pathRelativeToRoot */,
                                           sibling.GetFinalTargetUrl(navigationContext), Environment.NewLine);
            }

            var markdownContent = stringBuilder.ToString();

            var destinationFile = Utils.MakeAbsolutePath(config.Destination, this.GetTargetURL(navigationContext));

            var htmlContent = Utils.ConvertMarkdownToHtml(markdownContent, Path.GetDirectoryName(destinationFile), config.Destination,
                                                          string.Empty, new List <Heading>(), config.ConvertLocalLinks);

            return(htmlContent);
        }
Exemple #2
0
        /// <summary>
        /// Generates the index of the search data. this is a json file with per page which has markdown a couple of data elements.
        /// </summary>
        private void GenerateSearchDataIndex()
        {
            var collectedSearchEntries = new List <SearchIndexEntry>();

            this.Pages.CollectSearchIndexEntries(collectedSearchEntries, new NavigatedPath());
            JObject searchIndex = new JObject(new JProperty("docs",
                                                            new JArray(
                                                                collectedSearchEntries.Select(e => new JObject(
                                                                                                  new JProperty("location", e.Location),
                                                                                                  new JProperty("breadcrumbs", e.BreadCrumbs),
                                                                                                  new JProperty("keywords", e.Keywords),
                                                                                                  new JProperty("title", e.Title)))
                                                                )
                                                            ));

            File.WriteAllText(Utils.MakeAbsolutePath(this.Destination, "search_index.json"), searchIndex.ToString());
        }
Exemple #3
0
        private static CliInput ParseInput(string[] args)
        {
            var toReturn = new CliInput();

            if (args == null || args.Length <= 0 || string.IsNullOrWhiteSpace(args[0]))
            {
                return(null);
            }
            var options = args.Where(s => s.StartsWith("-")).Select(s => s.ToLowerInvariant()).ToList();

            toReturn.ClearDestinationFolder = options.Contains("-c");
            // start folder is expected to be the last argument.
            toReturn.StartFolder = Utils.MakeAbsolutePath(Environment.CurrentDirectory, args[args.Length - 1]);
            if (!Directory.Exists(toReturn.StartFolder))
            {
                return(null);
            }
            return(toReturn);
        }
        /// <summary>
        /// Generates the output for this navigation element
        /// </summary>
        /// <param name="activeConfig">The active configuration to use for the output.</param>
        /// <param name="activePath">The active path navigated through the ToC to reach this element.</param>
        /// <param name="navigationContext">The navigation context.</param>
        /// <exception cref="FileNotFoundException"></exception>
        /// <exception cref="System.IO.FileNotFoundException"></exception>
        public override void GenerateOutput(Config activeConfig, NavigatedPath activePath, NavigationContext navigationContext)
        {
            // if we're the __index element, we're not pushing ourselves on the path, as we're representing the container we're in, which is already on the path.
            if (!this.IsIndexElement)
            {
                activePath.Push(this);
            }
            _relativeLinksOnPage.Clear();
            var sourceFile      = Utils.MakeAbsolutePath(activeConfig.Source, this.Value);
            var destinationFile = Utils.MakeAbsolutePath(activeConfig.Destination, this.GetTargetURL(navigationContext));
            var sb      = new StringBuilder(activeConfig.PageTemplateContents.Length + 2048);
            var content = string.Empty;

            this.MarkdownFromFile = string.Empty;
            var relativePathToRoot = Utils.MakeRelativePathForUri(Path.GetDirectoryName(destinationFile), activeConfig.Destination);

            if (File.Exists(sourceFile))
            {
                this.MarkdownFromFile = File.ReadAllText(sourceFile, Encoding.UTF8);
                // Check if the content contains @@include tag
                content = Utils.IncludeProcessor(this.MarkdownFromFile, Utils.MakeAbsolutePath(activeConfig.Source, activeConfig.IncludeFolder));
                content = Utils.ConvertMarkdownToHtml(content, Path.GetDirectoryName(destinationFile), activeConfig.Destination, sourceFile, _relativeLinksOnPage, activeConfig.ConvertLocalLinks);
            }
            else
            {
                // if we're not the index element, the file is missing and potentially it's an error in the config page.
                // Otherwise we can simply assume we are a missing index page and we'll generate default markdown so the user has something to look at.
                if (this.IsIndexElement)
                {
                    // replace with default markdown snippet. This is the name of our container and links to the elements in that container as we are the index page that's not
                    // specified / existend.
                    var defaultMarkdown = new StringBuilder();
                    defaultMarkdown.AppendFormat("# {0}{1}{1}", this.ParentContainer.Name, Environment.NewLine);
                    defaultMarkdown.AppendFormat("Please select one of the topics in this section:{0}{0}", Environment.NewLine);
                    foreach (var sibling in this.ParentContainer.Value)
                    {
                        if (sibling == this)
                        {
                            continue;
                        }
                        defaultMarkdown.AppendFormat("* [{0}]({1}{2}){3}", sibling.Name, relativePathToRoot,
                                                     sibling.GetFinalTargetUrl(navigationContext), Environment.NewLine);
                    }
                    defaultMarkdown.Append(Environment.NewLine);
                    content = Utils.ConvertMarkdownToHtml(defaultMarkdown.ToString(), Path.GetDirectoryName(destinationFile), activeConfig.Destination, string.Empty, _relativeLinksOnPage, activeConfig.ConvertLocalLinks);
                }
                else
                {
                    // target not found. See if there's a content producer func to produce html for us. If not, we can only conclude an error in the config file.
                    if (this.ContentProducerFunc == null)
                    {
                        throw new FileNotFoundException(string.Format("The specified markdown file '{0}' couldn't be found. Aborting", sourceFile));
                    }
                    content = this.ContentProducerFunc(this, activeConfig, navigationContext);
                }
            }
            sb.Append(activeConfig.PageTemplateContents);
            sb.Replace("{{Name}}", activeConfig.Name);
            sb.Replace("{{Footer}}", activeConfig.Footer);
            sb.Replace("{{TopicTitle}}", this.Name);
            sb.Replace("{{Path}}", relativePathToRoot);
            sb.Replace("{{RelativeSourceFileName}}", Utils.MakeRelativePathForUri(activeConfig.Destination, sourceFile).TrimEnd('/'));
            sb.Replace("{{RelativeTargetFileName}}", Utils.MakeRelativePathForUri(activeConfig.Destination, destinationFile).TrimEnd('/'));
            sb.Replace("{{Breadcrumbs}}", activePath.CreateBreadCrumbsHTML(relativePathToRoot, navigationContext));
            sb.Replace("{{ToC}}", activePath.CreateToCHTML(relativePathToRoot, navigationContext));
            sb.Replace("{{ExtraScript}}", (this.ExtraScriptProducerFunc == null) ? string.Empty : this.ExtraScriptProducerFunc(this, activeConfig, navigationContext));

            // the last action has to be replacing the content marker, so markers in the content which we have in the template as well aren't replaced
            sb.Replace("{{Content}}", content);
            Utils.CreateFoldersIfRequired(destinationFile);
            File.WriteAllText(destinationFile, sb.ToString());
            if (!this.IsIndexElement)
            {
                activePath.Pop();
            }
        }