Skip to content

Commit

Permalink
init feat Breadcrumb Navigation (adityatelange#207)
Browse files Browse the repository at this point in the history
* adds Breadcrumb nav above title of single page/post
* add enabler var 'ShowBreadCrumbs'
* introduce i18n var "home"

usage:
in site config:
Params:
    ShowBreadCrumbs: true

in page front-matter:
ShowBreadCrumbs: false
  • Loading branch information
adityatelange authored Jan 29, 2021
1 parent a7e0b2f commit 75855b2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
7 changes: 6 additions & 1 deletion assets/css/post-single.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
margin-bottom: 5px;
}

.post-meta {
.post-meta,
.breadcrumbs {
color: var(--secondary);
font-size: 14px;
display: flex;
Expand All @@ -26,6 +27,10 @@
box-shadow: 0 1px 0 var(--secondary)
}

.breadcrumbs a {
font-size: 16px;
}

.post-content {
color: var(--content)
}
Expand Down
3 changes: 3 additions & 0 deletions i18n/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@

- id: translations
translation: "Translations"

- id: home
translation: "Home"
18 changes: 18 additions & 0 deletions layouts/_default/single.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,24 @@

<article class="post-single">
<header class="post-header">
{{- if (.Param "ShowBreadCrumbs")}}
<div class="breadcrumbs">
{{- $url := replace .Permalink ( printf "%s" .Site.BaseURL) "" }}
{{- $lang_url := replace $url ( printf "%s" .Lang) "" }}

<a href="{{ "" | absLangURL }}">{{ i18n "home" | default "Home"}}</a>
{{- range $index, $element := split $lang_url "/" }}

{{- $.Scratch.Add "path" (printf "%s/" $element )}}
{{- $bc_pg := $.Site.GetPage ($.Scratch.Get "path") -}}

{{- if (and ($bc_pg) (gt (len . ) 0))}}
{{- print "&nbsp;»&nbsp;" | safeHTML -}}<a href="{{ $bc_pg.Permalink }}">{{ $bc_pg.Name }}</a>
{{- end }}

{{- end }}
</div>
{{- end }}
<h1 class="post-title">
{{ .Title }}
{{- if .Draft }}<div class="entry-isdraft"><sup>&nbsp;&nbsp;[draft]</sup></div>{{- end }}
Expand Down

0 comments on commit 75855b2

Please sign in to comment.