【问题标题】:How to link your own articles on a Pelican blog?如何在 Pelican 博客上链接您自己的文章?
【发布时间】:2014-03-18 23:47:45
【问题描述】:

我尝试用 html 文件名链接,但因为它们在同一个文件夹中,所以它可以工作。

[Title](./this-is-the-file.html)

但由于 ARTICLE_URL 模式,另一篇文章可能会出现在另一个文件夹中。例子:

[Title 1](/2014/02/article1.html)
[Title 2](/2014/01/25/article2.html)

是否可以将您自己的文章与对 slug 的引用链接起来?除了生成的 HTML 文件名之外,还有其他更好的解决方案吗?

【问题讨论】:

  • 我认为目前还没有简单的方法可以做到这一点。希望有人会为此创建一个插件。

标签: relative-path pelican static-site


【解决方案1】:

documentation 中所述,您可以通过以下方式链接到其他源内容文件:

[a link relative to content root]({filename}/this-is-the-source-file.md)

...或...

[a link relative to current file]({filename}../this-is-the-source-file.md)

Pelican 将合并您选择的 URL 方案并自动确定链接到另一篇文章的正确方式。

【讨论】:

  • 这在使用 reStructuredText 而不是 Markdown 时的工作方式相同:This is `a link <{filename}/somefile.rst`_ to somewhere else.
【解决方案2】:

我这样做的方法是使用 save_as 元数据标签指定我自己的 sluglines。因此,如果我有一篇名为 my_post.md 的博文,它会是这样的:

Title: My Blog Post
save_as: myblogpost.html

This is the world's most boring blog post.

这确保我可以通过/myblogpost.html 链接到它。然后在其他一些博文中,我可以说:

Title: My Second Blog Post
save_as: mysecondblogpost.html

This is the world's second most boring blog post. The most boring blog post is [here]({{ SITEURL }}/myblogpost.html).

这是一种更灵活、更优雅的解决方案,可为您提供更细粒度的控制。如果您不将 Pelican 用于博客网站,那么它非常重要。

【讨论】:

  • 您确定可以在内容中使用 SITEURL 吗?我只能在模板中使用它,否则我会得到WARNING: Replacement Indicator '{ SITEURL ' not recognized, skipping replacement
【解决方案3】:

处理 rst / 重组文本中的链接。

假设您想要从第二个帖子到第一个帖子的链接。这是第二篇文章中的一段上下文:

If you wish to see my first blog post click `here`_

.. _here: first-blog-post

第一篇博文应该有适当的 slug:

First blog post
########################################
:date: 2019-02-18 20:31
:category: entry
:tags: python, blog, first
:slug: first-blog-post

我有配置:

ARTICLE_URL = '{date:%Y}/{date:%m}/{slug}.html'

它处理额外的东西,比如年和月。很可能您可以坚持使用 slug 而不必跟踪 HTML。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-22
    • 1970-01-01
    相关资源
    最近更新 更多