Browse Source

Improve PDF file generation

pull/22899/head
liangshiwei 9 months ago
parent
commit
c731847f1f
  1. 4
      modules/docs/app/VoloDocs.Web/VoloDocsWebModule.cs
  2. 2
      modules/docs/app/VoloDocs.Web/appsettings.json
  3. 18
      modules/docs/src/Volo.Docs.Domain/Volo/Docs/Projects/Pdf/ProjectPdfGenerator.cs
  4. 2
      modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml

4
modules/docs/app/VoloDocs.Web/VoloDocsWebModule.cs

@ -177,8 +177,8 @@ namespace VoloDocs.Web
Configure<DocsProjectPdfGeneratorOptions>(options =>
{
options.BaseUrl = configuration["App:selfUrl"];
options.IndexPagePath = "Index.md";
options.BaseUrl = configuration["App:SelfUrl"];
options.IndexPagePath = "index.md";
options.CalculatePdfFileTitle = project => project.ShortName == "abp" ? "ABP Documentation" : null;
options.DocumentContentNormalizer = content => content.Replace("<i class=\"fa fa-minus text-secondary\"></i>", "No").Replace("<i class=\"fa fa-check text-success\"></i>", "Yes");
});

2
modules/docs/app/VoloDocs.Web/appsettings.json

@ -1,6 +1,6 @@
{
"App": {
"selfUrl": "https://localhost:5001"
"SelfUrl": "https://localhost:5001"
},
"Kestrel": {
"EndPoints": {

18
modules/docs/src/Volo.Docs.Domain/Volo/Docs/Projects/Pdf/ProjectPdfGenerator.cs

@ -326,19 +326,21 @@ public class ProjectPdfGenerator : IProjectPdfGenerator, ITransientDependency
version = string.IsNullOrWhiteSpace(version) ? project.LatestVersionBranchName : version;
Document document = null;
Exception firstException = null;
foreach (var name in GetPossibleNames(documentName, project.Format))
var possibleNames = GetPossibleNames(documentName, project.Format);
document = await DocumentRepository.FindAsync(project.Id, possibleNames, languageCode, version);
if (document != null)
{
return document;
}
foreach (var name in possibleNames)
{
try
{
document = await DocumentRepository.FindAsync(project.Id, documentName, version, languageCode);
if (document != null)
{
break;
}
document = await DocumentSource.GetDocumentAsync(project, name, languageCode, version);
await DocumentRepository.InsertAsync(document, true);
break;
}
catch (Exception ex)

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

@ -294,7 +294,7 @@
@if (Model.HasDownloadPdfPermission)
{
<div class="docs-sidebar-footer">
<a href="@Url.Content($"~/api/docs/documents/pdf?ProjectId={Model.Project.Id}&Version={(Model.LatestVersionInfo == null || Model.LatestVersionInfo.IsSelected ? DocsAppConsts.Latest : Model.Version)}&LanguageCode={Model.LanguageCode}")" target="_blank" class="download-pdf-btn">
<a href="@Url.Content($"~/api/docs/documents/pdf?ProjectId={Model.Project.Id}&Version={(Model.LatestVersionInfo.IsSelected ? Model.LatestVersionInfo.Version : Model.Version)}&LanguageCode={Model.LanguageCode ?? Model.DefaultLanguageCode}")" target="_blank" class="download-pdf-btn">
<i class="fa fa-download"></i> @L["DownloadPDF"]
</a>
</div>

Loading…
Cancel
Save