Open emitanaka opened 5 months ago
This is a smaller repro:
---
title: "{{< meta date-val >}}"
date: "{{< meta date-val >}}"
date-val: 2024/04/19
---
This is unfortunately something that won't be easy to fix. The date
field is somewhat special and needs to be declared explicitly as a string (because it's handled in Typescript before Pandoc is called), while shortcodes are handled during Pandoc's rendering.
I've been using a workaround for a while to avoid the special treatment of date:
and I wonder if it's a common enough pattern/need that it could be made into a legit/documented alternative.
Could one use, say, an alternative field such as rawdate:
, which does not get pre-processed by Deno, but could perhaps be recognised by quarto and later used to overwrite the date (if not supplied explicitly) with a lightweight Lua filter?
I think, the date-format
could be used for such purpose. With for instance the use of a keyword (to be defined), e.g., date-format: identity
.
Note that you can use the date-format
directly:
Quarto document | HTML |
---|---|
````qmd --- title: "Quarto Playground" format: html date: "2000-01-01" date-format: "[My custom date format]" --- This is a playground for Quarto. ```` |
Edit: ok, kind of unexpected/hilarious, but this works with shortcode
Quarto document | HTML |
---|---|
````qmd --- title: "Quarto Playground" format: html date: "2021-09-01" date-format: "[{{< meta date-val >}}]" date-val: 2024/04/19 --- This is a playground for Quarto. ```` |
Note that it means the date formatting is now for the user to deal with.
True, and that does offer a workaround for the original query:
---
title: "{{< var date >}}"
format: html
date: "2021-09-01"
date-format: "[{{< var date >}}]"
---
This is a playground for Quarto.
in a project with _variables.yml
does pick up the date:
for both fields (obviously inserted as-is without normalising/formatting). I guess it might be worth adding an explicit note in the docs that this is a way to get arbitrary dates as-is, including those injected via shortcodes.
It is not super elegant though, since date-format
doesn't really sound like it should hold the data itself, so personally I'd prefer a date-format: raw
(or identity
) and an associated date-raw:
field to hold the actual content.
Nick hack @mcanouil ! That'll work well for what I needed, thanks!
Bug description
It seems the date YAML is processed before the shortcode is evaluated.
Steps to reproduce
For
index.qmd
:_variables.yml
Expected behavior
The result should be the same as below:
Actual behavior
Results in Invalid Date
Your environment
Quarto check output
Quarto 1.5.30 [✓] Checking versions of quarto binary dependencies... Pandoc version 3.1.13: OK Dart Sass version 1.70.0: OK Deno version 1.41.0: OK Typst version 0.11.0: OK [✓] Checking versions of quarto dependencies......OK [✓] Checking Quarto installation......OK Version: 1.5.30 Path: /Applications/quarto/bin
[✓] Checking tools....................OK TinyTeX: (not installed) Chromium: (not installed)
[✓] Checking LaTeX....................OK Using: Installation From Path Path: /Library/TeX/texbin Version: 2023
[✓] Checking basic markdown render....OK
[✓] Checking Python 3 installation....OK Version: 3.9.6 Path: /Users/emitanaka/.virtualenvs/r-reticulate/bin/python3 Jupyter: (None)
[✓] Checking R installation...........OK Version: 4.3.3 Path: /Library/Frameworks/R.framework/Resources LibPaths:
[✓] Checking Knitr engine render......OK