Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to show the table of contents #7

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions exampleSite/content/about.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
title: About Hugo XMin
author: Yihui Xie
toc: true
---

**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.
Expand Down
26 changes: 26 additions & 0 deletions exampleSite/content/post/2017-06-22-rmd-toc.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
title: Show Table of Contents for R Markdown Posts
date: '2017-06-22'
slug: rmd-toc
output:
blogdown::html_page:
toc: true
---

# One Section

A quick fox jumped over the lazy dog.

![quick fox](https://slides.yihui.name/gif/quick-fox.gif)

# Another Section

A quick fox jumped over the lazy dog.

## A subsection

A quick fox jumped over the lazy dog.

## Another subsection

A quick fox jumped over the lazy dog.
40 changes: 40 additions & 0 deletions exampleSite/content/post/2017-06-22-rmd-toc.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
title: Show Table of Contents for R Markdown Posts
date: '2017-06-22'
slug: rmd-toc
output:
blogdown::html_page:
toc: true
---


<div id="TOC">
<ul>
<li><a href="#one-section">One Section</a></li>
<li><a href="#another-section">Another Section</a><ul>
<li><a href="#a-subsection">A subsection</a></li>
<li><a href="#another-subsection">Another subsection</a></li>
</ul></li>
</ul>
</div>

<div id="one-section" class="section level1">
<h1>One Section</h1>
<p>A quick fox jumped over the lazy dog.</p>
<div class="figure">
<img src="https://slides.yihui.name/gif/quick-fox.gif" alt="quick fox" />
<p class="caption">quick fox</p>
</div>
</div>
<div id="another-section" class="section level1">
<h1>Another Section</h1>
<p>A quick fox jumped over the lazy dog.</p>
<div id="a-subsection" class="section level2">
<h2>A subsection</h2>
<p>A quick fox jumped over the lazy dog.</p>
</div>
<div id="another-subsection" class="section level2">
<h2>Another subsection</h2>
<p>A quick fox jumped over the lazy dog.</p>
</div>
</div>
4 changes: 4 additions & 0 deletions layouts/_default/single.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ <h1><span class="title">{{ .Title | markdownify }}</span></h1>
{{ if (gt .Params.date 0) }}<h2 class="date">{{ .Date.Format "2006/01/02" }}</h2>{{ end }}
</div>

{{ if .Params.toc }}
{{ .TableOfContents }}
{{ end }}

<main>
{{ .Content }}
</main>
Expand Down
4 changes: 4 additions & 0 deletions static/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ hr {
border-style: dashed;
color: #ddd;
}
#TableOfContents, #TOC {
border: 1px solid #eee;
border-radius: 5px;
}

/* code */
pre {
Expand Down