以下是我想要的最终结果:
<article itemscope itemtype="http://schema.org/BlogPosting">
<header>
<h1>Jekyll Table of Contents with Kramdown
</h1>
</header>
<nav aria-label="Table of Contents">
<ul>
<li>Topic 1</li>
<li>Topic 2</li>
<li>Topic 3</li>
</ul>
<nav>
<section itemprop="articleBody">
<p>the main body of the article</p>
</section>
</article>
使用默认的Jekyll安装,Kramdown可以使用
创建TOC* TOC
{:toc}
然而Markdown is not currently supported in HTML includes or Layout files。 我尝试使用[Capture and Markdownify}(https://github.com/jekyll/jekyll/issues/6166#issuecomment-322771527)将上面的TOC调用添加到布局文件中但没有成功
// _layouts/post.html
<article>
<header>
<h1>Jekyll Table of Contents with Kramdown
</h1>
</header>
{% capture toc %}{% include toc.md %}{% endcapture %}
{{ toc | markdownify }}
<section itemprop="articleBody">
<p>the main body of the article</p>
</section>
</article>
添加内联markdownify适用于普通降价,但不适用于Kramdown TOC调用。
// this works
{% capture md %}
## Heading 2
*Stuff added in my layout*
{% endcapture %}
{{ md | markdownify }}
// This doesn't work
{% capture md %}
* TOC
{:toc}
{% endcapture %}
{{ md | markdownify }}
我看到的唯一方法是在帖子的降价文件中加入一些布局标记。
// _layouts/post.html
<article>
<header>
<h1>Jekyll Table of Contents with Kramdown
</h1>
</header>
{{ content }}
</article>
// _posts/post.md
---
layout: post
---
<nav aria-label="Table of Contents">
* TOC
{:toc}
</nav>
<section itemprop="articleBody">
## My Heading
Standard markdown content here
</section>
这里的回顾是,我现在在我的帖子中有一个页面标记,很容易被破坏,并且会分散内容编辑的注意力。
有人看到这个方法吗?
答案 0 :(得分:2)
我发现了这个优秀的Ruby Gem jekyll-toc - 它会生成一个TOC,您可以放置在布局文件中的任何位置。
我现在已成功使用_layouts/post.html
中的以下内容:
<nav aria-label="Table of Contents">
{{ content | toc_only }}
</nav>
<section itemprop="articleBody">
{{ content }}
</section>