Browse Source

Fixed showing images...

pull/441/head
Alper Ebicoglu 8 years ago
parent
commit
f57e5b2ded
  1. 4
      modules/docs/src/Volo.Docs.Application.Contracts/Volo/Docs/Documents/ContentWithDetailsDto.cs
  2. 4
      modules/docs/src/Volo.Docs.Application/Volo/Docs/Documents/Document.cs
  3. 48
      modules/docs/src/Volo.Docs.Application/Volo/Docs/Documents/DocumentAppService.cs
  4. 12
      modules/docs/src/Volo.Docs.Application/Volo/Docs/Documents/GithubDocumentStore.cs
  5. 39
      modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/HtmlNormalizer.cs
  6. 7
      modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml.cs
  7. 4
      modules/docs/src/Volo.Docs.Web/compilerconfig.json

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

@ -21,6 +21,10 @@ namespace Volo.Docs.Documents
public string Version { get; set; }
public string LocalDirectory { get; set; }
public string FileName { get; set; }
public ProjectDto Project { get; set; }
}

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

@ -15,5 +15,9 @@ namespace Volo.Docs.Documents
public string RawRootUrl { get; set; }
public string Version { get; set; }
public string LocalDirectory { get; set; }
public string FileName { get; set; }
}
}

48
modules/docs/src/Volo.Docs.Application/Volo/Docs/Documents/DocumentAppService.cs

@ -54,17 +54,17 @@ namespace Volo.Docs.Documents
}
IDocumentStore documentStore = _documentStoreFactory.Create(project);
var document = await documentStore.FindDocumentByNameAsync(project, documentName, version);
Document document = await documentStore.FindDocumentByNameAsync(project, documentName, version);
var dto = ObjectMapper.Map<Document, DocumentWithDetailsDto>(document);
dto.Project = ObjectMapper.Map<Project, ProjectDto>(project);
if (normalize)
{
dto.Content = NormalizeLinks(dto.Content, project.ShortName, version);
dto.Content = NormalizeImages(dto.Content, dto.RawRootUrl);
}
//if (normalize)
//{
// dto.Content = NormalizeLinks(dto.Content, project.ShortName, version);
// dto.Content = NormalizeImages(dto.Content, dto.RawRootUrl);
//}
return dto;
}
@ -107,40 +107,6 @@ namespace Volo.Docs.Documents
await _distributedCache.SetAsync(projectShortName, versions, options);
}
private static string NormalizeLinks(string content, string projectShortName, string version)
{
var linkRegex = new Regex(@"\(([^)]+.md)\)", RegexOptions.Multiline);
var matches = linkRegex.Matches(content);
foreach (Match match in matches)
{
var mdFile = match.Value;
content = content.Replace(mdFile, "(/documents/" + projectShortName + "/" + version + "/" + mdFile.Replace("(", "").Replace(")", "").Replace(".md", "") + ")");
}
return content;
}
private static string NormalizeImages(string content, string documentRootAddress)
{
content = Regex.Replace(content, @"(<img\s+[^>]*)src=""([^""]*)""([^>]*>)", delegate (Match match)
{
var newImageSource = documentRootAddress.EnsureEndsWith('/') + match.Groups[1].Value.TrimStart('/');
return match.Groups[1] + "src=\"" + newImageSource + "\"" + match.Groups[3];
}, RegexOptions.IgnoreCase | RegexOptions.Singleline | RegexOptions.Multiline);
//var baseImageUrl = documentRootAddress;
//if (content.Contains("images/"))
//{
// Console.Write("");
//}
//var newSrcAttribute = "src=\"" + baseImageUrl + "images/\" data-src=\"" + baseImageUrl + "images/";
//return content.Replace("src=\"images/", newSrcAttribute)
// .Replace("src=\"../images/", newSrcAttribute);
return content;
}
}
}

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

@ -23,6 +23,14 @@ namespace Volo.Docs.Documents
var rawRootUrl = rootUrl.Replace("github.com", token + "raw.githubusercontent.com").Replace("/tree/", "/");
var rawUrl = rawRootUrl + documentName;
var editLink = rootUrl.Replace("/tree/", "/blob/") + documentName;
string localDirectory = "";
string fileName = documentName;
if (documentName.Contains("/"))
{
localDirectory = documentName.Substring(0, documentName.LastIndexOf('/'));
fileName = documentName.Substring(documentName.LastIndexOf('/') + 1, documentName.Length - documentName.LastIndexOf('/') - 1);
}
var content = DownloadWebContent(documentName, rawUrl);
@ -33,7 +41,9 @@ namespace Volo.Docs.Documents
EditLink = editLink,
RootUrl = rootUrl,
RawRootUrl = rawRootUrl,
Format = project.Format
Format = project.Format,
LocalDirectory = localDirectory,
FileName = fileName
});
}

39
modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/HtmlNormalizer.cs

@ -0,0 +1,39 @@
using System;
using System.Text.RegularExpressions;
namespace Volo.Docs.Pages.Documents.Project
{
public static class HtmlNormalizer
{
//todo: fix this for html content.
public static string NormalizeLinks(string content, string projectShortName, string version)
{
//var linkRegex = new Regex(@"\(([^)]+.md)\)", RegexOptions.Multiline);
//var matches = linkRegex.Matches(content);
//foreach (Match match in matches)
//{
// var mdFile = match.Value;
// content = content.Replace(mdFile, "(/documents/" + projectShortName + "/" + version + "/" + mdFile.Replace("(", "").Replace(")", "").Replace(".md", "") + ")");
//}
//return content;
return content;
}
public static string NormalizeImages(string content, string documentRawRootUrl, string localDirectory)
{
content = Regex.Replace(content, @"(<img\s+[^>]*)src=""([^""]*)""([^>]*>)", delegate (Match match)
{
var newImageSource = documentRawRootUrl.EnsureEndsWith('/') +
(localDirectory.IsNullOrEmpty() ? "" : localDirectory.TrimStart('/').EnsureEndsWith('/')) +
match.Groups[2].Value.TrimStart('/');
return match.Groups[1] + " src=\"" + newImageSource + "\" " + match.Groups[3];
}, RegexOptions.IgnoreCase | RegexOptions.Singleline | RegexOptions.Multiline);
return content;
}
}
}

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

@ -69,7 +69,10 @@ namespace Volo.Docs.Pages.Documents.Project
Document = await _documentAppService.GetByNameAsync(ProjectName, DocumentName, Version, true);
var documentFormatting = _documentFormattingFactory.Create(Document.Format ?? "md");
Document.Content = documentFormatting.Format(Document.Content);
var content = documentFormatting.Format(Document.Content);
content = HtmlNormalizer.NormalizeImages(content, Document.RawRootUrl, Document.LocalDirectory);
content = HtmlNormalizer.NormalizeLinks(content, Document.Project.ShortName, Document.Version);
Document.Content = content;
Navigation = await _documentAppService.GetNavigationDocumentAsync(ProjectName, Version, false);
Navigation.ConvertItems();
@ -89,5 +92,7 @@ namespace Volo.Docs.Pages.Documents.Project
Versions.Insert(0, DocsWebConsts.DefaultVersion);
}
}
}

4
modules/docs/src/Volo.Docs.Web/compilerconfig.json

@ -7,10 +7,6 @@
"outputFile": "Pages/Documents/_docs.css",
"inputFile": "Pages/Documents/_docs.scss"
},
{
"outputFile": "Pages/Documents/Project/vs.css",
"inputFile": "Pages/Documents/Project/vs.scss"
},
{
"outputFile": "Pages/Documents/_responsive.css",
"inputFile": "Pages/Documents/_responsive.scss"

Loading…
Cancel
Save