Browse Source

First working version of newly generated indexes (PathSpecification: relative)

pull/65/head
Geert van Horrik 8 years ago
parent
commit
8cd24cfd73
2 changed files with 24 additions and 5 deletions
  1. +1
    -1
      src/DocNet/Config.cs
  2. +23
    -4
      src/DocNet/NavigationLevel.cs

+ 1
- 1
src/DocNet/Config.cs View File

@@ -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))


+ 23
- 4
src/DocNet/NavigationLevel.cs View File

@@ -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:


Loading…
Cancel
Save