Refactor sidebar logic + Add Table of Contents in reading page (#33)

* Refactor sidebar logic + fix responsiveness

* Add TOC

* Add Pagination

* Update exampleSite

* Update README.md
This commit is contained in:
Md. Emruz Hossain 2020-07-22 04:14:08 +06:00 committed by GitHub
parent 647578e88b
commit fa4d474974
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
59 changed files with 1735 additions and 679 deletions

View file

@ -0,0 +1,19 @@
<nav class="navbar navbar-expand-xl top-navbar final-navbar shadow">
<div class="container">
<button class="navbar-toggler navbar-light" id="sidebar-toggler" type="button" onclick="toggleSidebar()">
<span class="navbar-toggler-icon"></span>
</button>
<a class="navbar-brand" href="{{ site.BaseURL }}">
<img src="/assets/images/logo.png">
{{- site.Title -}}
</a>
<button class="navbar-toggler navbar-light" id="toc-toggler" type="button" onclick="toggleTOC()">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="top-nav-items">
<ul class="navbar-nav ml-auto">
</ul>
</div>
</div>
</nav>

View file

@ -0,0 +1,53 @@
<nav class="navbar navbar-expand-xl top-navbar initial-navbar" id="top-navbar">
<div class="container">
<a class="navbar-brand" href="{{ .Site.BaseURL }}">
<img src="/assets/images/logo-inverted.png" id="logo">
{{- .Site.Title -}}
</a>
<button
class="navbar-toggler navbar-dark"
id="navbar-toggler"
type="button"
data-toggle="collapse"
data-target="#top-nav-items"
>
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="top-nav-items">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link" href="#home">Home</a>
</li>
{{- if .Site.Data.sections }}
{{- range sort .Site.Data.sections "section.weight" }}
{{ if and (.section.enable) (.section.showOnNavbar)}}
<li class="nav-item">
<a class="nav-link" href="#{{ replace (lower .section.name) " " "-" }}">{{ .section.name }}</a>
</li>
{{ end }}
{{- end }}
{{- end }}
{{ $hasCustomMenus:= false }}
{{ if and site.Params.customMenus }}
{{ if gt (len site.Params.customMenus) 0 }}
{{ $hasCustomMenus = true }}
{{ end }}
{{ end }}
{{ if (or site.Params.enableBlogPost $hasCustomMenus) }}
<div class="dropdown-divider" id="top-navbar-divider"></div>
{{ end }}
{{ if site.Params.enableBlogPost }}
<li class="nav-item">
<a class="nav-link" id="blog-link" href="/posts">Posts</a>
</li>
{{ end }}
{{ range site.Params.customMenus }}
<li class="nav-item">
<a class="nav-link" href="{{ .url }}">{{ .name }}</a>
</li>
{{ end }}
</ul>
</div>
</div>
</nav>

View file

@ -0,0 +1,35 @@
<div class="row next-prev-navigator">
{{ $currentPage := . }}
{{ range (where site.RegularPages.ByDate "Type" "in" site.Params.mainSections )}}
{{ if eq .RelPermalink $currentPage.RelPermalink }}
{{ if .Next }}
{{ if (in site.Params.mainSections .Next.Type) }}
<div class="col-md-6 previous-article">
<a href="{{.Next.RelPermalink}}" class="btn btn-outline-info">
<span><i class="fas fa-chevron-circle-left"></i> Prev</span>
<br />
<span>{{ .Next.Title }}</span>
</a>
</div>
{{ end }}
{{ end }}
{{ if .Prev }}
{{ if (in site.Params.mainSections .Prev.Type) }}
{{ $columnWidth:="col-md-12" }}
{{ if .Next }}
{{ if (in site.Params.mainSections .Next.Type) }}
{{ $columnWidth = "col-md-6" }}
{{ end }}
{{ end}}
<div class="{{ $columnWidth }} next-article">
<a href="{{ .Prev.RelPermalink }}" class="btn btn-outline-info">
<span>Next <i class="fas fa-chevron-circle-right"></i></span>
<br />
<span>{{ .Prev.Title }}</span>
</a>
</div>
{{ end }}
{{ end }}
{{ end }}
{{ end }}
</div>

View file

@ -0,0 +1,22 @@
{{ range .menus }}
{{ $class:= "" }}
{{ $icon:= "fa-plus-circle" }}
<!-- If the current menu is the selected menu or it contain the selected menu, set expand icon and set "active" class -->
{{ if or ($.ctx.HasMenuCurrent "sidebar" .) ($.ctx.IsMenuCurrent "sidebar" .)}}
{{ $icon = "fa-minus-circle"}}
{{ $class = "active" }}
{{end}}
{{ if .HasChildren }}
<!-- Add current entry -->
<li>
<i class="fas {{ $icon }}"></i><a class="{{$class}}" href="{{.URL}}">{{.Name}}</a>
<!-- Add sub-tree -->
<ul class="{{ $class }}">
{{ partial "navigators/sidebar.html" (dict "menus" .Children "ctx" $.ctx) }}
</ul>
</li>
{{ else }}
<!-- No sub-tree. So, only add current entry -->
<li><a class="{{$class}}" href="{{.URL}}">{{.Name}}</a></li>
{{ end }}
{{ end }}