mirror of
https://github.com/imfing/hextra.git
synced 2025-06-20 09:31:23 -04:00
chore: adapt theme to new template system (#696)
* Adapted theme's layout to [Hugo v0.146.0](https://gohugo.io/templates/new-templatesystem-overview/) * Bumped minimal Hugo version to v0.146.0
This commit is contained in:
21
layouts/_partials/utils/file-path.html
Normal file
21
layouts/_partials/utils/file-path.html
Normal file
@ -0,0 +1,21 @@
|
||||
{{/* This utility is used to get the file path from absolute, relative path or URL. */}}
|
||||
|
||||
{{- $path := .path -}}
|
||||
{{- $page := .page -}}
|
||||
|
||||
{{- $isLocal := not (urls.Parse $path).Scheme -}}
|
||||
{{- $isPage := and (eq $page.Kind "page") (not $page.BundleType) -}}
|
||||
{{- $startsWithSlash := hasPrefix $path "/" -}}
|
||||
{{- $startsWithRelative := hasPrefix $path "../" -}}
|
||||
|
||||
{{- if and $path $isLocal -}}
|
||||
{{- if $startsWithSlash -}}
|
||||
{{/* File under static directory */}}
|
||||
{{- $path = (relURL (strings.TrimPrefix "/" $path)) -}}
|
||||
{{- else if and $isPage (not $startsWithRelative) -}}
|
||||
{{/* File is a sibling to the individual page file */}}
|
||||
{{ $path = (printf "../%s" $path) }}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- return $path -}}
|
3
layouts/_partials/utils/format-date.html
Normal file
3
layouts/_partials/utils/format-date.html
Normal file
@ -0,0 +1,3 @@
|
||||
{{- with . -}}
|
||||
{{- . | time.Format (site.Params.dateFormat | default ":date_long") -}}
|
||||
{{- end -}}
|
62
layouts/_partials/utils/fragments.html
Normal file
62
layouts/_partials/utils/fragments.html
Normal file
@ -0,0 +1,62 @@
|
||||
{{/* Split page raw content into fragments */}}
|
||||
{{ $page := .context }}
|
||||
{{ $type := .type | default "content" }}
|
||||
|
||||
{{ $headingKeys := slice }}
|
||||
{{ $headingTitles := slice }}
|
||||
|
||||
{{ range $h1 := $page.Fragments.Headings }}
|
||||
{{ if eq $h1.Title "" }}
|
||||
{{ $headingKeys = $headingKeys | append $h1.Title }}
|
||||
{{ else }}
|
||||
{{ $headingKeys = $headingKeys | append (printf "%s#%s" $h1.ID $h1.Title) }}
|
||||
{{ end }}
|
||||
{{ $headingTitles = $headingTitles | append (printf "# %s" $h1.Title) }}
|
||||
|
||||
{{ range $h2 := $h1.Headings }}
|
||||
{{ $headingKeys = $headingKeys | append (printf "%s#%s" $h2.ID $h2.Title) }}
|
||||
{{ $headingTitles = $headingTitles | append (printf "## %s" $h2.Title) }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
|
||||
{{ $content := $page.RawContent }}
|
||||
{{ $len := len $headingKeys }}
|
||||
{{ $data := dict }}
|
||||
|
||||
{{ if eq $type "content" }}
|
||||
{{/* Include full content of the page */}}
|
||||
{{ if eq $len 0 }}
|
||||
{{ $data = $data | merge (dict "" ($page.Plain | htmlUnescape | chomp)) }}
|
||||
{{ else }}
|
||||
{{/* Split the raw content from bottom to top */}}
|
||||
{{ range seq $len }}
|
||||
{{ $i := sub $len . }}
|
||||
{{ $headingKey := index $headingKeys $i }}
|
||||
{{ $headingTitle := index $headingTitles $i }}
|
||||
|
||||
{{ if eq $i 0 }}
|
||||
{{ $data = $data | merge (dict $headingKey ($content | $page.RenderString | plainify | htmlUnescape | chomp)) }}
|
||||
{{ else }}
|
||||
{{ $parts := split $content (printf "\n%s\n" $headingTitle) }}
|
||||
{{ $lastPart := index $parts (sub (len $parts) 1) }}
|
||||
|
||||
{{ $data = $data | merge (dict $headingKey ($lastPart | $page.RenderString | plainify | htmlUnescape | chomp)) }}
|
||||
{{ $content = strings.TrimSuffix $lastPart $content }}
|
||||
{{ $content = strings.TrimSuffix (printf "\n%s\n" $headingTitle) $content }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ else if (eq $type "heading" ) }}
|
||||
{{/* Put heading keys with empty content to the data object */}}
|
||||
{{ $data = dict "" "" }}
|
||||
{{ range $headingKeys }}
|
||||
{{ $data = $data | merge (dict . "") }}
|
||||
{{ end }}
|
||||
{{ else if (eq $type "title") }}
|
||||
{{/* Use empty data object since title is included in search-data.json */}}
|
||||
{{ $data = $data | merge (dict "" "") }}
|
||||
{{ else if (eq $type "summary" ) }}
|
||||
{{ $data = $data | merge (dict "" ($page.Summary | plainify | htmlUnescape | chomp)) }}
|
||||
{{ end }}
|
||||
|
||||
{{ return $data }}
|
14
layouts/_partials/utils/icon.html
Normal file
14
layouts/_partials/utils/icon.html
Normal file
@ -0,0 +1,14 @@
|
||||
{{/* Render raw svg icon from .Site.Data */}}
|
||||
{{- $icon := index site.Data.icons .name -}}
|
||||
|
||||
{{- if not $icon -}}
|
||||
{{ errorf "icon %q not found" .name }}
|
||||
{{- end -}}
|
||||
|
||||
{{- $icon = $icon | safeHTML -}}
|
||||
|
||||
{{- if .attributes -}}
|
||||
{{- $icon = replaceRE "<svg" (printf "<svg %s" .attributes) $icon -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- return ($icon | safeHTML) -}}
|
25
layouts/_partials/utils/lang-link.html
Normal file
25
layouts/_partials/utils/lang-link.html
Normal file
@ -0,0 +1,25 @@
|
||||
{{/* Get relative link of a page for given language */}}
|
||||
{{/* If not found, return the homepage of the language page */}}
|
||||
|
||||
{{ $page := .context }}
|
||||
{{ $lang := .lang }}
|
||||
|
||||
{{ $link := false }}
|
||||
|
||||
{{ range $page.AllTranslations }}
|
||||
{{ if eq .Language.Lang $lang }}
|
||||
{{ $link = .RelPermalink }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
|
||||
{{ if not $link }}
|
||||
{{ range where $page.Sites ".Language.Lang" $lang }}
|
||||
{{ $link = .Home.RelPermalink }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
|
||||
{{ if not $link }}
|
||||
{{ $link = site.Home.RelPermalink }}
|
||||
{{ end }}
|
||||
|
||||
{{ return $link }}
|
11
layouts/_partials/utils/page-description.html
Normal file
11
layouts/_partials/utils/page-description.html
Normal file
@ -0,0 +1,11 @@
|
||||
{{ with .Description | plainify | htmlUnescape -}}
|
||||
{{ . -}}
|
||||
{{ else -}}
|
||||
{{ if .IsHome -}}
|
||||
{{ with .Site.Params.description | plainify | htmlUnescape -}}
|
||||
{{ . -}}
|
||||
{{ end -}}
|
||||
{{ else -}}
|
||||
{{ .Summary | plainify | htmlUnescape | chomp -}}
|
||||
{{ end -}}
|
||||
{{ end -}}
|
32
layouts/_partials/utils/sort-pages.html
Normal file
32
layouts/_partials/utils/sort-pages.html
Normal file
@ -0,0 +1,32 @@
|
||||
{{- $page := .page -}}
|
||||
{{- $by := .by | default "weight" -}}
|
||||
{{- $order := .order | default "asc" -}}
|
||||
|
||||
{{- $pages := slice }}
|
||||
|
||||
{{- if eq $by "weight" }}
|
||||
{{- $pages = $page.Pages.ByWeight }}
|
||||
{{- else if eq $by "date" }}
|
||||
{{- $pages = $page.Pages.ByDate }}
|
||||
{{- else if eq $by "title" }}
|
||||
{{- $pages = $page.Pages.ByTitle }}
|
||||
{{- else if eq $by "expiryDate" }}
|
||||
{{- $pages = $page.Pages.ByExpiryDate }}
|
||||
{{- else if eq $by "publishDate" }}
|
||||
{{- $pages = $page.Pages.ByPublishDate }}
|
||||
{{- else if eq $by "lastmod" }}
|
||||
{{- $pages = $page.Pages.ByLastmod }}
|
||||
{{- else if eq $by "linkTitle" }}
|
||||
{{- $pages = $page.Pages.ByLinkTitle }}
|
||||
{{- else if eq $by "length" }}
|
||||
{{- $pages = $page.Pages.ByLength }}
|
||||
{{- else }}
|
||||
{{- warnf "sort-pages: unknown sort field %q" $by -}}
|
||||
{{- $pages = $page.Pages }}
|
||||
{{ end -}}
|
||||
|
||||
{{- if eq $order "desc" }}
|
||||
{{- $pages = $pages.Reverse }}
|
||||
{{- end -}}
|
||||
|
||||
{{- return $pages -}}
|
19
layouts/_partials/utils/title.html
Normal file
19
layouts/_partials/utils/title.html
Normal file
@ -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 -}}
|
Reference in New Issue
Block a user