例如我想要这样的效果:
---
title: "Hello World"
date: "11/6/2020"
output: html_document
slug: "hello-world"
---
YAML头部的slug
就是把title
转换成用”-“连接的小写字符。
参考Access the document metadata in R code的实现方式现在是这样:
---
title: "Hello World"
date: "11/6/2020"
output: html_document
slug: "`r gsub(' ', '-', tolower(rmarkdown::metadata$title))`"
---
我看中间的markdown文件里slug
是空值的,并不是想要的hello-world
。
大家有什么好方法吗?
难道说rmarkdown::metadata只适合在正文中引用YAML头部元素吗?
另外一种方案是通过params
在中间过渡下,例如:
---
params:
post_title: "Hello World"
title: "`r params$post_title`"
date: "11/6/2020"
output: html_document
slug: "`r gsub(' ', '-', tolower(params$post_title))`"
---
但这种方法感觉不够直接,还是想直接引用title
😀