Jekyll:将kramdown目录放在_include中以进行哈希导航

Rov*_*ion 7 tableofcontents jekyll kramdown

我想在页面的标题中引入哈希链接到网页的菜单中.该网页是使用Jekyll生成的,其默认布局如下所示:

<!DOCTYPE html>
<html>

  {% include head.html %}

  <body>

    {% include header.html %}

    <div id="BigFatContainer">
        {{ content }}
        {% include footer.html %}
    </div>
  </body>
</html>
Run Code Online (Sandbox Code Playgroud)

用于导航到不同页面的菜单位于标题中.我已经能够{{ content }}在以下Kramdown命令的帮助下添加目录:

* Point at which the TOC is attached
{:toc}
Run Code Online (Sandbox Code Playgroud)

人们可以使用一些丑陋的JavaScript劈死的内容本表从移动{{ content }},进入header.html但会是一个坏的解决方案.由于没有被Kramdown解析,所以不可能将{:toc}宏放在里面header.html,即使你确保Kramdown使用例如这个插件解析它,它也会输出内容的TOC header.md而不是TOC.

san*_*oon 2

@miroslav-nedyalkov 在这里走在正确的轨道上。按照他查看 Bootstrap 文档的建议,我发现它使用 Ruby Gem - jekyll-toc,允许您将 TOC 放置在布局文件中的任何位置。您可以在前面的内容中启用它。我现在成功使用:

<nav aria-label="Table of Contents">
    {{ content | toc_only }}
</nav>

<section itemprop="articleBody">
    {{ content }}
</section>
Run Code Online (Sandbox Code Playgroud)