Browse Source

Remove index.htm from the target url (since navigating to the folder auto-navigates to the index.htm)

pull/65/head
Geert van Horrik 8 years ago
parent
commit
d9d4594b34
4 changed files with 33 additions and 16 deletions
  1. +1
    -0
      src/DocNet/Docnet.csproj
  2. +27
    -0
      src/DocNet/INavigationElementExtensions.cs
  3. +2
    -14
      src/DocNet/NavigationLevel.cs
  4. +3
    -2
      src/DocNet/SimpleNavigationElement.cs

+ 1
- 0
src/DocNet/Docnet.csproj View File

@@ -65,6 +65,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SearchIndexEntry.cs" />
<Compile Include="SimpleNavigationElement.cs" />
<Compile Include="INavigationElementExtensions.cs" />
<Compile Include="Utils.cs" />
</ItemGroup>
<ItemGroup>


+ 27
- 0
src/DocNet/INavigationElementExtensions.cs View File

@@ -0,0 +1,27 @@
using System;
using System.Web;

namespace Docnet
{
public static class INavigationElementExtensions
{
/// <summary>
/// Gets the final URL by encoding the path and by removing the filename if it equals <c>index.htm</c>.
/// </summary>
/// <param name="navigationElement">The navigation element.</param>
/// <param name="pathSpecification">The path specification.</param>
/// <returns></returns>
public static string GetFinalTargetUrl(this INavigationElement navigationElement, PathSpecification pathSpecification)
{
var targetUrl = navigationElement.GetTargetURL(pathSpecification);
var link = HttpUtility.UrlPathEncode(targetUrl);

if (link.EndsWith("index.htm", StringComparison.InvariantCultureIgnoreCase))
{
link = link.Substring(0, link.Length - "index.htm".Length);
}

return link;
}
}
}

+ 2
- 14
src/DocNet/NavigationLevel.cs View File

@@ -180,14 +180,8 @@ namespace Docnet
}
else
{
var link = HttpUtility.UrlPathEncode(indexElement.GetTargetURL(pathSpecification));
if (link.EndsWith("index.htm",StringComparison.InvariantCultureIgnoreCase))
{
link = link.Substring(0, link.Length - "index.htm".Length);
}

fragments.Add(string.Format("{0}<a href=\"{1}{2}\">{3}</a></span></li>",
elementStartTag, relativePathToRoot, link, this.Name));
elementStartTag, relativePathToRoot, indexElement.GetFinalTargetUrl(pathSpecification), this.Name));
}
}
// then the elements in the container. Index elements are skipped here.
@@ -199,15 +193,9 @@ namespace Docnet
}
else
{
var link = HttpUtility.UrlPathEncode(this.GetTargetURL(pathSpecification));
if (link.EndsWith("index.htm", StringComparison.InvariantCultureIgnoreCase))
{
link = link.Substring(0, link.Length - "index.htm".Length);
}

// just a link
fragments.Add(string.Format("<span class=\"navigationgroup\"><i class=\"fa fa-caret-right\"></i> <a href=\"{0}{1}\">{2}</a></span>",
relativePathToRoot, link, this.Name));
relativePathToRoot, this.GetFinalTargetUrl(pathSpecification), this.Name));
}
if (!this.IsRoot)
{


+ 3
- 2
src/DocNet/SimpleNavigationElement.cs View File

@@ -89,7 +89,8 @@ namespace Docnet
{
continue;
}
defaultMarkdown.AppendFormat("* [{0}]({1}{2}){3}", sibling.Name, relativePathToRoot, HttpUtility.UrlPathEncode(sibling.GetTargetURL(pathSpecification)), Environment.NewLine);
defaultMarkdown.AppendFormat("* [{0}]({1}{2}){3}", sibling.Name, relativePathToRoot,
sibling.GetFinalTargetUrl(pathSpecification), Environment.NewLine);
}
defaultMarkdown.Append(Environment.NewLine);
content = Utils.ConvertMarkdownToHtml(defaultMarkdown.ToString(), Path.GetDirectoryName(destinationFile), activeConfig.Destination, string.Empty, _relativeH2LinksOnPage, activeConfig.ConvertLocalLinks);
@@ -189,7 +190,7 @@ namespace Docnet
string.IsNullOrWhiteSpace(liClass) ? string.Empty : string.Format(" class=\"{0}\"", liClass),
string.IsNullOrWhiteSpace(aClass) ? string.Empty : string.Format(" class=\"{0}\"", aClass),
relativePathToRoot,
HttpUtility.UrlPathEncode(this.GetTargetURL(pathSpecification)),
this.GetFinalTargetUrl(pathSpecification),
this.Name));
if(isCurrent && _relativeH2LinksOnPage.Any())
{


Loading…
Cancel
Save