Skip to content

Support modifying output files names in post render script #12987

@cderv

Description

@cderv

Post render script is ran as part of renderProject

// run post-render if this isn't incremental
if (postRenderScripts.length) {

post render does allow access to output files

env.QUARTO_PROJECT_OUTPUT_FILES = outputFiles
.map((outputFile) => relative(projDir, outputFile.file))
.join("\n");

This post render step is done before other steps that use the output files

const renderResult = await renderProject(project, {
services,
progress: false,
useFreezer: false,
flags,
pandocArgs: args,
previewServer: true,
}, [file]);
if (renderResult.error) {
throw renderResult.error;
}
handleRenderResult(file, renderResult);

This is specifically the compute of finalOutput that fails

// print output created
const finalOutput = renderResultFinalOutput(
renderResult,
dirname(file),
);

It could happen that the output file's name is modified by the post render step. However, there is no mechanism to pass back this information for the rest of the process.

I see to choice here:

  • Either supporting passing back information of modification

    • For example, QUARTO_PROJECT_OUTPUT_FILES or QUARTO_USE_FILE_FOR_PROJECT_OUTPUT_FILES with a modified by post render script, and read that for new output files
  • Either document that this should not happen in post render script or quarto preview won't work.

For render, the final output is also computed, but if no found based on input name, it will just show nothing and not error like in preview

if (renderResult && renderResultInput) {
// report output created
if (!options.flags?.quiet && options.flags?.output !== kStdOut) {
const finalOutput = renderResultFinalOutput(
renderResult,
Deno.statSync(renderResultInput).isDirectory
? renderResultInput
: dirname(renderResultInput),
);
if (finalOutput) {
info("Output created: " + finalOutput + "\n");
}
if (renderResult) {
renderResult.context.cleanup();
}
}

The real issue is the error at

if (!finalOutput) {
throw new Error("No output created by quarto render " + basename(file));
}

leading to

ERROR: No output created by quarto render 02_filtering.qmd

Stack trace:
    at handleRenderResult (file:///Applications/RStudio.app/Contents/Resources/app/quarto/bin/quarto.js:91527:15)
    at renderForPreview (file:///Applications/RStudio.app/Contents/Resources/app/quarto/bin/quarto.js:91543:25)
    at eventLoopTick (ext:core/01_core.js:175:7)
    at async render (file:///Applications/RStudio.app/Contents/Resources/app/quarto/bin/quarto.js:91416:29)
GET: /Analysis/02_filtering.html (404: Not Found)

when post render modify the name of 02_filtering.html

Maybe not erroring and just previewing the base url (for index.html as a fallback) is better 🤷‍♂

Use case: Using post render script to rename output file was given as workaround to support adding date to output file name. See

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions