Skip to content

Commit 32aeeb7

Browse files
authored
Merge pull request #2193 from JoeStech/json-ld
Add auto-builder of json-ld content into a Hugo partial template
2 parents e0757e9 + 7694067 commit 32aeeb7

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

themes/arm-design-system-hugo-theme/layouts/partials/head/head.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
<link rel="canonical" href="https://learn.arm.com{{ .Permalink }}" />
2727
<title>{{ $title }}</title>
2828

29+
{{ partial "head/jsonld.html" . }}
30+
2931
<!-- Include the Arm standard Lato font for machines that don't have by default (Mac) -->
3032
<!-- Can be done automatically now in cross-page.css locally to speed up process -->
3133
<link rel="preconnect" href="https://fonts.gstatic.com" />
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
{{/* layouts/partials/head/jsonld.html */}}
2+
{{/* ---------------------------------------------------------------
3+
Render JSON‑LD only for Learning‑Path _index.md main pages
4+
---------------------------------------------------------------- */}}
5+
{{- if and .IsSection (eq .Params.learning_path_main_page "yes") -}}
6+
{{/* -------- Helper : Build ISO‑8601 duration (PT30M, PT2H, …) */}}
7+
{{- $duration := "" -}}
8+
{{- with .Params.minutes_to_complete -}}
9+
{{- $duration = printf "PT%dM" (int .) -}}
10+
{{- end -}}
11+
{{/* -------- Learning objectives & prerequisites */}}
12+
{{- $objectives := slice -}}
13+
{{- with .Params.learning_objectives -}}
14+
{{- range . }}{{ $objectives = $objectives | append ( . | plainify ) }}{{ end -}}
15+
{{- end -}}
16+
{{- $prereqs := slice -}}
17+
{{- with .Params.prerequisites -}}
18+
{{- range . }}{{ $prereqs = $prereqs | append ( . | plainify ) }}{{ end -}}
19+
{{- end -}}
20+
{{/* -------- Collect tag‑style params into one keywords list */}}
21+
{{- $keywords := slice -}}
22+
{{- $tagParams := slice
23+
"skilllevels"
24+
"cloud_service_providers"
25+
"armips"
26+
"subjects"
27+
"operatingsystems"
28+
"tools_software_languages"
29+
-}}
30+
{{- range $tagParams -}}
31+
{{- $v := index $.Params . -}}
32+
{{- with $v -}}
33+
{{- if reflect.IsSlice $v -}}
34+
{{- range $v }}{{ $keywords = $keywords | append ( . | plainify ) }}{{ end -}}
35+
{{- else -}}
36+
{{- $keywords = $keywords | append ( $v | plainify ) -}}
37+
{{- end -}}
38+
{{- end -}}
39+
{{- end -}}
40+
{{/* -------- Assemble JSON‑LD dict */}}
41+
{{- $j := dict
42+
"@context" "https://schema.org"
43+
"@type" "Course"
44+
"name" .Title
45+
-}}
46+
{{- with .Params.who_is_this_for }}{{ $j = merge $j (dict "description" ( . | plainify )) }}{{ end -}}
47+
{{- if $duration }}{{ $j = merge $j (dict "timeRequired" $duration) }}{{ end -}}
48+
{{- with .Params.skilllevels }}{{ $j = merge $j (dict "educationalLevel" .) }}{{ end -}}
49+
{{- with $objectives }}{{ if gt (len .) 0 }}{{ $j = merge $j (dict "teaches" .) }}{{ end }}{{ end -}}
50+
{{- with $prereqs }}{{ if gt (len .) 0 }}{{ $j = merge $j (dict "competencyRequired" .) }}{{ end }}{{ end -}}
51+
{{- with .Params.author }}{{ $j = merge $j (dict "author" (dict "@type" "Person" "name" .)) }}{{ end -}}
52+
{{- if $keywords }}{{ $j = merge $j (dict "keywords" (delimit (uniq $keywords) ", ")) }}{{ end -}}
53+
{{- with .Site.Title }}{{ $j = merge $j (dict "provider" (dict "@type" "Organization" "name" .)) }}{{ end -}}
54+
{{/* -------- Emit into <head> */}}
55+
<script type="application/ld+json">
56+
{{- /* prettify the JSON (2‑space indent) and mark it as safe JS */ -}}
57+
{{- $j | jsonify (dict "indent" " ") | safeJS -}}
58+
</script>
59+
{{- end -}}

0 commit comments

Comments
 (0)