hugo: define front matter metadata through data

Signed-off-by: David Karlsson <35727626+dvdksn@users.noreply.github.com>
This commit is contained in:
David Karlsson 2023-10-19 17:50:34 +02:00
parent 1fc6d134a7
commit fd980de7fe
5 changed files with 47 additions and 4 deletions

10
data/frontmatter.yaml Normal file
View File

@ -0,0 +1,10 @@
# this file lets you add descriptions and keywords
# to files without modifying the file.
#
# Useful for upstream pages where we don't want to
# or can't add front matter to the source!
#
# To add descriptions and keywords for a page,
# add a key with the path of the page file,
# relative to the content directory. For upstream
# page files, that's the target of the file mount.

View File

@ -1,5 +1,5 @@
{{ $title := partial "utils/title.html" . }} {{ $title := partial "utils/title.html" . }}
{{ $description := .Description | default .Summary }} {{ $description := partial "utils/description.html" . }}
{{ if .IsHome }} {{ if .IsHome }}
<title>{{ site.Title }}</title> <title>{{ site.Title }}</title>
{{ else }} {{ else }}
@ -13,7 +13,7 @@
<meta name="description" content="{{ $description }}" /> <meta name="description" content="{{ $description }}" />
<meta <meta
name="keywords" name="keywords"
content="{{ .Keywords | default "docker, docker open source, docker platform, distributed applications, microservices, containers, docker containers, docker software, docker virtualization" }}" content="{{- partial "utils/keywords.html" . -}}"
/> />
<link rel="canonical" href="{{ .Permalink }}" /> <link rel="canonical" href="{{ .Permalink }}" />

View File

@ -0,0 +1,14 @@
{{ $desc := "" }}
{{ if .Description }}
{{ $desc = .Description }}
{{ else }}
{{ $desc = .Summary }}
{{ with .File }}
{{ with (index (site.Data.frontmatter) .Path) }}
{{ with .description }}
{{ $desc = strings.Replace . "\n" " " | strings.TrimRight " " }}
{{ end }}
{{ end }}
{{ end }}
{{ end }}
{{ return $desc }}

View File

@ -0,0 +1,14 @@
{{ $keywords := "" }}
{{ if .Keywords }}
{{ $keywords = .Keywords }}
{{ else }}
{{ $keywords = "docker, docker open source, docker platform, distributed applications, microservices, containers, docker containers, docker software, docker virtualization" }}
{{ with .File }}
{{ with (index (site.Data.frontmatter) .Path) }}
{{ with .keywords }}
{{ $keywords = strings.Replace . "\n" " " | strings.TrimRight " " }}
{{ end }}
{{ end }}
{{ end }}
{{ end }}
{{ return $keywords }}

View File

@ -3,8 +3,13 @@
{{ $title = .LinkTitle }} {{ $title = .LinkTitle }}
{{ else }} {{ else }}
{{ $title = index (findRE `# .*` .RawContent) 0 | strings.TrimLeft "# " }} {{ $title = index (findRE `# .*` .RawContent) 0 | strings.TrimLeft "# " }}
{{ if not $title }} {{ with .File }}
{{ with .File }} {{ with (index (site.Data.frontmatter) .Path) }}
{{ with .title }}
{{ $title = . }}
{{ end }}
{{ end }}
{{ if not $title }}
{{ $title = strings.ReplaceRE "[-_]" " " .TranslationBaseName }} {{ $title = strings.ReplaceRE "[-_]" " " .TranslationBaseName }}
{{ end }} {{ end }}
{{ end }} {{ end }}