Jekyll:使用指向内部markdown文件的链接

时间:2023-01-15 00:21:29

md file with a link to Folder/file.md

带文件夹/文件.md链接的md文件

When jekyll generates the index the link to the file is still folder/file.md and so doesn't connect to the generated file.html. Can jekyll replace links in markdown with their corresponding html files?

当jekyll生成索引时,文件的链接仍然是文件夹/文件。md和so不连接到生成的文件。html。jekyll可以用相应的html文件替换markdown中的链接吗?

I really want to to maintain my folder structure (7 or so subfolders, each with 3 markdown files).

我真的想维护我的文件夹结构(7个左右的子文件夹,每个都有3个markdown文件)。

5 个解决方案

#1


5  

The answer since December 2016 is to use the jekyll-relative-links plugin.

2016年12月以来的答案是使用jekyll-相对论链接插件。

It is a white-listed plugin if you are hosting on GitHub pages so you probably already have it.

如果你是在GitHub上托管的话,它是一个白名单的插件,所以你可能已经有了它。


If you are not using GitHub pages you will need the following installation instructions (from the README):

如果您不使用GitHub页面,您将需要以下安装说明(来自README):

1.Add the following to your site's Gemfile:

1。将以下内容添加到站点的Gemfile中:

gem 'jekyll-relative-links'

2.Add the following to your site's config file:

2。在站点的配置文件中添加以下内容:

gems:
  - jekyll-relative-links

#2


2  

i've written a simple plugin to solve this. put this in _plugins/, and make links refer to the *.md files (so github rendering linking works); if you build it with jekyll (when you are able to run plugins) the links are changed to *.html. since github doesn't run plugins, this isn't applied.

我写了一个简单的插件来解决这个问题。把这个放入_plugins/,并使链接指向*。md文件(github渲染链接工作);如果您使用jekyll(当您能够运行插件)构建它时,链接将被更改为*.html。因为github不运行插件,所以这并不适用。

module ChangeLocalMdLinksToHtml
  class Generator < Jekyll::Generator
    def generate(site)
      site.pages.each { |p| rewrite_links(site, p) }
    end
    def rewrite_links(site, page)
      page.content = page.content.gsub(/(\[[^\]]*\]\([^:\)]*)\.md\)/, '\1.html)')
    end
  end
end

it's not perfect (i'm sure you could fool the regex) but it has been good enough for my purpose.

它并不完美(我相信您可以骗过regex),但它已经足够符合我的目的了。

#3


1  

The tag you're looking for is {% link %} and it arrived in 2016.

您正在寻找的标签是{% link %},它在2016年到达。

If you had {% link _funkyCollection/banjo.md %} it would generate the right path to the output file funkyCollection/banjo.html, or funkyCollection/banjo/index.html, or whatever, wherever it ends up being.

如果您有{% link _funkyCollection/banjo。它将生成输出文件funkyCollection/banjo的正确路径。html或funkyCollection /班卓琴/索引。html,或者别的什么,不管它在哪里。

#4


0  

A Folder/file.md page will result in creation of a _site/Folder/file.html page.

一个文件夹/文件。md页面将导致创建一个_site/文件夹/文件。html页面。

So when your link to this page it's [Link to page]({{site.baseurl}}/Folder/file.html) not [Link to page]({{site.baseurl}}/Folder/file.md).

因此,当您链接到这个页面时,它(链接到页面)({site.baseurl} /Folder/file.html)不[链接到页面]({{site.baseurl}}/文件夹/文件.md)。

Jekyll will never rewrite file.md to file.html in url. So you have to set your links targets yourself to the resulting page.url which is usually a html file but can be css, je, json, ...

Jekyll永远不会重写文件。md文件。html在url。所以你必须设置你自己的链接目标到结果页面。url通常是一个html文件,但是可以是css, je, json…

If you use permalink: /folder/folder/ in any file.md, it will generate a /folder/folder/index.html file which can be reached with [Link to page]({{site.baseurl}}/folder/folder/)

如果您使用permalink: /文件夹/文件夹/任何文件。md,它会生成一个/文件夹/文件夹/索引。可以通过[链接到页面]({{{site.baseurl}}/文件夹/文件夹/)访问的html文件

#5


0  

I've run into this and written a basic Jekyll/Kramdown plugin. It's less likely to break than the regular expression approach.

我遇到了这个,并编写了一个基本的Jekyll/Kramdown插件。与正则表达式方法相比,它不太可能中断。

As long as your link doesn't start with http:// or something like it, and ends with .md, it will convert links to their lowercased and hyphenated names.

只要你的链接不是以http://之类的开头,以.md结尾,它就会将链接转换为小写和连字符名。

Of course, you could always modify the behavior to fit your needs.

当然,您可以随时修改行为以适应您的需要。

#1


5  

The answer since December 2016 is to use the jekyll-relative-links plugin.

2016年12月以来的答案是使用jekyll-相对论链接插件。

It is a white-listed plugin if you are hosting on GitHub pages so you probably already have it.

如果你是在GitHub上托管的话,它是一个白名单的插件,所以你可能已经有了它。


If you are not using GitHub pages you will need the following installation instructions (from the README):

如果您不使用GitHub页面,您将需要以下安装说明(来自README):

1.Add the following to your site's Gemfile:

1。将以下内容添加到站点的Gemfile中:

gem 'jekyll-relative-links'

2.Add the following to your site's config file:

2。在站点的配置文件中添加以下内容:

gems:
  - jekyll-relative-links

#2


2  

i've written a simple plugin to solve this. put this in _plugins/, and make links refer to the *.md files (so github rendering linking works); if you build it with jekyll (when you are able to run plugins) the links are changed to *.html. since github doesn't run plugins, this isn't applied.

我写了一个简单的插件来解决这个问题。把这个放入_plugins/,并使链接指向*。md文件(github渲染链接工作);如果您使用jekyll(当您能够运行插件)构建它时,链接将被更改为*.html。因为github不运行插件,所以这并不适用。

module ChangeLocalMdLinksToHtml
  class Generator < Jekyll::Generator
    def generate(site)
      site.pages.each { |p| rewrite_links(site, p) }
    end
    def rewrite_links(site, page)
      page.content = page.content.gsub(/(\[[^\]]*\]\([^:\)]*)\.md\)/, '\1.html)')
    end
  end
end

it's not perfect (i'm sure you could fool the regex) but it has been good enough for my purpose.

它并不完美(我相信您可以骗过regex),但它已经足够符合我的目的了。

#3


1  

The tag you're looking for is {% link %} and it arrived in 2016.

您正在寻找的标签是{% link %},它在2016年到达。

If you had {% link _funkyCollection/banjo.md %} it would generate the right path to the output file funkyCollection/banjo.html, or funkyCollection/banjo/index.html, or whatever, wherever it ends up being.

如果您有{% link _funkyCollection/banjo。它将生成输出文件funkyCollection/banjo的正确路径。html或funkyCollection /班卓琴/索引。html,或者别的什么,不管它在哪里。

#4


0  

A Folder/file.md page will result in creation of a _site/Folder/file.html page.

一个文件夹/文件。md页面将导致创建一个_site/文件夹/文件。html页面。

So when your link to this page it's [Link to page]({{site.baseurl}}/Folder/file.html) not [Link to page]({{site.baseurl}}/Folder/file.md).

因此,当您链接到这个页面时,它(链接到页面)({site.baseurl} /Folder/file.html)不[链接到页面]({{site.baseurl}}/文件夹/文件.md)。

Jekyll will never rewrite file.md to file.html in url. So you have to set your links targets yourself to the resulting page.url which is usually a html file but can be css, je, json, ...

Jekyll永远不会重写文件。md文件。html在url。所以你必须设置你自己的链接目标到结果页面。url通常是一个html文件,但是可以是css, je, json…

If you use permalink: /folder/folder/ in any file.md, it will generate a /folder/folder/index.html file which can be reached with [Link to page]({{site.baseurl}}/folder/folder/)

如果您使用permalink: /文件夹/文件夹/任何文件。md,它会生成一个/文件夹/文件夹/索引。可以通过[链接到页面]({{{site.baseurl}}/文件夹/文件夹/)访问的html文件

#5


0  

I've run into this and written a basic Jekyll/Kramdown plugin. It's less likely to break than the regular expression approach.

我遇到了这个,并编写了一个基本的Jekyll/Kramdown插件。与正则表达式方法相比,它不太可能中断。

As long as your link doesn't start with http:// or something like it, and ends with .md, it will convert links to their lowercased and hyphenated names.

只要你的链接不是以http://之类的开头,以.md结尾,它就会将链接转换为小写和连字符名。

Of course, you could always modify the behavior to fit your needs.

当然,您可以随时修改行为以适应您的需要。