From 8cd24cfd732f5b14c8f1530fe05ebd94835ea519 Mon Sep 17 00:00:00 2001 From: Geert van Horrik Date: Mon, 26 Jun 2017 19:34:03 +0200 Subject: [PATCH] First working version of newly generated indexes (PathSpecification: relative) --- src/DocNet/Config.cs | 2 +- src/DocNet/NavigationLevel.cs | 27 +++++++++++++++++++++++---- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/DocNet/Config.cs b/src/DocNet/Config.cs index bd21cc3..55b15d6 100644 --- a/src/DocNet/Config.cs +++ b/src/DocNet/Config.cs @@ -262,7 +262,7 @@ namespace Docnet { var pathSpecification = PathSpecification.Full; - var pathSpecificationAsString = _configData.PathSpecification; + var pathSpecificationAsString = (string)_configData.PathSpecification; if (!string.IsNullOrWhiteSpace(pathSpecificationAsString)) { if (!Enum.TryParse(pathSpecificationAsString, true, out pathSpecification)) diff --git a/src/DocNet/NavigationLevel.cs b/src/DocNet/NavigationLevel.cs index b607c8e..d093b6b 100644 --- a/src/DocNet/NavigationLevel.cs +++ b/src/DocNet/NavigationLevel.cs @@ -71,6 +71,7 @@ namespace Docnet { path = Path.Combine(_rootDirectory, path); } + toAdd = CreateGeneratedLevel(path); toAdd.Name = nameToUse; } @@ -222,7 +223,7 @@ namespace Docnet var item = new SimpleNavigationElement { Name = name, - Value = Utils.MakeRelativePath(mdFile, _rootDirectory), + Value = Path.Combine(Utils.MakeRelativePath(_rootDirectory, path), Path.GetFileName(mdFile)), ParentContainer = root }; @@ -237,6 +238,7 @@ namespace Docnet root.Value.Add(subDirectoryNavigationElement); } + return root; } @@ -294,22 +296,39 @@ namespace Docnet { path = Path.GetDirectoryName(this.ParentContainer.GetTargetURL(pathSpecification)); } + var nameToUse = this.Name.Replace(".", "").Replace('/', '_').Replace("\\", "_").Replace(":", "").Replace(" ", ""); if (string.IsNullOrWhiteSpace(nameToUse)) { return null; } - var value = string.Empty; + var value = string.Format("{0}{1}.md", path, nameToUse); switch (pathSpecification) { case PathSpecification.Full: - value = string.Format("{0}{1}.md", path, nameToUse); + // Default is correct break; case PathSpecification.Relative: - value = Path.Combine(path ?? string.Empty, nameToUse + ".md"); + var preferredPath = path; + + // We're making a big assumption here, but we can get the first page and assume it's + // in the right folder. + + // Find first (simple) child and use 1 level up. A SimpleNavigationElement mostly represents a folder + // thus is excellent to be used as a folder name + var firstSimpleChildPage = (SimpleNavigationElement)this.Value.FirstOrDefault(x => x is SimpleNavigationElement && !ReferenceEquals(this, x)); + if (firstSimpleChildPage != null) + { + preferredPath = Path.GetDirectoryName(firstSimpleChildPage.Value); + } + + if (!string.IsNullOrWhiteSpace(preferredPath)) + { + value = Path.Combine(preferredPath, "index.md"); + } break; default: