Skip to content

Commit 1a346c6

Browse files
committed
support table of contents for Markdown posts
1 parent ae0bdbe commit 1a346c6

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

exampleSite/content/about.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
title: About Hugo XMin
33
author: Yihui Xie
4+
toc: true
45
---
56

67
**XMin** is the first Hugo theme I have designed. The original reason that I wrote it was I needed a minimal example of Hugo themes when I was writing the [**blogdown**](https://github.com/rstudio/blogdown) book. Basically I wanted a simple theme that supports a navigation menu, a home page, other single pages, lists of pages, blog posts, categories, tags, and RSS. That is all. Nothing fancy. In terms of CSS and JavaScript, I really want to keep them minimal. In fact, this theme does not contain any JavaScript code at all, although on this example website I did introduce some JavaScript code (still relatively simple anyway). The theme does not contain any images, either, and is pretty much a plain-text theme.

layouts/_default/single.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ <h1><span class="title">{{ .Title | markdownify }}</span></h1>
55
{{ if (gt .Params.date 0) }}<h2 class="date">{{ .Date.Format "2006/01/02" }}</h2>{{ end }}
66
</div>
77

8+
{{ if .Params.toc }}
9+
{{ .TableOfContents }}
10+
{{ end }}
11+
812
<main>
913
{{ .Content }}
1014
</main>

static/css/style.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ hr {
2121
border-style: dashed;
2222
color: #ddd;
2323
}
24+
#TableOfContents, #TOC {
25+
border: 1px solid #eee;
26+
border-radius: 5px;
27+
}
2428

2529
/* code */
2630
pre {

0 commit comments

Comments
 (0)