theme: Implement related content tooling

This commit is contained in:
Joe Mooring 2025-03-06 02:55:29 -08:00 committed by GitHub
parent fd628be6ed
commit a943a4bb83
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
14 changed files with 56 additions and 12 deletions

View File

@ -2,7 +2,7 @@
title: math.Acos
description: Returns the arccosine, in radians, of the given number.
categories: []
keywords: []
keywords: [trigonometry]
params:
functions_and_methods:
aliases: []

View File

@ -2,7 +2,7 @@
title: math.Asin
description: Returns the arcsine, in radians, of the given number.
categories: []
keywords: []
keywords: [trigonometry]
params:
functions_and_methods:
aliases: []

View File

@ -2,7 +2,7 @@
title: math.Atan
description: Returns the arctangent, in radians, of the given number.
categories: []
keywords: []
keywords: [trigonometry]
params:
functions_and_methods:
aliases: []

View File

@ -2,7 +2,7 @@
title: math.Atan2
description: Returns the arctangent, in radians, of the given number pair, determining the correct quadrant from their signs.
categories: []
keywords: []
keywords: [trigonometry]
params:
functions_and_methods:
aliases: []

View File

@ -2,7 +2,7 @@
title: math.Cos
description: Returns the cosine of the given radian number.
categories: []
keywords: []
keywords: [trigonometry]
params:
functions_and_methods:
aliases: []

View File

@ -2,7 +2,7 @@
title: math.Pi
description: Returns the mathematical constant pi.
categories: []
keywords: []
keywords: [trigonometry]
params:
functions_and_methods:
aliases: []

View File

@ -2,7 +2,7 @@
title: math.Sin
description: Returns the sine of the given radian number.
categories: []
keywords: []
keywords: [trigonometry]
params:
functions_and_methods:
aliases: []

View File

@ -2,7 +2,7 @@
title: math.Tan
description: Returns the tangent of the given radian number.
categories: []
keywords: []
keywords: [trigonometry]
params:
functions_and_methods:
aliases: []

View File

@ -2,7 +2,7 @@
title: math.ToDegrees
description: ToDegrees converts radians into degrees.
categories: []
keywords: []
keywords: [trigonometry]
params:
functions_and_methods:
aliases: []

View File

@ -2,7 +2,7 @@
title: math.ToRadians
description: ToRadians converts degrees into radians.
categories: []
keywords: []
keywords: [trigonometry]
params:
functions_and_methods:
aliases: []

12
data/keywords.yaml Normal file
View File

@ -0,0 +1,12 @@
# We use the front matter keywords field to determine related content. To
# ensure consistency, during site build we validate each keyword against the
# entries in data/keywords.yaml.
# As of March 5, 2025, this feature is experimental, pending usability
# assessment. We anticipate that the number of additions to data/keywords.yaml
# will decrease over time, though the initial implementation will require some
# effort.
- menu
- resource
- trigonometry

View File

@ -36,7 +36,7 @@ disableAliases = true
path = '{/news/**}'
[frontmatter]
date = ['date'] # do not add publishdate; it will affect page sorting
date = ['date'] # do not add publishdate; it will affect page sorting
expiryDate = ['expirydate']
lastmod = [':git', 'lastmod', 'publishdate', 'date']
publishDate = ['publishdate', 'date']
@ -110,6 +110,14 @@ disableAliases = true
[params.render_hooks.link]
errorLevel = 'warning' # ignore (default), warning, or error (fails the build)
[related]
includeNewer = true
threshold = 80
toLower = true
[[related.indices]]
name = 'keywords'
weight = 1
[security]
[security.funcs]
getenv = ['^HUGO_', '^REPOSITORY_URL$', '^BRANCH$']

View File

@ -0,0 +1,22 @@
{{/* prettier-ignore-start */ -}}
{{- /*
We use the front matter keywords field to determine related content. To ensure
consistency, during site build we validate each keyword against the entries in
data/keywords.yaml.
As of March 5, 2025, this feature is experimental, pending usability
assessment. We anticipate that the number of additions to data/keywords.yaml
will decrease over time, though the initial implementation will require some
effort.
*/}}
{{/* prettier-ignore-end */ -}}
{{- $t := debug.Timer "validateKeywords" }}
{{- $allowedKeywords := collections.Apply site.Data.keywords "strings.ToLower" "." }}
{{- range $p := site.Pages }}
{{- range .Params.keywords }}
{{- if not (in $allowedKeywords (lower .)) }}
{{- warnf "The word or phrase %q is not in the keywords data file. See %s." . $p.Page.String }}
{{- end }}
{{- end }}
{{- end }}
{{- $t.Stop }}

View File

@ -1 +1,3 @@
{{/* Empty for now */}}
{{- if .IsHome }}
{{- partial "helpers/validation/validate-keywords.html" }}
{{- end }}