Jekyll 内部 Post 链接
Jekyll Internal Post Links
这是一个非常小众的问题,但是...我 运行 一个关于 Jekyll 的博客 运行 我经常 post 。为了让我的编辑保持理智,我定期存档 posts,那些存档的 posts 有一个非常严格的结构。但是,我整整一年才归档。
link 对其他 post 造成伤害的地方。我曾经能够绝对引用文件名(根据 jekyll markdown internal links),但这似乎已被弃用:
Deprecation: A call to '{% post_url 2018-09-06-peppermint %}' did not match a post using the new matching method of checking name (path-date-slug) equality. Please make sure that you change this tag to match the post's name exactly.
现在,如果我必须包含文件的完整路径,那么当我归档当年的 posts 时,我必须解析全年的所有 posts并更新它们之间的任何 links 以包含其存档位置的新文件路径,从而完全破坏了使用此工具的意义。直接 link 到页面实际上会更好,因为我不经常更改 URL 结构。
对于不依赖于文件结构的内部 link 是否有更好的解决方案,允许移动文件而不必更新每个 link 到该文件?
示例文件结构:
_posts
-2018
-post1
-post2
-etc
-Archive
-2017
-2016
如果没有更好的答案,我可能不得不回到使用绝对外部 links。
解决方法1.使用自己的include
创建一个 post_url.html 文件并写入:
{% include post_url.html slug="2018-09-06-peppermint" %}
include(称为 post_url.html)应该找到带有正确 slug 的 post 并回显 link,如下所示:
{% assign link = site.posts | where:'slug',include.slug %}
<a href="{{ link[0].url }}">{{ link[0].title }}</a>
解决方案 2. 搜索和替换
您必须解析 posts?对所有文件进行简单的搜索和替换,查找 (/2018/
并替换为 (/Archive/2018/
应该可以解决问题(如果您使用 markdown links)。这应该只需要几秒钟。
这是一个非常小众的问题,但是...我 运行 一个关于 Jekyll 的博客 运行 我经常 post 。为了让我的编辑保持理智,我定期存档 posts,那些存档的 posts 有一个非常严格的结构。但是,我整整一年才归档。
link 对其他 post 造成伤害的地方。我曾经能够绝对引用文件名(根据 jekyll markdown internal links),但这似乎已被弃用:
Deprecation: A call to '{% post_url 2018-09-06-peppermint %}' did not match a post using the new matching method of checking name (path-date-slug) equality. Please make sure that you change this tag to match the post's name exactly.
现在,如果我必须包含文件的完整路径,那么当我归档当年的 posts 时,我必须解析全年的所有 posts并更新它们之间的任何 links 以包含其存档位置的新文件路径,从而完全破坏了使用此工具的意义。直接 link 到页面实际上会更好,因为我不经常更改 URL 结构。
对于不依赖于文件结构的内部 link 是否有更好的解决方案,允许移动文件而不必更新每个 link 到该文件?
示例文件结构:
_posts
-2018
-post1
-post2
-etc
-Archive
-2017
-2016
如果没有更好的答案,我可能不得不回到使用绝对外部 links。
解决方法1.使用自己的include
创建一个 post_url.html 文件并写入:
{% include post_url.html slug="2018-09-06-peppermint" %}
include(称为 post_url.html)应该找到带有正确 slug 的 post 并回显 link,如下所示:
{% assign link = site.posts | where:'slug',include.slug %}
<a href="{{ link[0].url }}">{{ link[0].title }}</a>
解决方案 2. 搜索和替换
您必须解析 posts?对所有文件进行简单的搜索和替换,查找 (/2018/
并替换为 (/Archive/2018/
应该可以解决问题(如果您使用 markdown links)。这应该只需要几秒钟。