• R语言已解决
  • Blogdown建立博客后文件夹中config.yaml、congfig.toml和params.toml的区别及应用

问题背景

在帖子“blogdown xmag 主题如何通过 iframe 插入外链音乐”中,我找到自己的带有外链音乐的新帖子发布却没有在网站显示的原因是时区问题

根据叶大哥的回复,我在congfig.toml中添加了buildFuture = true,最后成功解决了问题。但是随之而来的是困惑了我很久的问题。

问题描述

我在谢大哥这篇issue的回复中看到config文件分.yaml和.toml两种,但我用blogdown部署完帖子后,选择的主题文件夹下同时存在config.yaml、config.toml和params.toml三种文件。它们的源代码地址分别是:

config.yaml:
https://github.com/residualsun1/Residualsun/blob/main/config/_default/config.yaml

config.toml:
https://github.com/residualsun1/Residualsun/blob/main/themes/anatole/exampleSite/config/_default/config.toml

params.toml:
https://github.com/residualsun1/Residualsun/blob/main/config/_default/params.toml

我之前在调整主题的时候,看到GitHub上相关的回复都是说在config.toml里面进行修改。但我一开始找不到自己的config.toml文件,刚好发现params.toml文件里面的格式和config.toml长得相近,就在params.toml文件进行修改,也可以达到自己想要的目的。

config.yaml和config.toml文件也在以相近的代码实现同样的功能。以我这两个文件的源代码中的一段为例:

config.yaml:

enableEmoji: yes
enableRobotsTXT: yes

config.toml:

enableEmoji = true
enableRobotsTXT = true

问题诉求

综上,我想向各位前辈请教一下config.yaml、config.toml和params.toml三种文件是什么关系?在三者都存在的情况下,我如果要调整主题,应该在哪个文件进行代码修改?

Hugo uses the hugo.toml, hugo.yaml, or hugo.json (if found in the site root) as the default site configuration file.

https://gohugo.io/getting-started/configuration/

TOML、YAML、JSON 都是存储数据的格式,它们写法不一样,Hugo 用它们存储配置。如果同一个文件夹有同名但不同格式的配置文件,Hugo 会按优先级选一个。

你用的主题使用了多个配置文件。关于该改哪个文件,你看看主题文档,没提及就随意吧。

我还是第一次见多配置文件的主题,长见识了。