Browse Source

Removed file extension for local MD files.

pull/473/head
Alper Ebicoglu 8 years ago
parent
commit
159c8e650c
  1. 5
      modules/docs/src/Volo.Docs.Application.Contracts/Volo/Docs/Documents/ContentWithDetailsDto.cs
  2. 4
      modules/docs/src/Volo.Docs.Application/Volo/Docs/Documents/GithubDocumentStore.cs
  3. 50
      modules/docs/src/Volo.Docs.Web/Formatting/MarkdownDocumentConverter.cs
  4. 8
      modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml.cs

5
modules/docs/src/Volo.Docs.Application.Contracts/Volo/Docs/Documents/ContentWithDetailsDto.cs

@ -43,7 +43,7 @@ namespace Volo.Docs.Documents
public bool HasChildItems => Items != null && Items.Any();
public bool IsEmpty => Text == null && Path == null;
public bool IsSelected(string documentName)
{
if (documentName == null)
@ -51,7 +51,7 @@ namespace Volo.Docs.Documents
return false;
}
if (string.Equals(documentName, Path, StringComparison.InvariantCultureIgnoreCase))
if (string.Equals(documentName, Path, StringComparison.OrdinalIgnoreCase))
{
return true;
}
@ -71,7 +71,6 @@ namespace Volo.Docs.Documents
return false;
}
}
public class NavigationWithDetailsDto : DocumentWithDetailsDto

4
modules/docs/src/Volo.Docs.Application/Volo/Docs/Documents/GithubDocumentStore.cs

@ -121,7 +121,7 @@ namespace Volo.Docs.Documents
try
{
var urlStartingAfterFirstSlash =
url.Substring(url.IndexOf("github.com/", StringComparison.Ordinal) + "github.com/".Length);
url.Substring(url.IndexOf("github.com/", StringComparison.OrdinalIgnoreCase) + "github.com/".Length);
return urlStartingAfterFirstSlash.Substring(0, urlStartingAfterFirstSlash.IndexOf('/'));
}
catch (Exception)
@ -135,7 +135,7 @@ namespace Volo.Docs.Documents
try
{
var urlStartingAfterFirstSlash =
url.Substring(url.IndexOf("github.com/", StringComparison.Ordinal) + "github.com/".Length);
url.Substring(url.IndexOf("github.com/", StringComparison.OrdinalIgnoreCase) + "github.com/".Length);
var urlStartingAfterSecondSlash =
urlStartingAfterFirstSlash.Substring(urlStartingAfterFirstSlash.IndexOf('/') + 1);
return urlStartingAfterSecondSlash.Substring(0, urlStartingAfterSecondSlash.IndexOf('/'));

50
modules/docs/src/Volo.Docs.Web/Formatting/MarkdownDocumentConverter.cs

@ -1,4 +1,5 @@
using System.Text;
using System;
using System.Text;
using System.Text.RegularExpressions;
using CommonMark;
using Volo.Abp.DependencyInjection;
@ -11,6 +12,8 @@ namespace Volo.Docs.Formatting
private const string NewLinkFormat = "[{0}](/documents/{1}/{2}/{3}/{4})";
private const string MarkdownLinkRegExp = @"\[([^)]+)\]\(([^)]+." + Type + @")\)";
public string Convert(string content)
{
return CommonMarkConverter.Convert(Encoding.UTF8.GetString(Encoding.Default.GetBytes(content)));
@ -19,14 +22,45 @@ namespace Volo.Docs.Formatting
public string NormalizeLinks(string content, string projectShortName, string version,
string documentLocalDirectory)
{
return Regex.Replace(content, @"\[([^)]+)\]\(([^)]+.md)\)", delegate (Match match)
{
var displayText = match.Groups[1].Value;
var documentName = match.Groups[2].Value;
var newLink = string.Format(NewLinkFormat, displayText, projectShortName, version, documentLocalDirectory.TrimStart('/').TrimEnd('/'), documentName);
return newLink;
});
return Regex.Replace(content, MarkdownLinkRegExp, delegate (Match match)
{
var displayText = match.Groups[1].Value;
var documentName = RemoveFileExtensionIfLocalUrl(match.Groups[2].Value);
return string.Format(NewLinkFormat, displayText, projectShortName, version,
documentLocalDirectory.TrimStart('/').TrimEnd('/'), documentName);
});
}
private static string RemoveFileExtensionIfLocalUrl(string documentName)
{
if (string.IsNullOrWhiteSpace(documentName))
{
return documentName;
}
if (!documentName.EndsWith(Type, StringComparison.OrdinalIgnoreCase))
{
return documentName;
}
if (IsRemoteUrl(documentName))
{
return documentName;
}
return documentName.Left(documentName.Length - Type.Length - 1);
}
private static bool IsRemoteUrl(string url)
{
try
{
return Regex.IsMatch(url, @"\A(https?|ftp)://(-\.)?([^\s/?\.#-]+\.?)+(/[^\s]*)?\z");
}
catch (Exception)
{
return true;
}
}
}
}

8
modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml.cs

@ -75,13 +75,8 @@ namespace Volo.Docs.Pages.Documents.Project
projectDto.ExtraProperties, projectDto.DocumentStoreType, DocumentNameWithExtension);
Versions = versions.Select(v => new VersionInfo(v, v)).ToList();
//VersionInfo latestVersion = Versions.First();
//latestVersion.DisplayText = $"{latestVersion.Version} - " + DocsAppConsts.LatestVersion;
//latestVersion.Version = latestVersion.Version;
if (string.Equals(Version, DocsAppConsts.LatestVersion, StringComparison.InvariantCultureIgnoreCase))
if (string.Equals(Version, DocsAppConsts.LatestVersion, StringComparison.OrdinalIgnoreCase))
{
LatestVersionInfo.IsSelected = true;
Version = LatestVersionInfo.Version;
@ -112,6 +107,7 @@ namespace Volo.Docs.Pages.Documents.Project
Navigation = await _documentAppService.GetNavigationDocumentAsync(ProjectName, Version, false);
Navigation.ConvertItems();
}
}

Loading…
Cancel
Save