hideToc param added, now enableToc logically same with toc

This commit is contained in:
zzossig 2019-12-26 15:44:04 +09:00
parent 43a4d17a74
commit 4cfd38b339
6 changed files with 26 additions and 20 deletions

View File

@ -246,6 +246,7 @@ enableSidebarTags = true # if you want to use tags.
enableSidebarSeries = true enableSidebarSeries = true
enableSidebarCategories = true enableSidebarCategories = true
enableToc = true # single page table of contents enableToc = true # single page table of contents
hideToc = false # Hide or Show toc
enableTocSwitch = true # single page table of contents visibility switch enableTocSwitch = true # single page table of contents visibility switch
itemsPerCategory = 5 # maximum number of posts shown in the sidebar. itemsPerCategory = 5 # maximum number of posts shown in the sidebar.

View File

@ -241,6 +241,7 @@ enableSidebarTags = true # if you want to use tags.
enableSidebarSeries = true enableSidebarSeries = true
enableSidebarCategories = true enableSidebarCategories = true
enableToc = true # single page table of contents enableToc = true # single page table of contents
hideToc = false # Hide or Show toc
enableTocSwitch = true # single page table of contents visibility switch enableTocSwitch = true # single page table of contents visibility switch
itemsPerCategory = 5 # maximum number of posts shown in the sidebar. itemsPerCategory = 5 # maximum number of posts shown in the sidebar.

View File

@ -3,7 +3,7 @@
{{ $enquire := resources.Get "js/enquire.min.js" | resources.Fingerprint }} {{ $enquire := resources.Get "js/enquire.min.js" | resources.Fingerprint }}
<script src="{{ $enquire.RelPermalink }}"></script> <script src="{{ $enquire.RelPermalink }}"></script>
<main class="{{ if $.Param "enableToc" }}main-main{{ else }}main{{ end }}"> <main class="{{ if or ($.Param "enableToc") ($.Param "toc") }}{{ if $.Param "hideToc" }}main{{ else }}main-main{{ end }}{{ else }}main{{ end }}">
{{ if eq .Site.Params.enableBreadcrumb true }} {{ if eq .Site.Params.enableBreadcrumb true }}
{{ partial "body/breadcrumb" . }} {{ partial "body/breadcrumb" . }}
{{ end }} {{ end }}
@ -30,7 +30,7 @@
</main> </main>
{{ if $.Param "enableSidebar" }} {{ if $.Param "enableSidebar" }}
<aside class="{{ if $.Param "enableToc" }}main-side{{ end }}"> <aside class="{{ if or ($.Param "enableToc") ($.Param "toc") }}main-side{{ end }}">
{{ partial "sidebar/sidebar-single" . }} {{ partial "sidebar/sidebar-single" . }}
</aside> </aside>
{{ end }} {{ end }}

View File

@ -23,7 +23,7 @@
<link rel="stylesheet" href="{{ $photoSwipeSkin.RelPermalink }}"> <link rel="stylesheet" href="{{ $photoSwipeSkin.RelPermalink }}">
{{ end }} {{ end }}
{{ if $.Param "enableToc" }} {{ if or ($.Param "enableToc") ($.Param "toc") }}
{{ $toc := resources.Get "js/jquery.toc.min.js" | resources.Fingerprint }} {{ $toc := resources.Get "js/jquery.toc.min.js" | resources.Fingerprint }}
<script defer src="{{ $toc.RelPermalink }}"></script> <script defer src="{{ $toc.RelPermalink }}"></script>
{{ end }} {{ end }}
@ -131,9 +131,13 @@
// toc // toc
{{ $enableToc := ($.Param "enableToc") }} {{ $enableToc := ($.Param "enableToc") }}
{{ $toc := ($.Param "toc") }}
{{ $hideToc := ($.Param "hideToc") }}
var enableToc = JSON.parse({{ $enableToc | jsonify }}); var enableToc = JSON.parse({{ $enableToc | jsonify }});
var toc = JSON.parse({{ $toc | jsonify }});
var hideToc = JSON.parse({{ $hideToc | jsonify }});
if (enableToc) { if (enableToc || toc) {
$("#toc").toc({ content: ".single__contents", headings: "h1,h2,h3,h4" }); $("#toc").toc({ content: ".single__contents", headings: "h1,h2,h3,h4" });
$('#toc > li').each(function () { $('#toc > li').each(function () {
$(this).find('ul').css('display', 'none'); $(this).find('ul').css('display', 'none');

View File

@ -1,17 +1,17 @@
{{ if $.Param "enableSidebar" }} {{ if $.Param "enableSidebar" }}
{{ if $.Param "enableToc" }} {{ if or ($.Param "enableToc") ($.Param "toc") }}
<section class="sidebar"> <section class="sidebar">
<div class="toc__flexbox" data-position="fixed"> <div class="toc__flexbox" data-position="{{ if $.Param "hideToc" }}absolute{{ else }}fixed{{ end }}">
<h6 class="toc__title">{{ i18n "toc-label" }}</h6> <h6 class="toc__title">{{ i18n "toc-label" }}</h6>
{{ if $.Param "enableTocSwitch" }} {{ if $.Param "enableTocSwitch" }}
<label class="switch"> <label class="switch">
<input id="toggle-toc" aria-label="Toggle TOC" type="checkbox" checked> <input id="toggle-toc" aria-label="Toggle TOC" type="checkbox" {{ if $.Param "hideToc" }}{{ else }}checked{{ end }}>
<span class="slider round"></span> <span class="slider round"></span>
</label> </label>
{{ end }} {{ end }}
</div> </div>
<div class="toc"> <div class="toc {{ if $.Param "hideToc" }}hide{{ end }}">
<ul id="toc"></ul> <ul id="toc"></ul>
</div> </div>
</section> </section>