Skip to content

Commit bbffff1

Browse files
KStockyimfing
andauthored
feat: support breadcrumbs for single pages that are neither docs or blogs (#743)
* feat: support breadcrumbs for single pages that are neither docs or blogs. * feat: support enabling breadcrumbs across different content types other than docs and blog docs: added docs and examples for enabling breadcrumbs for specific content types * feat: breadcrumbs being enabled is fully driven by the `breadcrumbs` front matter field. docs: updated docs to reflect that there is no site parameter driving breadcrumbs feat: enabled breadcrumbs for lists as well as singles for uniformity * Removing _partials/utils/default-breadcrumbs-enabled.html in favour of extra parameterization of _partials/breadcrumb.html * fix: change breadcrumbs parameter from `enabledByDefault` to `enable` to remain consistent with the rest of the theme * Update layouts/_partials/breadcrumb.html --------- Co-authored-by: Xin <[email protected]>
1 parent f9a94f0 commit bbffff1

File tree

8 files changed

+33
-8
lines changed

8 files changed

+33
-8
lines changed

exampleSite/content/docs/guide/organize-files.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,17 @@ This would now generate the following breadcrumbs:
180180
Documentation > Guide > Foo Bar
181181
```
182182

183-
### Hiding Breadcrumbs
183+
### Enabling and Disabling Breadcrumbs
184184

185-
You can hide breadcrumbs completely from a page by specifying `breadcrumbs: false` in its front matter:
185+
Whether breadcrumbs are enabled, or disabled, by default for a page, is determined by its [content type](https://gohugo.io/quick-reference/glossary/#content-type) and [page kind](https://gohugo.io/quick-reference/glossary/#page-kind):
186+
187+
| Content Type | Section | Page |
188+
|:----------------|:--------:|:----------|
189+
| `docs` | Enabled | Enabled |
190+
| `blog` | Disabled | Enabled |
191+
| Any other type | Disabled | Disabled |
192+
193+
You can override these defaults on a page by setting `breadcrumbs` in its front matter:
186194

187195
```yaml {filename="content/docs/guide/organize-files.md"}
188196
---
@@ -191,6 +199,18 @@ title: Organize Files
191199
---
192200
```
193201

202+
Similarly you can use [cascade](https://gohugo.io/content-management/front-matter/#cascade-1) to override the defaults on a page and its decendents:
203+
204+
```yaml {filename="content/portfolio/_index.md"}
205+
---
206+
title: "Portfolio"
207+
208+
cascade:
209+
params:
210+
breadcrumbs: true
211+
---
212+
```
213+
194214
## Configure Content Directory
195215

196216
By default, the root `content/` directory is used by Hugo to build the site.

layouts/_partials/breadcrumb.html

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
{{- if (default true .Params.breadcrumbs) }}
1+
{{- $page := .page -}}
2+
{{- $enable := .enable -}}
3+
{{- if (default $enable $page.Params.breadcrumbs) -}}
24
<div class="hx:mt-1.5 hx:flex hx:items-center hx:gap-1 hx:overflow-hidden hx:text-sm hx:text-gray-500 hx:dark:text-gray-400 hx:contrast-more:text-current">
3-
{{- range .Ancestors.Reverse }}
5+
{{- range $page.Ancestors.Reverse }}
46
{{- if not .IsHome }}
57
<div class="hx:whitespace-nowrap hx:transition-colors hx:min-w-[24px] hx:overflow-hidden hx:text-ellipsis hx:hover:text-gray-900 hx:dark:hover:text-gray-100">
68
<a href="{{ .RelPermalink }}">{{- partial "utils/title" . -}}</a>
@@ -9,7 +11,7 @@
911
{{ end -}}
1012
{{ end -}}
1113
<div class="hx:whitespace-nowrap hx:transition-colors hx:font-medium hx:text-gray-700 hx:contrast-more:font-bold hx:contrast-more:text-current hx:dark:text-gray-100 hx:contrast-more:dark:text-current">
12-
{{- partial "utils/title" . -}}
14+
{{- partial "utils/title" $page -}}
1315
</div>
1416
</div>
1517
{{ end -}}

layouts/blog/list.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
{{ partial "sidebar.html" (dict "context" . "disableSidebar" true "displayPlaceholder" true) }}
55
<article class="hx:w-full hx:break-words hx:flex hx:min-h-[calc(100vh-var(--navbar-height))] hx:min-w-0 hx:justify-center hx:pb-8 hx:pr-[calc(env(safe-area-inset-right)-1.5rem)]">
66
<main class="hx:w-full hx:min-w-0 hx:max-w-6xl hx:px-6 hx:pt-4 hx:md:px-12">
7+
{{ partial "breadcrumb.html" (dict "page" . "enable" false) }}
78
<br class="hx:mt-1.5 hx:text-sm" />
89
{{ if .Title }}<h1 class="hx:text-center hx:mt-2 hx:text-4xl hx:font-bold hx:tracking-tight hx:text-slate-900 hx:dark:text-slate-100">{{ .Title }}</h1>{{ end }}
910
<div class="content">{{ .Content }}</div>

layouts/blog/single.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{{ partial "toc.html" . }}
55
<article class="hx:w-full hx:break-words hx:flex hx:min-h-[calc(100vh-var(--navbar-height))] hx:min-w-0 hx:justify-center hx:pb-8 hx:pr-[calc(env(safe-area-inset-right)-1.5rem)]">
66
<main class="hx:w-full hx:min-w-0 hx:max-w-6xl hx:px-6 hx:pt-4 hx:md:px-12">
7-
{{ partial "breadcrumb.html" . }}
7+
{{ partial "breadcrumb.html" (dict "page" . "enable" true) }}
88
{{ if .Title }}<h1 class="hx:mt-2 hx:text-4xl hx:font-bold hx:tracking-tight hx:text-slate-900 hx:dark:text-slate-100">{{ .Title }}</h1>{{ end }}
99
<div class="hx:mt-4 hx:mb-16 hx:text-gray-500 hx:dark:text-gray-400 hx:text-sm hx:flex hx:items-center hx:flex-wrap hx:gap-y-2">
1010
{{- with $date := .Date }}<span class="hx:mr-1">{{ partial "utils/format-date" $date }}</span>{{ end -}}

layouts/docs/list.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{{ partial "toc.html" . }}
55
<article class="hx:w-full hx:break-words hx:flex hx:min-h-[calc(100vh-var(--navbar-height))] hx:min-w-0 hx:justify-center hx:pb-8 hx:pr-[calc(env(safe-area-inset-right)-1.5rem)]">
66
<main class="hx:w-full hx:min-w-0 hx:max-w-6xl hx:px-6 hx:pt-4 hx:md:px-12">
7-
{{ partial "breadcrumb.html" . }}
7+
{{ partial "breadcrumb.html" (dict "page" . "enable" true) }}
88
<div class="content">
99
{{ if .Title }}<h1>{{ .Title }}</h1>{{ end }}
1010
{{ .Content }}

layouts/docs/single.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{{ partial "toc.html" . }}
55
<article class="hx:w-full hx:break-words hx:flex hx:min-h-[calc(100vh-var(--navbar-height))] hx:min-w-0 hx:justify-center hx:pb-8 hx:pr-[calc(env(safe-area-inset-right)-1.5rem)]">
66
<main class="hx:w-full hx:min-w-0 hx:max-w-6xl hx:px-6 hx:pt-4 hx:md:px-12">
7-
{{ partial "breadcrumb.html" . }}
7+
{{ partial "breadcrumb.html" (dict "page" . "enable" true) }}
88
<div class="content">
99
{{ if .Title }}<h1>{{ .Title }}</h1>{{ end }}
1010
{{ .Content }}

layouts/list.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
{{ partial "toc.html" . }}
55
<article class="hx:w-full hx:break-words hx:flex hx:min-h-[calc(100vh-var(--navbar-height))] hx:min-w-0 hx:justify-center hx:pb-8 hx:pr-[calc(env(safe-area-inset-right)-1.5rem)]">
66
<main class="hx:w-full hx:min-w-0 hx:max-w-6xl hx:px-6 hx:pt-4 hx:md:px-12">
7+
{{ partial "breadcrumb.html" (dict "page" . "enable" false) }}
78
<div class="content">
89
{{ if .Title }}<h1>{{ .Title }}</h1>{{ end }}
910
{{ .Content }}

layouts/single.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
{{ partial "toc.html" . }}
55
<article class="hx:w-full hx:break-words hx:flex hx:min-h-[calc(100vh-var(--navbar-height))] hx:min-w-0 hx:justify-center hx:pb-8 hx:pr-[calc(env(safe-area-inset-right)-1.5rem)]">
66
<main class="hx:w-full hx:min-w-0 hx:max-w-6xl hx:px-6 hx:pt-4 hx:md:px-12">
7+
{{ partial "breadcrumb.html" (dict "page" . "enable" false) }}
78
<br class="hx:mt-1.5 hx:text-sm" />
89
{{ if .Title }}<h1 class="hx:text-center hx:mt-2 hx:text-4xl hx:font-bold hx:tracking-tight hx:text-slate-900 hx:dark:text-slate-100">{{ .Title }}</h1>{{ end }}
910
<div class="hx:mb-16"></div>

0 commit comments

Comments
 (0)