【问题标题】:Linking to another post in blogdown链接到 blogdown 中的另一篇文章
【发布时间】:2019-05-01 01:29:16
【问题描述】:

假设我在 contents/post/2019-04-29-old-post.Rmd 中有一个较旧的帖子,我想从一个新的 rmarkdown 帖子链接到它。有什么方法可以在不使用实时站点的硬编码 url 的情况下做到这一点(这样当我的站点的 url 发生变化时,我就不必更改所有这些交叉链接)?

现在我这样做:

In the [previous post](https://my.si.te/2019/04/29/old-post.html) we covered...

有没有办法以某种方式识别旧帖子(可能是 Rmd 文件名)并让 blogdown/hugo 生成正确的 url?

【问题讨论】:

    标签: r blogdown


    【解决方案1】:

    如果您在config.toml 中正确设置了基本 URL,如下所示:

    baseurl = "https://my.si.te/"
    languageCode = "en-us"
    title = "A Hugo website"
    theme = "hugo-lithium"
    googleAnalytics = ""
    

    并且还设置了[permalinks] 设置(也在config.toml 中):

    [permalinks]
        post = "/:year/:month/:day/:slug/"
    

    然后基础 URL 成为根文件夹,所以你可以这样链接:

    In the [previous post](/2019/04/29/old-post/) we covered...
    

    一般形式是

    In the [previous post](/:year/:month/:day/:slug/) we covered...
    

    基于[permalinks] 选项。

    【讨论】:

    • 如果文件只存储在目录而不是帖子中怎么办?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-11-14
    • 1970-01-01
    • 1970-01-01
    • 2018-07-22
    • 1970-01-01
    • 2015-12-01
    • 1970-01-01
    相关资源
    最近更新 更多