Skip to content

Commit

Permalink
✨ Feat: add separator and capitalize options for breadcrumb config
Browse files Browse the repository at this point in the history
  • Loading branch information
Lruihao committed Oct 1, 2024
1 parent f9dde8f commit ed8cf31
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 12 deletions.
4 changes: 2 additions & 2 deletions assets/css/_core/_breadcrumb.scss
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
.breadcrumb-item {
display: flex;

+.breadcrumb-item::before {
content: "/";
+ .breadcrumb-item::before {
content: attr(data-separator);
display: inline-block;
padding-inline: 0.5rem;
color: $global-font-secondary-color;
Expand Down
3 changes: 3 additions & 0 deletions hugo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,9 @@ enableEmoji = true
enable = false
sticky = false
showHome = false
# FixIt 0.3.13 | NEW
separator = "/"
capitalize = false

# FixIt 0.3.10 | NEW Post navigation config
[params.navigation]
Expand Down
10 changes: 7 additions & 3 deletions layouts/partials/breadcrumb.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{{- if (gt (len .Ancestors.Reverse) 1) | and (eq .Site.Params.breadcrumb.enable true) -}}
{{- $separator := .Site.Params.breadcrumb.separator | default "/" -}}
<nav aria-label="breadcrumb" class="breadcrumb-container{{ if .Site.Params.breadcrumb.sticky }} sticky{{ end }}">
<ol class="breadcrumb">
{{- range .Ancestors.Reverse -}}
Expand All @@ -20,13 +21,16 @@
{{- if .IsHome -}}
{{- $innerText = T "single.home" -}}
{{- else -}}
{{- $innerText = ((T (add .TranslationKey ".breadcrumbTitle")) | default (lower .LinkTitle | T) | default .LinkTitle) | title -}}
{{- $innerText = (T (add .TranslationKey ".breadcrumbTitle")) | default (lower .LinkTitle | T) | default .LinkTitle -}}
{{- $innerText = cond (.Param "breadcrumb.capitalize") (title $innerText) $innerText -}}
{{- end -}}

<li class="breadcrumb-item"><a href="{{ .RelPermalink }}" title="{{ $title }}">{{ $innerText }}</a></li>
<li class="breadcrumb-item" data-separator="{{ $separator }}"><a href="{{ .RelPermalink }}" title="{{ $title }}">{{ $innerText }}</a></li>
{{- end -}}

<li class="breadcrumb-item active" aria-current="page">{{ (T (add .TranslationKey ".breadcrumbTitle")) | default (lower .LinkTitle | T) | default .LinkTitle | title }}</li>
{{- $currentText := (T (add .TranslationKey ".breadcrumbTitle")) | default (lower .LinkTitle | T) | default .LinkTitle -}}
{{- $currentText = cond (.Param "breadcrumb.capitalize") (title $currentText) $currentText -}}
<li class="breadcrumb-item active" data-separator="{{ $separator }}" aria-current="page">{{ $currentText }}</li>
</ol>
</nav>
{{- end -}}
2 changes: 1 addition & 1 deletion layouts/partials/init/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- .Scratch.Set "version" "v0.3.12" -}}
{{- .Scratch.Set "version" "v0.3.13-b029036c" -}}
{{- .Scratch.Set "this" dict -}}

{{- partial "init/detection-env.html" . -}}
Expand Down
2 changes: 1 addition & 1 deletion layouts/partials/plugin/icon.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{{- $src = printf "%v/%v.svg" $prefix . -}}
{{- end -}}

{{ if not $src }}
{{- if not $src -}}
{{- errorf "Icon src is missing" -}}
{{- end -}}

Expand Down
2 changes: 1 addition & 1 deletion layouts/partials/plugin/link.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
{{- end -}}
{{- if
(.ExternalIcon | default false)
| and $external | and (eq (hasPrefix .Content `<img` ) false)
| and $external | and (eq (hasPrefix .Content `<img`) false)
| and (eq ((strings.HasSuffix .Content `</i>`) | or (strings.HasSuffix .Content `):`)) false)
-}}
{{- if .Download -}}
Expand Down
9 changes: 5 additions & 4 deletions layouts/partials/single/collection-list.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@
<div class="details-content collection-content">
<nav>
<ul class="collection-list">
{{- range $key, $value := $pages -}}
{{- $title := title $value.LinkTitle -}}
{{- if $value.LinkTitle | eq $.LinkTitle -}}
{{- range $key, $page := $pages -}}
{{- /* whether to capitalize the title, consistent with breadcrumb */ -}}
{{- $title := cond ($page.Param "breadcrumb.capitalize") (title $page.LinkTitle) $page.LinkTitle -}}
{{- if $page.LinkTitle | eq $.LinkTitle -}}
{{- $currentKey = $key -}}
<li class="collection-item"><span class="active" title="{{ $title }}">{{ $title }}</span></li>
{{- else }}
<li class="collection-item"><a href="{{ $value.RelPermalink }}" title="{{ $title }}">{{ $title }}</a></li>
<li class="collection-item"><a href="{{ $page.RelPermalink }}" title="{{ $title }}">{{ $title }}</a></li>
{{- end }}
{{- end -}}
</ul>
Expand Down

0 comments on commit ed8cf31

Please sign in to comment.