Skip to content

Commit 3c8af5f

Browse files
committed
When publishing, prefer HTML, then PDf for rootfile
1 parent 3169217 commit 3c8af5f

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

src/publish/publish.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ import {
3636
} from "./config.ts";
3737
import { websiteTitle } from "../project/types/website/website-config.ts";
3838
import { gfmAutoIdentifier } from "../core/pandoc/pandoc-id.ts";
39+
import { RenderResultFile } from "../command/render/types.ts";
40+
import { isHtmlContent, isPdfContent } from "../core/mime.ts";
3941

4042
export const kSiteContent = "site";
4143
export const kDocumentContent = "document";
@@ -149,12 +151,27 @@ export async function publishDocument(
149151
return file;
150152
}
151153
};
152-
let rootFile: string | undefined;
154+
155+
// When publishing a document, try using an HTML or PDF
156+
// document as the rootFile, if one isn't present, just take
157+
// the first one
158+
const findRootFile = (files: RenderResultFile[]) => {
159+
const rootFile = files.find((renderResult) => {
160+
return isHtmlContent(renderResult.file);
161+
}) || files.find((renderResult) => {
162+
return isPdfContent(renderResult.file);
163+
}) || files[0];
164+
165+
if (rootFile) {
166+
return asRelative(rootFile.file);
167+
} else {
168+
return undefined;
169+
}
170+
};
171+
172+
const rootFile: string | undefined = findRootFile(result.files);
153173
for (const resultFile of result.files) {
154174
const file = asRelative(resultFile.file);
155-
if (!rootFile) {
156-
rootFile = file;
157-
}
158175
files.push(file);
159176
if (resultFile.supporting) {
160177
files.push(

0 commit comments

Comments
 (0)