jekyll markdown internal links

后端 未结 6 927
[愿得一人]
[愿得一人] 2020-12-07 09:28

Jekyll uses Markdown-formatted links, but how can I link to internal content?

[[link]] 
6条回答
  •  心在旅途
    2020-12-07 10:00

    There are multiple ways of linking in Jekyll, some of which are now outdated.

    With link tags

    The recommended way to link to internal files is

    [Link]({{ site.baseurl }}{% link path/to/file.md %})
    

    Note that this will cause an error if the file moves or gets deleted.

    With permalinks

    To link to a page without causing errors (broken links instead):

    [Link]({{ '/path/to/page/' | relative_url }})
    

    Note that here you need to know the permalink of the page and pass it through the relative_url filter to ensure that it is prefixed with the base url of the site.

    The permalink of a page depends on the permalink setting in your config file and the permalink key in the front matter of the file.

    With jekyll-relative-links

    If you want to use relative paths (and want the links to work in GitHub's markdown view), you should use jekyll-relative-links. This lets you write links like:

    [Link](./path/to/file.md)
    
    [Link to file in parent folder](../file.md)
    

提交回复
热议问题