perf(schema): loop fusion

This commit is contained in:
ZhenShuo Leo
2025-12-03 11:15:03 +08:00
parent afa810841c
commit 8b362f58d3
+13 -10
View File
@@ -49,22 +49,25 @@
"@context": "https://schema.org", "@context": "https://schema.org",
"@type": "BreadcrumbList", "@type": "BreadcrumbList",
"itemListElement": [ "itemListElement": [
{{- $breadcrumbs := slice -}} {{- $position := 0 -}}
{{- range .Ancestors -}} {{- range .Ancestors -}}
{{- if not .IsHome -}} {{- if not .IsHome -}}
{{- $breadcrumbs = $breadcrumbs | append . -}} {{- $position = add $position 1 -}}
{{- end -}}
{{- end -}}
{{- $breadcrumbs = $breadcrumbs | append . -}}
{{- range $index, $element := $breadcrumbs -}}
{ {
"@type": "ListItem", "@type": "ListItem",
"position": {{ add $index 1 }}, "position": {{ $position }},
"name": "{{ .Title }}", "name": "{{ .Title }}",
"item": {{ .Permalink }}, "item": {{ .Permalink }}
}{{ if ne (add $index 1) (len $breadcrumbs) }},{{ end }} },
{{- end -}} {{- end -}}
{{- end -}}
{{- $position = add $position 1 -}}
{
"@type": "ListItem",
"position": {{ $position }},
"name": "{{ .Title }}",
"item": {{ .Permalink }}
}
] ]
}{{ end }}] }{{ end }}]
</script> </script>