File tree Expand file tree Collapse file tree 1 file changed +21
-4
lines changed
Expand file tree Collapse file tree 1 file changed +21
-4
lines changed Original file line number Diff line number Diff line change @@ -36,6 +36,8 @@ import {
3636} from "./config.ts" ;
3737import { websiteTitle } from "../project/types/website/website-config.ts" ;
3838import { gfmAutoIdentifier } from "../core/pandoc/pandoc-id.ts" ;
39+ import { RenderResultFile } from "../command/render/types.ts" ;
40+ import { isHtmlContent , isPdfContent } from "../core/mime.ts" ;
3941
4042export const kSiteContent = "site" ;
4143export 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 (
You can’t perform that action at this time.
0 commit comments