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: Modify isCoverPage check conditions #10453

Merged
merged 1 commit into from
Dec 14, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion samples/seed/docfx.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
{ "files": [ "**" ], "src": "obj/md", "dest": "md" },
{ "files": [ "**" ], "src": "obj/apipage", "dest": "apipage" },
{ "files": [ "articles/**/*.{md,yml}", "*.md", "toc.yml", "restapi/**" ] },
{ "files": [ "pdf/**" ] }
{ "files": [ "pdf/*.{md,yml}" ] }
],
"resource": [
{
Expand Down
19 changes: 16 additions & 3 deletions src/Docfx.App/PdfBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ await Parallel.ForEachAsync(pdfTocs, async (item, _) =>
var outputPath = Path.Combine(outputFolder, outputName);

await CreatePdf(
PrintPdf, PrintHeaderFooter, task, new(baseUrl, url), toc, outputPath,
PrintPdf, PrintHeaderFooter, task, new(baseUrl, url), toc, outputFolder, outputPath,
pageNumbers => pdfPageNumbers[url] = pageNumbers);

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

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

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

var isTocPage = IsTocPage(url);
if (isTocPage)
Expand Down Expand Up @@ -440,6 +440,19 @@ PdfAction HandleUriAction(UriAction url)

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

static bool IsCoverPage(Uri pageUri, string baseFolder, string? pdfCoverPage)
{
Debug.Assert(Path.IsPathFullyQualified(baseFolder));

if (string.IsNullOrEmpty(pdfCoverPage))
return false;

string pagePath = pageUri.AbsolutePath.TrimStart('/');
string covePagePath = PathUtility.MakeRelativePath(baseFolder, Path.GetFullPath(Path.Combine(baseFolder, pdfCoverPage)));

return pagePath.Equals(covePagePath, GetStringComparison());
}

static bool IsTocPage(Uri url) => url.AbsolutePath.StartsWith("/_pdftoc/");

Bookmarks CreateBookmarks(Outline[]? items)
Expand Down
Loading