Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/pjbakker/flexible-seo-hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul <paul@brainspark.nl>2020-02-28 22:59:24 +0300
committerPaul <paul@brainspark.nl>2020-02-28 22:59:24 +0300
commite24419cfaf2be745ffa87626d4e8f29e99320a42 (patch)
treecb53d4b9e20fb07d004445e35503a0de29d85abd
parentb15d5547a32408cabf1b8cda058f643aedc54dbe (diff)
Add breadcrumb list to pages
-rw-r--r--README.md4
-rw-r--r--layouts/_default/single.html8
-rw-r--r--layouts/partials/breadcrumbs.html42
-rw-r--r--layouts/partials/breadcrumbs/list/footer.html2
-rw-r--r--layouts/partials/breadcrumbs/list/header.html5
-rw-r--r--layouts/partials/breadcrumbs/list/item.html10
-rw-r--r--layouts/partials/breadcrumbs/recursive.html20
7 files changed, 91 insertions, 0 deletions
diff --git a/README.md b/README.md
index eb1ad25..6a5eef4 100644
--- a/README.md
+++ b/README.md
@@ -30,6 +30,10 @@ Within your `config.toml` add the according parameter you want the theme to use.
The theme will look for the theme parts in *layouts/partials/navs/*, *layouts/partials/headers/*, and *layouts/partials/footers/* accordingly. For instance, with `nav = "simple"`, it will look for *layouts/partials/navs/simple.html*.
+## Breadcrumbs
+
+By default a breadcrumb bar is shown at the top of each page other than Home. You can disable showing the breadcrumb bar at a site or page level by setting `showBreadcrumbs` to `false`.
+
## Enabling Analytics
Assuming you already signed up for [Google Analytics](https://www.google.com/analytics/), you can add your Google Tracking ID to the `googleAnalytics` parameter in `config.toml`. It will then automatically include Google Analytics code in your site.
diff --git a/layouts/_default/single.html b/layouts/_default/single.html
index e76edc3..596f113 100644
--- a/layouts/_default/single.html
+++ b/layouts/_default/single.html
@@ -1,5 +1,13 @@
{{ define "main" }}
+{{- $showBreadcrumbs := $.Params.showBreadcrumbs | default $.Site.Params.showBreadcrumbs | default true }}
<div class="container" role="main">
+ <div class="row justify-content-center">
+ <div class="col-md-8">
+ {{ if eq $showBreadcrumbs true -}}
+ {{ partial "breadcrumbs.html" ( dict "ctx" . "output_type" "list" ) }}
+ {{- end }}
+ </div>
+ </div>
<article>
<div class="row justify-content-center">
<div class="col-md-8">
diff --git a/layouts/partials/breadcrumbs.html b/layouts/partials/breadcrumbs.html
new file mode 100644
index 0000000..4ea756f
--- /dev/null
+++ b/layouts/partials/breadcrumbs.html
@@ -0,0 +1,42 @@
+{{- $ctx := .ctx }}
+{{- $output_type := .output_type }}
+{{- $header := print "breadcrumbs/" $output_type "/header.html" }}
+{{- $item := print "breadcrumbs/" $output_type "/item.html" }}
+{{- $footer := print "breadcrumbs/" $output_type "/footer.html" }}
+
+{{- with $ctx }}
+ {{- $path := split .URL "/" }}
+
+ {{ partial $header }}
+
+ {{- if eq .Kind "taxonomyTerm" }}
+
+ {{ partial $item (dict "caption" .Title "url" "" "level" 1 "image" "" "final" true) }}
+
+ {{- else if eq .Kind "taxonomy" }}
+
+ {{/* Find the taxonomyTerm and render */}}
+
+ {{- $taxonomyTerm := .Site.GetPage "taxonomyTerm" .Data.Plural }}
+ {{ partial $item (dict "caption" $taxonomyTerm.Title "url" $taxonomyTerm.URL "level" 1 "image" "" "final" false) }}
+
+ {{/* Render the taxonomy item */}}
+
+ {{ partial $item (dict "caption" .Title "url" .URL "level" 2 "image" "" "final" true) }}
+
+ {{- else if or ( eq .Kind "section" ) ( eq .Kind "page" ) }}
+
+ {{/* Display all relevant section elements */}}
+
+ {{- partial "breadcrumbs/recursive.html" (dict "output_type" $output_type "sections" .Site.Home.Sections "level" 1 "path" $path "dir" .URL ) }}
+
+ {{- if eq .Kind "page" }}
+
+ {{- $aux := split .URL "/" }}
+ {{ partial $item (dict "caption" .Title "url" .URL "level" (sub (len $aux) 2 ) "image" .Params.share_img "final" true ) }}
+
+ {{- end }}
+ {{- end }}
+
+ {{ partial $footer }}
+{{- end }}
diff --git a/layouts/partials/breadcrumbs/list/footer.html b/layouts/partials/breadcrumbs/list/footer.html
new file mode 100644
index 0000000..0672325
--- /dev/null
+++ b/layouts/partials/breadcrumbs/list/footer.html
@@ -0,0 +1,2 @@
+ </ol>
+</nav>
diff --git a/layouts/partials/breadcrumbs/list/header.html b/layouts/partials/breadcrumbs/list/header.html
new file mode 100644
index 0000000..241a289
--- /dev/null
+++ b/layouts/partials/breadcrumbs/list/header.html
@@ -0,0 +1,5 @@
+<nav aria-label="breadcrumb">
+ <ol class="breadcrumb">
+ <li class="breadcrumb-item active" aria-current="page">
+ <a href="/"><i class="fa fa-home"></i></a>
+ </li>
diff --git a/layouts/partials/breadcrumbs/list/item.html b/layouts/partials/breadcrumbs/list/item.html
new file mode 100644
index 0000000..4443419
--- /dev/null
+++ b/layouts/partials/breadcrumbs/list/item.html
@@ -0,0 +1,10 @@
+{{- $url := .url }}
+{{- $caption := .caption }}
+{{- $image := .image }}
+{{- $level := .level }}
+{{- $final := .final }}
+ <li class="breadcrumb-item {{ if eq $final true }}active{{ end }}" {{ if eq $final true }}aria-current="page"{{ end }}>
+ {{- if eq $final false }}<a href="{{ .url }}">{{- end }}
+ <small>{{ .caption }}</small>
+ {{- if eq $final false }}</a>{{- end }}
+ </li>
diff --git a/layouts/partials/breadcrumbs/recursive.html b/layouts/partials/breadcrumbs/recursive.html
new file mode 100644
index 0000000..97e8442
--- /dev/null
+++ b/layouts/partials/breadcrumbs/recursive.html
@@ -0,0 +1,20 @@
+{{- $sections := .sections }}
+{{- $level := .level }}
+{{- $path := .path }}
+{{- $dir := .dir }}
+{{- $output_type := .output_type }}
+{{- $item := print "breadcrumbs/" $output_type "/item.html" }}
+
+{{- range $sections }}
+ {{- $section := index $path $level }}
+ {{- $aux := split .URL "/" }}
+
+ {{- if eq $section (index $aux $level) }}
+ {{ partial $item (dict "caption" .Title "url" .URL "image" .Params.share_img "level" $level "final" (eq ( add $level 2 ) (len $path) ) ) }}
+
+ {{- if gt (len .Sections) 0 }}
+ {{- partial "breadcrumbs_recursive.html" ( dict "output_type" $output_type "sections" .Sections "level" (add $level 1) "path" $path "dir" $dir ) }}
+
+ {{- end }}
+ {{- end }}
+{{- end }}