commit 5742c0c476c0327c5a81048d993b123fd5b4f24f from: Anton Kasimov date: Mon May 4 22:24:45 2026 UTC Поддержка массивов в файлах .jsonld commit - 8ca2b72f354861b9e3a33c2915213f56dbac4218 commit + 5742c0c476c0327c5a81048d993b123fd5b4f24f blob - 43a4a1c69c9620c9da3a02014274569d4fc5fd65 blob + 0af4d39323f32e3db98f6d144017812cec51ec94 --- layouts/_partials/schema/json-ld.html +++ layouts/_partials/schema/json-ld.html @@ -17,7 +17,13 @@ {{- $results := slice }} {{- range uniq $schemas }} {{- with (partial "schema/load" (dict "page" $page "schema" .)) }} - {{- $results = $results | append (merge (dict "@context" "http://schema.org") .) }} + {{- if reflect.IsSlice . }} + {{- range . }} + {{- $results = $results | append (merge (dict "@context" "http://schema.org") .) }} + {{- end }} + {{- else }} + {{- $results = $results | append (merge (dict "@context" "http://schema.org") .) }} + {{- end }} {{- end }} {{- end }} {{- with $results }} blob - 92b34e5e6ea880248fa6441775ec09e20415cd9b blob + 9353f85e24a3e663272c083ce6b00a9a9a3e9bcb --- layouts/_partials/schema/load.html +++ layouts/_partials/schema/load.html @@ -15,27 +15,21 @@ {{ $result := dict }} {{ with $page }} - {{ $processedParams := dict }} {{ with .Resources.Get (printf "%s.jsonld" $schema) }} {{ with . | transform.Unmarshal (dict "format" "json") }} - {{ range $key, $value := . }} - {{ if and - (reflect.IsMap $value) - (index $value "@id") - (eq (len $value) 1) - (findRE `^/.+#.+$` (index $value "@id")) - }} - {{ $processedParams = merge $processedParams (dict $key (partial "schema/load" (index $value "@id"))) }} - {{ else }} - {{ $processedParams = merge $processedParams (dict $key $value) }} + {{ if reflect.IsSlice . }} + {{ $items := slice }} + {{ range $index, $item := . }} + {{ $loaded := partial "schema/load-object" (dict "page" $page "schema" $schema "item" $item) }} + {{ $items = $items | append (merge $loaded (dict "@id" (printf "%s-%d" (index $loaded "@id") (add $index 1)))) }} {{ end }} + {{ $result = $items }} + {{ else }} + {{ $result = partial "schema/load-object" (dict "page" $page "schema" $schema "item" .) }} {{ end }} {{ end }} + {{ else }} + {{ $result = partial "schema/load-object" (dict "page" $page "schema" $schema "item" dict) }} {{ end }} - {{ $result = merge - (partialCached (printf "schema/%s" $schema) . . $schema) - (dict "@type" $schema "@id" (printf "%s#%s" .Permalink $schema)) - $processedParams - }} {{ end }} {{ return $result }} blob - /dev/null blob + 4c233943666b3f5c4c4a473a8a5d306a3d84700a (mode 644) --- /dev/null +++ layouts/_partials/schema/load-object.html @@ -0,0 +1,19 @@ +{{ $processedParams := dict }} +{{ range $key, $value := .item }} + {{ if and + (reflect.IsMap $value) + (index $value "@id") + (eq (len $value) 1) + (findRE `^/.+#.+$` (index $value "@id")) + }} + {{ $processedParams = merge $processedParams (dict $key (partial "schema/load" (index $value "@id"))) }} + {{ else }} + {{ $processedParams = merge $processedParams (dict $key $value) }} + {{ end }} +{{ end }} + +{{ return merge + (partialCached (printf "schema/%s" .schema) .page .schema) + (dict "@type" .schema "@id" (printf "%s#%s" .page.Permalink .schema)) + $processedParams +}}