Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions layouts/partials/schema/collectors/comparison-table-entity.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
{{/* Returns ItemList entity for comparison tables found on /comparisons/ pages */}}

{{ $entity := dict }}

{{ if and (strings.Contains .RelPermalink "/comparisons/") (strings.Contains .RawContent "| Feature |") }}

{{/* Extract from "| Feature |" onward */}}
{{ $afterHeader := replaceRE `(?s)^.*?\| Feature \|` "| Feature |" .RawContent }}

{{/* Extract all table lines */}}
{{ $allTableLines := findRE `(?m)^\|.+\|` $afterHeader }}

{{ if ge (len $allTableLines) 3 }}

{{/* Extract column names from the table header row (always in correct column order) */}}
{{ $headerCells := split (index $allTableLines 0) "|" }}
{{ $productName := index $headerCells 2 | strings.TrimSpace }}
{{ $competitorName := index $headerCells 3 | strings.TrimSpace }}

{{ if $competitorName }}

{{ $dataLines := $allTableLines | after 2 }}

{{/* Use Scratch to accumulate rows inside range */}}
{{ $.Scratch.Set "compRows" slice }}

{{ range $dataLines }}
{{ $line := . | strings.TrimSpace }}
{{ if not (findRE `^\|[\s\-:|]+\|$` $line) }}
{{ $cells := split $line "|" }}
{{ if ge (len $cells) 4 }}
{{ $feature := index $cells 1 | strings.TrimSpace }}
{{ $feature = replaceRE `\[([^\]]+)\]\([^)]+\)` "$1" $feature }}
{{ $val1 := index $cells 2 | strings.TrimSpace }}
{{ $val2 := index $cells 3 | strings.TrimSpace }}
{{ $val1 = replaceRE `<[^>]+>` " " $val1 }}
{{ $val2 = replaceRE `<[^>]+>` " " $val2 }}
{{ $val1 = replaceRE `\[([^\]]+)\]\([^)]+\)` "$1" $val1 }}
{{ $val2 = replaceRE `\[([^\]]+)\]\([^)]+\)` "$1" $val2 }}
{{ $existing := $.Scratch.Get "compRows" }}
{{ $.Scratch.Set "compRows" ($existing | append (dict "feature" $feature "product" $val1 "competitor" $val2)) }}
{{ end }}
{{ end }}
{{ end }}

{{ $rows := $.Scratch.Get "compRows" }}
{{ $.Scratch.Delete "compRows" }}

{{ if len $rows }}

{{/* Build ItemList with ListItem entries */}}
{{ $.Scratch.Set "compItems" slice }}
{{ range $i, $row := $rows }}
{{ $position := add $i 1 }}
{{ $existing := $.Scratch.Get "compItems" }}
{{ $.Scratch.Set "compItems" ($existing | append (dict
"@type" "ListItem"
"position" $position
"name" $row.feature
"description" (printf "%s: %s | %s: %s" $productName $row.product $competitorName $row.competitor)
)) }}
{{ end }}

{{ $items := $.Scratch.Get "compItems" }}
{{ $.Scratch.Delete "compItems" }}

{{ $entity = dict
"@type" "ItemList"
"@id" "#comparison-table"
"name" (printf "%s vs. %s Feature Comparison" $productName $competitorName)
"description" (printf "Side-by-side feature comparison of %s and %s for infrastructure as code" $productName $competitorName)
"numberOfItems" (len $items)
"itemListElement" $items
}}

{{ end }}
{{ end }}
{{ end }}
{{ end }}

{{ return $entity }}
14 changes: 14 additions & 0 deletions layouts/partials/schema/graph-builder.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@
{{ $webpage = merge $webpage (dict "mainEntity" (dict "@id" "#main-content")) }}
{{ end }}

{{/* Collect comparison table schema before finalizing WebPage so hasPart can be wired */}}
{{ $comparisonTable := dict }}
{{ if not .IsHome }}
{{ $comparisonTable = partial "schema/collectors/comparison-table-entity.html" . }}
{{ if and $comparisonTable (ne $comparisonTable (dict)) }}
{{ $webpage = merge $webpage (dict "hasPart" (dict "@id" "#comparison-table")) }}
{{ end }}
{{ end }}

{{/* Add WebPage to graph */}}
{{ $graph = $graph | append $webpage }}

Expand Down Expand Up @@ -171,6 +180,11 @@
{{ $graph = $graph | append $software }}
{{ end }}

{{/* Add comparison table to graph (collected earlier to wire hasPart into WebPage) */}}
{{ if and $comparisonTable (ne $comparisonTable (dict)) }}
{{ $graph = $graph | append $comparisonTable }}
{{ end }}

{{/* Add video schema if page contains YouTube videos */}}
{{ if not .IsHome }}
{{ $videoEntity := partial "schema/collectors/video-entity.html" . }}
Expand Down