From 77d07e41a70e4f6da539f085aee75c2f5fb67415 Mon Sep 17 00:00:00 2001 From: Marijn Feijten Date: Mon, 17 Jun 2024 08:59:51 +0200 Subject: [PATCH] #9990 Add reading of file, instead of only allowing the template to be added to the toc.yml --- src/Docfx.App/PdfBuilder.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Docfx.App/PdfBuilder.cs b/src/Docfx.App/PdfBuilder.cs index 25b7e225467..49b6765b00a 100644 --- a/src/Docfx.App/PdfBuilder.cs +++ b/src/Docfx.App/PdfBuilder.cs @@ -181,8 +181,8 @@ IResult TocPage(string url) Task 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()); @@ -217,6 +217,13 @@ static string ExpandTemplate(string? pdfTemplate, int pageNumber, int totalPages .Replace("", $"{totalPages}") .Replace("", $"{totalPages}"); } + + static string? GetHeaderFooter(string? template) + { + return File.Exists(template) + ? File.ReadAllText(template) + : template; + } } }