From aeaad41e84a68bf04136507013a8d10772758314 Mon Sep 17 00:00:00 2001 From: Gordon Woodhull Date: Tue, 19 Mar 2024 14:19:19 -0400 Subject: [PATCH] support input qmds prefixed with directory however, these are not reflected in output, so qmd filenames have to be unique --- tools/render-all-formats.ts | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/tools/render-all-formats.ts b/tools/render-all-formats.ts index d0fde35afa..1cb191c4ef 100644 --- a/tools/render-all-formats.ts +++ b/tools/render-all-formats.ts @@ -42,17 +42,25 @@ async function extractMetadataFromFile(file: string): Promise { async function renderAndMoveArtifacts(dryRun: boolean, outputRoot: string, qmdFile : string) { if (!qmdFile.endsWith('.qmd')) { console.log('expecting only .qmd files, skipping', qmdFile); - return null; + return; } console.log(qmdFile); const qmdbase = path.basename(qmdFile).slice(0, -4); + const qmddir = path.dirname(qmdFile); const meta = await extractMetadataFromFile(qmdFile); - for (const [format, spec] of Object.entries(meta['format'])) { + const mdformat = meta['format']; + if (!mdformat) { + console.log(`does not contain format, skipping`, qmdFile); + return; + } + const formats = typeof mdformat === 'string' ? [mdformat] : Object.keys(mdformat); + + for (const format of formats) { const outext = formatOutput[format]; if (!outext) { - console.log(`unsupported format ${format}, skipping`); + console.log(`unsupported format ${format}, skipping`, qmdFile); continue; } const outdir = path.join(outputRoot, qmdbase, format); @@ -94,11 +102,12 @@ async function renderAndMoveArtifacts(dryRun: boolean, outputRoot: string, qmdFi } movefiles.push(`${qmdbase}_files`); for (const movefile of movefiles) { + const src = path.join(qmddir, movefile); const dest = path.join(outdir, movefile); - console.log(`mv ${movefile} ${dest}`); + console.log(`mv ${src} ${dest}`); if (!dryRun) { try { - await fs.move('./' + movefile, dest); + await fs.move(src, dest); } catch (error) { if(error instanceof Deno.errors.NotFound) { console.log('... not found'); @@ -115,7 +124,7 @@ async function renderAndMoveArtifacts(dryRun: boolean, outputRoot: string, qmdFi if (import.meta.main) { const args = Deno.args; - if (args.length < 2) { + if (args.includes('--help') || args.includes('-h') || args.filter(arg => !arg.startsWith('-')).length < 2) { console.log('usage: render-all-formats.ts [--dryrun] output-root doc.qmd ...'); console.log(' creates output-root/doc/format/...'); console.log(' output-root should be empty');