From bb1f3f9f1a202a415a105dfa811139c5b8e30968 Mon Sep 17 00:00:00 2001 From: Jeremy Karst Date: Thu, 19 Jun 2025 01:04:55 -0400 Subject: [PATCH] Added a page header option to disable the table of contents, meant for shorter pages. --- content/personal-blog/_index.md | 1 + layouts/_default/index.json | 20 ++++ layouts/partials/article-link.html | 82 +++++++++++++++ layouts/partials/extend-footer.html | 2 +- layouts/partials/head.html | 154 ++++++++++++++++++++++++++++ layouts/partials/schema.html | 97 ++++++++++++++++++ layouts/personal-blog/single.html | 2 +- 7 files changed, 356 insertions(+), 2 deletions(-) create mode 100644 layouts/_default/index.json create mode 100644 layouts/partials/article-link.html create mode 100644 layouts/partials/head.html create mode 100644 layouts/partials/schema.html diff --git a/content/personal-blog/_index.md b/content/personal-blog/_index.md index e23d34a..13513f5 100644 --- a/content/personal-blog/_index.md +++ b/content/personal-blog/_index.md @@ -5,6 +5,7 @@ description: "Projects, Guides, Thoughts and more." cascade: showEdit: false showSummary: true + # disableToc: true # Uncomment this line to disable the table of contents --- {{< lead >}} diff --git a/layouts/_default/index.json b/layouts/_default/index.json new file mode 100644 index 0000000..644dcf5 --- /dev/null +++ b/layouts/_default/index.json @@ -0,0 +1,20 @@ +{{- $index := slice -}} +{{- range .Site.Pages -}} + {{- $section := .Site.GetPage "section" .Section -}} + {{- $showDate := .Params.showDate | default .Site.Params.article.showDate -}} + {{- $summary := .Summary | emojify -}} + {{- $summary := replaceRE "]*>(.*?)" "$1" $summary -}} + {{- $summary := replaceRE "\\s*" " " $summary -}} + {{- $summary := replaceRE "\\s+" " " $summary -}} + {{- $summary := trim $summary " " -}} + {{- $index = $index | append (dict + "date" (cond (and .IsPage $showDate) (.Date | time.Format (site.Params.dateFormat | default ":date_long")) nil) + "title" (.Title | emojify | safeJS) + "section" ($section.Title | emojify | safeJS) + "summary" ($summary | safeJS) + "content" (.Plain | emojify | safeJS) + "permalink" .RelPermalink + ) + -}} +{{- end -}} +{{- $index | jsonify -}} \ No newline at end of file diff --git a/layouts/partials/article-link.html b/layouts/partials/article-link.html new file mode 100644 index 0000000..155e340 --- /dev/null +++ b/layouts/partials/article-link.html @@ -0,0 +1,82 @@ +
+ {{- $images := $.Resources.ByType "image" }} + {{- $thumbnail := $images.GetMatch (.Params.thumbnail | default "*thumb*") }} + {{- $feature := $images.GetMatch (.Params.feature | default "*feature*") | default $thumbnail }} + {{- with $feature }} +
+ + {{ $.Params.featureAlt | default $.Params.thumbnailAlt | default + +
+ {{- end }} +
+

+ {{ with .Params.externalUrl }} +
+ {{ $.Title | emojify }} + + + + +
+ {{ else }} + {{ .Title | emojify }} + {{ end }} + {{ if and .Draft .Site.Params.article.showDraftLabel }} +
+ {{ partial "badge.html" (i18n "article.draft" | emojify) }} +
+ {{ end }} + {{ if templates.Exists "partials/extend-article-link.html" }} + {{ partial "extend-article-link.html" . }} + {{ end }} +

+
+ {{ partial "article-meta.html" . }} +
+ {{ if .Params.showSummary | default (.Site.Params.list.showSummary | default false) }} +
+ {{ $summary := .Summary | emojify }} + {{ $summary := replaceRE "]*>(.*?)" "$1" $summary }} + {{ $summary := replaceRE "\\s*" " " $summary }} + {{ $summary := replaceRE "\\s+" " " $summary }} + {{ $summary := trim $summary " " }} + {{ $summary | safeHTML }} +
+ {{ end }} +
+
\ No newline at end of file diff --git a/layouts/partials/extend-footer.html b/layouts/partials/extend-footer.html index 7ee539b..3c25403 100644 --- a/layouts/partials/extend-footer.html +++ b/layouts/partials/extend-footer.html @@ -1,4 +1,4 @@ -{{ if .TableOfContents }} +{{ if and .TableOfContents (not (.Params.disableToc | default false)) }} {{ $tocHighlight := resources.Get "js/toc-highlight.js" | js.Build | fingerprint }} {{ end }} \ No newline at end of file diff --git a/layouts/partials/head.html b/layouts/partials/head.html new file mode 100644 index 0000000..999e28e --- /dev/null +++ b/layouts/partials/head.html @@ -0,0 +1,154 @@ + + + + + {{/* Title */}} + {{ if .IsHome -}} + {{ .Site.Title | emojify }} + + {{- else -}} + {{ .Title | emojify }} · {{ .Site.Title | emojify }} + + {{- end }} + {{/* Asset bundles */}} + {{ $assets := newScratch }} + {{ $algorithm := .Site.Params.fingerprintAlgorithm | default "sha256" }} + {{ $jsAppearance := resources.Get "js/appearance.js" }} + {{ $jsAppearance = $jsAppearance | resources.Minify | resources.Fingerprint $algorithm }} + + {{ $cssScheme := resources.Get (printf "css/schemes/%s.css" (lower .Site.Params.colorScheme | default "congo")) }} + {{ if not $cssScheme }} + {{ $cssScheme = resources.Get "css/schemes/congo.css" }} + {{ end }} + {{ $assets.Add "css" (slice $cssScheme) }} + {{ $cssMain := resources.Get "css/compiled/main.css" }} + {{ $assets.Add "css" (slice $cssMain) }} + {{ $cssCustom := resources.Get "css/custom.css" }} + {{ if $cssCustom }} + {{ $assets.Add "css" (slice $cssCustom) }} + {{ end }} + {{ $bundleCSS := $assets.Get "css" | resources.Concat "css/main.bundle.css" | resources.Minify | resources.Fingerprint $algorithm }} + + {{ if .Site.Params.enableSearch | default false }} + {{ $jsFuse := resources.Get "lib/fuse/fuse.min.js" }} + {{ $jsSearch := resources.Get "js/search.js" }} + {{ $assets.Add "js" (slice $jsFuse $jsSearch) }} + {{ end }} + {{ if .Site.Params.enableQuicklink | default false }} + {{ $jsQuicklink := resources.Get "lib/quicklink/quicklink.umd.js" }} + {{ $jsQuicklinkInit := resources.Get "js/quicklink.js" }} + {{ $assets.Add "js" (slice $jsQuicklink $jsQuicklinkInit) }} + {{ end }} + {{ if .Site.Params.enableCodeCopy | default false }} + {{ $jsCode := resources.Get "js/code.js" }} + {{ $assets.Add "js" (slice $jsCode) }} + {{ end }} + {{ if or (eq .Site.Params.header.layout "hamburger") (eq .Site.Params.header.layout "hybrid") }} + {{ $jsMenu := resources.Get "js/menu.js" }} + {{ $assets.Add "js" (slice $jsMenu) }} + {{ end }} + {{ if eq (site.Language.LanguageDirection | default "ltr") "rtl" }} + {{ $jsRTL := resources.Get "js/rtl.js" }} + {{ $assets.Add "js" (slice $jsRTL) }} + {{ end }} + {{ if $assets.Get "js" }} + {{ $bundleJS := $assets.Get "js" | resources.Concat "js/main.bundle.js" | resources.Minify | resources.Fingerprint $algorithm }} + + {{ end }} + {{/* Metadata */}} + {{- $description := "" -}} + {{- with .Description -}} + {{- $description = . -}} + {{- else -}} + {{- if .IsPage -}} + {{- $summary := .Summary -}} + {{- $summary := replaceRE "]*>(.*?)" "$1" $summary -}} + {{- $summary := replaceRE "\\s*" " " $summary -}} + {{- $summary := replaceRE "\\s+" " " $summary -}} + {{- $description = trim $summary " " -}} + {{- else -}} + {{- with .Site.Params.description -}} + {{- $description = . -}} + {{- end -}} + {{- end -}} + {{- end -}} + + {{ with union .Site.Params.keywords .Params.keywords -}} + + {{- end }} + {{ with .Site.Params.robots }} + + {{ end }} + {{ with .Params.robots }} + + {{ end }} + + {{ range .AlternativeOutputFormats -}} + {{ printf `` .Rel .MediaType.Type .RelPermalink ($.Site.Title | emojify) | safeHTML }} + {{ end -}} + {{/* Icons */}} + {{ if templates.Exists "partials/favicons.html" }} + {{ partialCached "favicons.html" .Site }} + {{ else }} + + + + + {{ end }} + {{/* Site Verification */}} + {{ with .Site.Params.verification.google }} + + {{ end }} + {{ with .Site.Params.verification.bing }} + + {{ end }} + {{ with .Site.Params.verification.pinterest }} + + {{ end }} + {{ with .Site.Params.verification.yandex }} + + {{ end }} + {{ with $.Params.externalUrl }} + + {{ end }} + {{/* Social */}} + {{ template "_internal/opengraph.html" . }} + {{ template "_internal/twitter_cards.html" . }} + {{/* Schema */}} + {{ partial "schema.html" . }} + {{/* Me */}} + {{ with .Site.Language.Params.Author.name }}{{ end }} + {{ with .Site.Language.Params.Author.links }} + {{ range $links := . }} + {{ range $name, $url := $links }}{{ end }} + {{ end }} + {{ end }} + {{/* Vendor */}} + {{ partial "vendor.html" . }} + {{/* Analytics */}} + {{ partial "analytics.html" . }} + {{/* Extend head - eg. for custom analytics scripts, etc. */}} + {{ if templates.Exists "partials/extend-head.html" }} + {{ partial "extend-head.html" . }} + {{ end }} + \ No newline at end of file diff --git a/layouts/partials/schema.html b/layouts/partials/schema.html new file mode 100644 index 0000000..7b2afa0 --- /dev/null +++ b/layouts/partials/schema.html @@ -0,0 +1,97 @@ +{{- define "partials/inline/breadcrumbData" -}} + {{- $scratchCtx := .scratch -}} + {{- with .parent }} + {{ partial "inline/breadcrumbData" (dict "scratch" $scratchCtx "parent" .Parent) }} + {{- $scratchCtx.Add "listItem" (slice (dict + "@type" "ListItem" + "position" ($scratchCtx.Get "count") + "name" (.Title | humanize | title) + "item" .Permalink + )) -}} + {{- $scratchCtx.Add "count" 1 -}} + {{- end }} +{{- end -}} + +{{ if .IsHome -}} + +{{ else if .IsPage }} + {{- $iso8601 := "2006-01-02T15:04:05-07:00" -}} + {{- $summary := .Summary -}} + {{- $summary := replaceRE "]*>(.*?)" "$1" $summary -}} + {{- $summary := replaceRE "\\s*" " " $summary -}} + {{- $summary := replaceRE "\\s+" " " $summary -}} + {{- $summary := trim $summary " " -}} + + {{- /* Source: https://bullaki.com/projects/web-design/seo-with-hugo-5-breadcrumbs/ */}} + {{- $scratch := newScratch -}} + {{- $scratch.Set "count" 1 -}} + {{ partial "inline/breadcrumbData" (dict "scratch" $scratch "parent" .Parent) }} + + {{- with index (.GetTerms "categories") 0 -}} + {{- $scratch.Add "listItem" (slice (dict + "@type" "ListItem" + "position" ($scratch.Get "count") + "name" .LinkTitle + "item" .Permalink + )) -}} + {{- $scratch.Add "count" 1 -}} + {{- end }} + + + {{- $scratch.Add "listItem" (slice (dict + "@type" "ListItem" + "position" ($scratch.Get "count") + "name" (.Title | humanize | title) + )) -}} + + {{- $scratch.SetInMap "breadcrumb" "@context" "https://schema.org" -}} + {{- $scratch.SetInMap "breadcrumb" "@type" "BreadcrumbList" -}} + {{- $scratch.SetInMap "breadcrumb" "itemListElement" ($scratch.Get "listItem") -}} + + +{{- end }} \ No newline at end of file diff --git a/layouts/personal-blog/single.html b/layouts/personal-blog/single.html index 1fbf7e3..1ee3e18 100644 --- a/layouts/personal-blog/single.html +++ b/layouts/personal-blog/single.html @@ -35,7 +35,7 @@ {{ end }}
- {{ if and (.Params.showTableOfContents | default (.Site.Params.article.showTableOfContents | default false)) (in .TableOfContents "
{{ partial "toc.html" . }}