自定义日期在 RMarkdown-pdf 中有效,但我注意到 Quarto 不行。
如何在 Quarto YAML 中使用自定义日期?
---
title: "Some pdf document"
author: "me"
date: "Spring 2022" <- I would like to use this
format: pdf
----
Run Code Online (Sandbox Code Playgroud)
---
title: "Some pdf document"
author: "me"
date: "Last update : `r Sys.Date()`" <- Or, like this
format: pdf
----
Run Code Online (Sandbox Code Playgroud)
当前的 Quarto-pdf 仅生成 %m/%d/%Y 格式日期。
您可以提供last-modified关键字(指包含该日期的文件的最后修改日期和时间)来确定日期并用于date-format修改日期。您还可以在方括号之间添加其他单词,然后这些单词将被转义并保持原样。
---
title: "Some pdf document"
author: "me"
date: last-modified
date-format: "[Last Updated on] MMMM, YYYY"
format: pdf
---
Run Code Online (Sandbox Code Playgroud)
现在,由于季节名称没有格式字符串,因此可以使用Pandoc Lua filter制作一个格式字符串。
---
title: "Some pdf document"
author: "None"
date: last-modified
date-format: "[Last Updated on] %MMM%, YYYY"
format: pdf
filters:
- custom-date.lua
---
Run Code Online (Sandbox Code Playgroud)
注意这里我们使用了%MMM%,它将被季节名称替换。
自定义日期.lua
local function replace_mon_with_season(date)
local season_table = {
Jan = "Winter", Feb = "Winter", Mar = "Spring",
Apr = "Spring", May = "Spring", Jun = "Summer",
Jul = "Summer", Aug = "Summer", Sep = "Autumn",
Oct = "Autumn", Nov = "Autumn", Dec = "Spring"
}
local date = pandoc.utils.stringify(date)
local mon = date:match("%%(%a+)%%")
local season = season_table[mon]
return date:gsub("%%" .. mon .. "%%", season)
end
function Meta(m)
m.date = replace_mon_with_season(m.date)
return m
end
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1599 次 |
| 最近记录: |