更改 blogdown 帖子的默认目录

Change the default directory for blogdown posts

我使用的 Hugo 主题的帖子在 /content/blog 目录中,而使用 blogdown::new_post() 创建的新帖子默认在 /content/post 目录中。

从函数定义来看,有一个全局选项可以更改新帖子的保存目录(帮助也指出了这一点):

new_post(title, kind = "default", open = interactive(), 
    author = getOption("blogdown.author"), categories = NULL, 
    tags = NULL, date = Sys.Date(), file = NULL, slug = NULL, 
    subdir = getOption("blogdown.subdir", "post"), ext = getOption("blogdown.ext", 
        ".md"))

看起来如果我将 getOption("blogdown.subdir", "post") 更改为 getOption("blogdown.subdir", "blog"),那么这可能会奏效,但我怎样才能做到这一点才能使其成为所有帖子的默认设置?

您需要 options(blogdown.subdir = 'blog')。请阅读 blogdown 一书中的 Section 1.4 了解更多信息。