如何为Jekyll博客帖子创建目录?

Zan*_*ndo 30 markdown jekyll

如果我在Jekyll中有一个带标题的页面/帖子,是否可以自动生成目录/大纲以进行导航?类似于维基百科文章的最重要的东西.

man*_*ork 38

这是标记解析器的任务.

在Markdown的情况下,其中一个语法扩展定义了自动生成目录:

* This will become a table of contents (this text will be scraped).
{:toc}
Run Code Online (Sandbox Code Playgroud)

这部作品在Marukukramdown.

  • @CiroSantilli这里记录了[这里](http://kramdown.gettalong.org/converter/html.html#toc)._"只需使用IAL将引用名称"toc"分配给有序或无序列表,该列表将替换为实际的目录."_注意:仅将`{:toc}`放在哪里是不够的你想要目录.`{:toc}`必须紧跟在列表项之后. (4认同)
  • 好的,它可以工作,但前提是 Markdown 文件中有 H1 标头,根据此:http://webiva.lighthouseapp.com/projects/38599/tickets/5-maruku-table-of-contents-not-genating -没有额外的h1标签 (2认同)

Sha*_*mar 6

我有JOCyll博客的TOC,看起来类似于维基百科TOC 在此输入图像描述

所以我所有的Jekyll帖子都有一个目录部分.它可以使用kramdown完成.

在您希望显示TOC的帖子中使用此代码

* Do not remove this line (it will not be displayed)
{:toc}
Run Code Online (Sandbox Code Playgroud)

并使用这个CSS来设置它像维基百科TOC

// Adding 'Contents' headline to the TOC
#markdown-toc::before {
    content: "Contents";
    font-weight: bold;
}


// Using numbers instead of bullets for listing
#markdown-toc ul {
    list-style: decimal;
}

#markdown-toc {
    border: 1px solid #aaa;
    padding: 1.5em;
    list-style: decimal;
    display: inline-block;
}
Run Code Online (Sandbox Code Playgroud)

使用适合您博客的适当颜色.

这就对了!

如果在任何情况下上述方法都不起作用,TOC也可以在jekyll-of-contents的帮助下完成.这个使用Jquery和一个js文件.

以下是我如何做到的详细指南:Jekyll TOC