From 8b362f58d30c1c308ab215d5e752e15fbb4736d8 Mon Sep 17 00:00:00 2001 From: ZhenShuo Leo <98386542+ZhenShuo2021@users.noreply.github.com> Date: Wed, 3 Dec 2025 11:15:03 +0800 Subject: [PATCH] perf(schema): loop fusion --- layouts/partials/schema.html | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/layouts/partials/schema.html b/layouts/partials/schema.html index 2f14cc69..6d278272 100644 --- a/layouts/partials/schema.html +++ b/layouts/partials/schema.html @@ -49,22 +49,25 @@ "@context": "https://schema.org", "@type": "BreadcrumbList", "itemListElement": [ - {{- $breadcrumbs := slice -}} + {{- $position := 0 -}} {{- range .Ancestors -}} {{- if not .IsHome -}} - {{- $breadcrumbs = $breadcrumbs | append . -}} + {{- $position = add $position 1 -}} + { + "@type": "ListItem", + "position": {{ $position }}, + "name": "{{ .Title }}", + "item": {{ .Permalink }} + }, {{- end -}} {{- end -}} - {{- $breadcrumbs = $breadcrumbs | append . -}} - - {{- range $index, $element := $breadcrumbs -}} - { - "@type": "ListItem", - "position": {{ add $index 1 }}, - "name": "{{ .Title }}", - "item": {{ .Permalink }}, - }{{ if ne (add $index 1) (len $breadcrumbs) }},{{ end }} - {{- end -}} + {{- $position = add $position 1 -}} + { + "@type": "ListItem", + "position": {{ $position }}, + "name": "{{ .Title }}", + "item": {{ .Permalink }} + } ] }{{ end }}]