如何在html模板中使用Jekyll toc? (* .md帖子文件之外)

时间:2018-02-04 12:00:26

标签: html templates jekyll

我想知道为什么在Jekyll post.html模板中使用TOC(以{{}}包围或不以任何方式呈现时不会呈现:

---
layout: default
---
<article class="post" itemscope itemtype="http://schema.org/BlogPosting">

  <header class="post-header">
    <h1 class="post-title" itemprop="name headline">{{ page.title }}</h1>
    <p class="post-meta"><time datetime="{{ page.date | date_to_xmlschema }}" itemprop="datePublished">{{ page.date | date: "%A, %B %-d, %Y" }}</time>{% if page.author %} • <span itemprop="author" itemscope itemtype="http://schema.org/Person"><span itemprop="name">{{ page.author }}</span></span>{% endif %}</p>
  </header>

  <div class="post-content" itemprop="articleBody">

    >> * TOC  <<
    >> {:toc} <<

    {{ content }}
  </div>

</article>

1 个答案:

答案 0 :(得分:-1)

您正在描述的目录功能是kramdown转换器的一项功能,这意味着您必须将toc生成代码添加到markdown文件内容中。正如我所见,你将它添加到`html。

我在.md文件的博客上以下列方式使用它: * TOC {:toc}

请注意,您可以使用.no_toc类名从内容生成中排除标题。

# Contents header {:.no_toc}

这意味着您可以在帖子.md文件中添加以下内容,以及将toc添加到您的内容的另一个原因:

# Table of contents {:.no_toc}

* TOC {:toc}

# Heading 1

## Heading 2

另请确保在markdown: kramdown中设置_config.yml。 (kramdown是GitHub页面上的默认值)。