-
Notifications
You must be signed in to change notification settings - Fork 391
Description
Post render script is ran as part of renderProject
quarto-cli/src/command/render/project.ts
Lines 857 to 858 in 7483c62
| // run post-render if this isn't incremental | |
| if (postRenderScripts.length) { |
post render does allow access to output files
quarto-cli/src/command/render/project.ts
Lines 876 to 878 in 7483c62
| 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
quarto-cli/src/command/preview/cmd.ts
Lines 360 to 371 in 7483c62
| 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
quarto-cli/src/command/preview/preview.ts
Lines 394 to 398 in 7483c62
| // 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_FILESorQUARTO_USE_FILE_FOR_PROJECT_OUTPUT_FILESwith a modified by post render script, and read that for new output files
- For example,
-
Either document that this should not happen in post render script or
quarto previewwon'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
quarto-cli/src/command/render/cmd.ts
Lines 269 to 286 in 7483c62
| 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
quarto-cli/src/command/preview/preview.ts
Lines 399 to 401 in 7483c62
| 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