Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #9990 header and footer template files #10012

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/Docfx.App/PdfBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ IResult TocPage(string url)

Task<byte[]> PrintHeaderFooter(Outline toc, int pageNumber, int totalPages)
{
var headerTemplate = ExpandTemplate(toc.pdfHeaderTemplate, pageNumber, totalPages);
var footerTemplate = ExpandTemplate(toc.pdfFooterTemplate ?? DefaultFooterTemplate, pageNumber, totalPages);
var headerTemplate = ExpandTemplate(GetHeaderFooter(toc.pdfHeaderTemplate), pageNumber, totalPages);
var footerTemplate = ExpandTemplate(GetHeaderFooter(toc.pdfFooterTemplate) ?? DefaultFooterTemplate, pageNumber, totalPages);

return headerFooterCache.GetOrAdd((headerTemplate, footerTemplate), _ => PrintHeaderFooterCore());

Expand Down Expand Up @@ -222,6 +222,13 @@ static string ExpandTemplate(string? pdfTemplate, int pageNumber, int totalPages
.Replace("<span class='totalPages'></span>", $"<span>{totalPages}</span>")
.Replace("<span class=\"totalPages\"></span>", $"<span>{totalPages}</span>");
}

static string? GetHeaderFooter(string? template)
{
return File.Exists(template)
? File.ReadAllText(template)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is the current directory if this is a relative path? Consider explicitly state the base directoy to relative to

: template;
}
}
}

Expand Down
Loading