我如何获得vanilla Markdown风格的相关链接以与vanilla Jekyll和Github页面一起工作? [英] How do I get vanilla Markdown style relative links to work with vanilla Jekyll and Github pages?

查看:122
本文介绍了我如何获得vanilla Markdown风格的相关链接以与vanilla Jekyll和Github页面一起工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

tl; dr 我希望Markdown,相关链接,Jekyll和Github页面能够很好地协作。我希望成为能够在Github上查看包含工作 vanilla Markdown风格的相关链接(即 [相对链接](other_file.md))的文件使用Jekyll的Github页面。



到目前为止,这与在Github上查看所述文件一起工作因为Github增加了对相关链接的支持



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



一些预处理器或其他方法,我可以用它来获得香草Markdown风格相关链接在Jekyll中工作,而不使用任何'不安全'插件? 解决方案

解决方案

Markdown,相关链接,Jekyll和Github页面在一起播放很好



Ma rkdown



Jekyll的默认Markdown解析器是 Kramdown 。它允许你在文件(page.md或page.markdown)和变量中写入markdown。



当你在变量中有一些标记时,你可以用{{variable |您的示例链接( [相对链接]) (other_file.md))会从你的页面到other_file.md兄弟页面呈现完美的相对链接。



你可以自由使用这个语法。



{{site.baseurl}} {{post.url这些变量在Jekyll中不是强制性的。



<$ 通常在for循环中找到c $ c> {{post.url}} ,并导致像 [{{post.title}}]({{post.url }})这只是自动化。您不必使用自动化功能。



{{site.baseurl}} {{site.url}} )是建立相对于网站根目录的链接的一个非常有用的变量。



A像 [相对链接](/ other_file.md)这样的链接只有在您的网站位于域的根目录时才有效,因为它转换为 /other_file.html
如果您的网站托管在 domain.tld.blog ,则此链接将错过目标。



如果您在 _config.yml 文件中设置 baseurl:/ blog
添加 [相对链接]({{site.baseurl}} / other_file.md)会为您提供完美的相对链接: /blog/other_file.html


tl;dr I want Markdown, relative links, Jekyll, and Github pages to play well together.

I would like to be able to view a file that contains working vanilla Markdown style relative links (i.e. [a relative link](other_file.md)) on Github and on Github pages using Jekyll.

So far this works with viewing said file on Github since Github added support for relative links.

However this doesn't work out of the box in Jekyll because it expects {{ site.baseurl }}{{ post.url }}.

Is there some preprocessor or other method I could use to get vanilla Markdown style relative links working in Jekyll without using any 'unsafe' plugins?

解决方案

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.

这篇关于我如何获得vanilla Markdown风格的相关链接以与vanilla Jekyll和Github页面一起工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆