quarto-dev / quarto-dev/quarto-cli

Support modifying output files names in post render script

Open
#12,987 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement project-scripts
Dominant language
JavaScript
Stars
6k
Forks
458
Avg merge
1d 9h
Merged PRs (30d)
41

Description

Post render script is ran as part of renderProject
https://github.com/quarto-dev/quarto-cli/blob/7483c62fa9af0437f72b3341f9a1c53a22c58b66/src/command/render/project.ts#L857-L858

post render does allow access to output files
https://github.com/quarto-dev/quarto-cli/blob/7483c62fa9af0437f72b3341f9a1c53a22c58b66/src/command/render/project.ts#L876-L878

This post render step is done before other steps that use the output files
https://github.com/quarto-dev/quarto-cli/blob/7483c62fa9af0437f72b3341f9a1c53a22c58b66/src/command/preview/cmd.ts#L360-L371

This is specifically the compute of finalOutput that fails
https://github.com/quarto-dev/quarto-cli/blob/7483c62fa9af0437f72b3341f9a1c53a22c58b66/src/command/preview/preview.ts#L394-L398

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
https://github.com/quarto-dev/quarto-cli/blob/7483c62fa9af0437f72b3341f9a1c53a22c58b66/src/command/render/cmd.ts#L269-L286

The real issue is the error at
https://github.com/quarto-dev/quarto-cli/blob/7483c62fa9af0437f72b3341f9a1c53a22c58b66/src/command/preview/preview.ts#L399-L401

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with src/command/render/project.ts and trace how post-render output files flow into src/command/preview/cmd.ts and src/command/preview/preview.ts, especially finalOutput. Compare the related handling in src/command/render/cmd.ts and reproduce a post-render rename such as 02_filtering.html; done means preview can locate and serve the renamed output without the “No output created” error.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
cli
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.