hugo: return keywords as sliceArray

Signed-off-by: David Karlsson <35727626+dvdksn@users.noreply.github.com>
This commit is contained in:
David Karlsson 2024-05-13 15:23:28 +02:00
parent bbb894f3e4
commit 5599686cb9
3 changed files with 12 additions and 4 deletions

View File

@ -15,7 +15,15 @@ async function initializeIndex() {
keys: [
{ name: "title", weight: 2 },
{ name: "description", weight: 1 },
{ name: "keywords", weight: 1 },
{
name: "keywords",
weight: 1,
getFn: (page) => {
return Array.isArray(page.keywords)
? page.keywords.join(" ")
: page.keywords;
},
},
{ name: "tags", weight: 1 },
],
minMatchCharLength: 1,

View File

@ -13,7 +13,7 @@
<meta name="description" content="{{ $description }}" />
<meta
name="keywords"
content="{{- partial "utils/keywords.html" . -}}"
content="{{- delimit (partialCached "utils/keywords.html" . .) ", " -}}"
/>
<link rel="canonical" href="{{ .Permalink }}" />

View File

@ -1,11 +1,11 @@
{{ $keywords := "" }}
{{ if .Keywords }}
{{ $keywords = delimit .Keywords " " }}
{{ $keywords = collections.Apply .Keywords "strings.Trim" "." ", " }}
{{ else }}
{{ with .File }}
{{ with (index (site.Data.frontmatter) .Path) }}
{{ with .keywords }}
{{ $keywords = strings.Replace (strings.Trim . "\n") "\n" " " }}
{{ $keywords = collections.Apply (strings.Split (strings.Replace . "\n" " ") ",") "strings.Trim" "." " " }}
{{ end }}
{{ end }}
{{ end }}