-
-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add title utility to get page or section title (#325)
* feat: add title utility to get page or section title * with graceful fallback to using the directory or filename * chore: update link titles in breadcrumb, pager, and sidebar
- Loading branch information
Showing
4 changed files
with
32 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{{/* | ||
This utility is used to retrieve the title of a page or section. | ||
If no title is set, it falls back to using the directory or file name. | ||
|
||
Based on https://github.com/thegeeklab/hugo-geekdoc/blob/v0.44.0/layouts/partials/utils/title.html | ||
*/}} | ||
{{- $title := "" }} | ||
|
||
{{ if .LinkTitle }} | ||
{{ $title = .LinkTitle }} | ||
{{ else if .Title }} | ||
{{ $title = .Title }} | ||
{{ else if and .IsSection .File }} | ||
{{ $title = path.Base .File.Dir | humanize | title }} | ||
{{ else if and .IsPage .File }} | ||
{{ $title = .File.BaseFileName | humanize | title }} | ||
{{ end }} | ||
|
||
{{ return $title -}} |