From fd980de7fe42339a0637d00d61f728df22ea125f Mon Sep 17 00:00:00 2001
From: David Karlsson <35727626+dvdksn@users.noreply.github.com>
Date: Thu, 19 Oct 2023 17:50:34 +0200
Subject: [PATCH] hugo: define front matter metadata through data
Signed-off-by: David Karlsson <35727626+dvdksn@users.noreply.github.com>
---
data/frontmatter.yaml | 10 ++++++++++
layouts/partials/meta.html | 4 ++--
layouts/partials/utils/description.html | 14 ++++++++++++++
layouts/partials/utils/keywords.html | 14 ++++++++++++++
layouts/partials/utils/title.html | 9 +++++++--
5 files changed, 47 insertions(+), 4 deletions(-)
create mode 100644 data/frontmatter.yaml
create mode 100644 layouts/partials/utils/description.html
create mode 100644 layouts/partials/utils/keywords.html
diff --git a/data/frontmatter.yaml b/data/frontmatter.yaml
new file mode 100644
index 0000000000..1f58f37681
--- /dev/null
+++ b/data/frontmatter.yaml
@@ -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.
diff --git a/layouts/partials/meta.html b/layouts/partials/meta.html
index 839ad14e30..993f6e54eb 100644
--- a/layouts/partials/meta.html
+++ b/layouts/partials/meta.html
@@ -1,5 +1,5 @@
{{ $title := partial "utils/title.html" . }}
-{{ $description := .Description | default .Summary }}
+{{ $description := partial "utils/description.html" . }}
{{ if .IsHome }}
{{ site.Title }}
{{ else }}
@@ -13,7 +13,7 @@
diff --git a/layouts/partials/utils/description.html b/layouts/partials/utils/description.html
new file mode 100644
index 0000000000..c0e6aa086d
--- /dev/null
+++ b/layouts/partials/utils/description.html
@@ -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 }}
diff --git a/layouts/partials/utils/keywords.html b/layouts/partials/utils/keywords.html
new file mode 100644
index 0000000000..754b0537b4
--- /dev/null
+++ b/layouts/partials/utils/keywords.html
@@ -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 }}
diff --git a/layouts/partials/utils/title.html b/layouts/partials/utils/title.html
index 054dba2023..101b8baf1f 100644
--- a/layouts/partials/utils/title.html
+++ b/layouts/partials/utils/title.html
@@ -3,8 +3,13 @@
{{ $title = .LinkTitle }}
{{ else }}
{{ $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 }}
{{ end }}
{{ end }}