简体   繁体   English

Jekyll降价链接标题

[英]Jekyll markdown titles to links

I'm using Jekyll for my static blog. 我将Jekyll用于我的静态博客。 I write the posts using Markdown. 我使用Markdown撰写帖子。

The problem I have is that Jekyll does not create the links associated with the titles . 我的问题是Jekyll不会创建与标题关联的链接 And I would try to do that without using Javascript. 我会尝试不使用Javascript来做到这一点。

Here is an example, let's call this page mysite.com/page 这是一个示例,我们将此页面称为mysite.com/page

# My title

bla bla bla

I would like Jekyll to include a link to mysite.com/page/#my-title or mysite.com/page#my-title as both work typing them by hand. 我希望Jekyll包含指向mysite.com/page/#my-titlemysite.com/page#my-title的链接,因为两者都可以手动键入。 Just like it is possible on any Github readme (see here for instance) 就像在任何Github自述文件中都有可能(例如,请参见此处

I am using Kramdown: 我正在使用Kramdown:

markdown:      kramdown
markdown_ext:  markdown,mkd,mkdn,md
textile_ext:   textile
kramdown:
  input: GFM
  syntax_highlighter: rouge
excerpt_separator: "<!-- more -->"

Ok solved it thanks to @streetturtle and the issue on Github. 好了,感谢@streetturtle和Github上的问题,解决了。

Anchor JS 锚JS

I'm using the Anchor JS script, and add it to my html templates 我正在使用Anchor JS脚本,并将其添加到我的html模板中

<script src="//cdnjs.cloudflare.com/ajax/libs/anchor-js/3.2.0/anchor.min.js"></script>

Usage 用法

In a new script I simply add the following lines : 在新脚本中,我只需添加以下几行:

document.addEventListener("DOMContentLoaded", function(event) {
  anchors.add('article section h1, h2, h3, h4, h5, h6');
  anchors.options.placement = 'left';
});

What you want to have is called anchor links. 您想要拥有的称为锚链接。 Kramdown should support them by default (check in _config.xml if it's turned on). 默认情况下,Kramdown应该支持它们(如果已启用_config.xml请签入)。 Otherwise there is an issue on jekyll github page, where you can find more details. 否则,jekyll github页面上会有问题 ,您可以在其中找到更多详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM