1

tl;dr我希望 Markdown、相关链接、Jekyll 和 Github 页面能够很好地协同工作。

我希望能够在 Github 和使用 Jekyll 的 Github 页面上查看包含有效的vanilla Markdown 样式相关链接(即)的文件。[a relative link](other_file.md)

到目前为止,这适用于在 Github 上查看所述文件,因为 Github 添加了对相对链接的支持

然而,这在 Jekyll 中不能开箱即用,因为它期望{{ site.baseurl }}{{ post.url }}.

是否有一些预处理器或其他方法可以让我在 Jekyll 中使用香草 Markdown 风格的相关链接而不使用任何“不安全”插件?

4

2 回答 2

1

Markdown, relative links, Jekyll, and Github pages are playing well together

Markdown

Default Markdown parser for Jekyll is Kramdown. It allows you to write markdown in file (page.md or page.markdown) and in variables.

When you have some markdown in a variable, you can parse it with {{ variable | markdownify }}

Markdown links

Your example link ([a relative link](other_file.md)) will render a perfect relative link from you page to the other_file.md sibling page.

You are free to use this syntax.

{{ site.baseurl }} and {{ post.url }} variables

Those variables are not mandatory in Jekyll.

{{ post.url }} is often found in for loops and result in links like [{{ post.title }}]({{ post.url }}) and this is only automation. And you're not obliged to use automation.

{{ site.baseurl }} (which is different from {{ site.url }}) is a very useful variable to build links relative to site root.

A link like [a relative link](/other_file.md) will only work if your site is at the root of a domain, because it converted like /other_file.html. If you site is hosted at domain.tld.blog, this link will miss is target.

If you set baseurl: /blog in your _config.yml file. Adding [a relative link]({{ site.baseurl }}/other_file.md) will give you the perfect relative link to root : /blog/other_file.html.

于 2015-01-10T19:39:52.237 回答
-1

我正在使用 Cory Gross docsync 方法,该方法在页面加载后使用 javascript 来操作相对链接。这允许香草风格的链接。

于 2015-07-21T04:33:34.233 回答