Skip to content

Commit 445113c

Browse files
authored
fix: Modify isCoverPage check conditions (#10453)
fix: modify isCoverPage check conditions
1 parent 233ffb8 commit 445113c

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

samples/seed/docfx.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
{ "files": [ "**" ], "src": "obj/md", "dest": "md" },
7171
{ "files": [ "**" ], "src": "obj/apipage", "dest": "apipage" },
7272
{ "files": [ "articles/**/*.{md,yml}", "*.md", "toc.yml", "restapi/**" ] },
73-
{ "files": [ "pdf/**" ] }
73+
{ "files": [ "pdf/*.{md,yml}" ] }
7474
],
7575
"resource": [
7676
{

src/Docfx.App/PdfBuilder.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ await Parallel.ForEachAsync(pdfTocs, async (item, _) =>
106106
var outputPath = Path.Combine(outputFolder, outputName);
107107

108108
await CreatePdf(
109-
PrintPdf, PrintHeaderFooter, task, new(baseUrl, url), toc, outputPath,
109+
PrintPdf, PrintHeaderFooter, task, new(baseUrl, url), toc, outputFolder, outputPath,
110110
pageNumbers => pdfPageNumbers[url] = pageNumbers);
111111

112112
task.Value = task.MaxValue;
@@ -256,7 +256,7 @@ static string ExpandTemplate(string? pdfTemplate, int pageNumber, int totalPages
256256

257257
static async Task CreatePdf(
258258
Func<Outline, Uri, Task<byte[]?>> printPdf, Func<Outline, int, int, Page, Task<byte[]>> printHeaderFooter, ProgressTask task,
259-
Uri outlineUrl, Outline outline, string outputPath, Action<Dictionary<Outline, int>> updatePageNumbers)
259+
Uri outlineUrl, Outline outline, string outputFolder, string outputPath, Action<Dictionary<Outline, int>> updatePageNumbers)
260260
{
261261
var tempDirectory = Path.Combine(Path.GetTempPath(), ".docfx", "pdf", "pages");
262262
Directory.CreateDirectory(tempDirectory);
@@ -357,7 +357,7 @@ async Task MergePdf()
357357
if (!pageBytes.TryGetValue(node, out var bytes))
358358
continue;
359359

360-
var isCoverPage = url.AbsolutePath.TrimStart('/').Equals(outline.pdfCoverPage, GetStringComparison());
360+
var isCoverPage = IsCoverPage(url, outputFolder, outline.pdfCoverPage);
361361

362362
var isTocPage = IsTocPage(url);
363363
if (isTocPage)
@@ -440,6 +440,19 @@ PdfAction HandleUriAction(UriAction url)
440440

441441
static Uri CleanUrl(Uri url) => new UriBuilder(url) { Query = null, Fragment = null }.Uri;
442442

443+
static bool IsCoverPage(Uri pageUri, string baseFolder, string? pdfCoverPage)
444+
{
445+
Debug.Assert(Path.IsPathFullyQualified(baseFolder));
446+
447+
if (string.IsNullOrEmpty(pdfCoverPage))
448+
return false;
449+
450+
string pagePath = pageUri.AbsolutePath.TrimStart('/');
451+
string covePagePath = PathUtility.MakeRelativePath(baseFolder, Path.GetFullPath(Path.Combine(baseFolder, pdfCoverPage)));
452+
453+
return pagePath.Equals(covePagePath, GetStringComparison());
454+
}
455+
443456
static bool IsTocPage(Uri url) => url.AbsolutePath.StartsWith("/_pdftoc/");
444457

445458
Bookmarks CreateBookmarks(Outline[]? items)

0 commit comments

Comments
 (0)