add include_toc options in FrontMatter

This commit is contained in:
Terry Rod 2019-04-02 14:22:00 +08:00
parent 160b3d9400
commit 5427aefb1f
2 changed files with 15 additions and 11 deletions

View file

@ -1,3 +1,4 @@
{{ $include_toc := .Params.include_toc}}
<article>
<header>
<h1>{{ .Title }}</h1>
@ -10,15 +11,17 @@
</header>
{{ $tableOfContents := .TableOfContents }}
{{ with .Site.Params.toc }}
<div class="toc-wrapper">
<input type="checkbox" id="tocToggle">
<label for="tocToggle">Table of Content</label>
{{ if eq . "hugo" }}
{{ $tableOfContents }}
{{ else if eq . "tocbot"}}
<div class="toc" id="TableOfContents"></div>
{{ end }}
</div>
{{ if ne $include_toc false }}
<div class="toc-wrapper">
<input type="checkbox" id="tocToggle">
<label for="tocToggle">Table of Content</label>
{{ if eq . "hugo" }}
{{ $tableOfContents }}
{{ else if eq . "tocbot"}}
<div class="toc" id="TableOfContents"></div>
{{ end }}
</div>
{{ end }}
{{ end }}
<div class="post">
{{ .Content }}

View file

@ -1,3 +1,4 @@
{{ $include_toc := .Params.include_toc}}
{{ if .Site.GoogleAnalytics }}
<!-- Google Analytics -->
{{ template "_internal/google_analytics_async.html" . }}
@ -5,8 +6,8 @@
{{ partial "footer/font-awesome-js.html" . }}
{{ partial "highlight-js.html" . }}
{{ with .Site.Params.toc }}
{{ if eq . "tocbot" }}
<script src="https://cdnjs.cloudflare.com/ajax/libs/tocbot/4.4.2/tocbot.js"></script>
{{ if and (eq . "tocbot") (ne $include_toc false) }}
<script src="/js/tocbot.js"></script>
<script type="text/javascript">
if (tocbot) {
tocbot.init({