|
1 | 1 | {{- /* Render hook for decision tree code blocks */ -}} |
2 | | -{{- /* Preserve YAML source for visual display and JavaScript parsing */ -}} |
3 | | -<pre class="decision-tree-source">{{ .Inner | htmlEscape | safeHTML }}</pre> |
| 2 | +{{- /* Check if content is empty (used to trigger JS loading without rendering) */ -}} |
| 3 | +{{- $trimmedContent := strings.TrimSpace .Inner -}} |
| 4 | +{{- if eq $trimmedContent "" -}} |
| 5 | + {{- /* Empty code block - just set the flag to load the JS, don't render anything */ -}} |
| 6 | + {{ .Page.Store.Set "hasDecisionTree" true }} |
| 7 | +{{- else -}} |
| 8 | + {{- /* Preserve YAML source for visual display and JavaScript parsing */ -}} |
| 9 | + <pre class="decision-tree-source">{{ .Inner | htmlEscape | safeHTML }}</pre> |
4 | 10 |
|
5 | | -{{- /* Extract id and scope from YAML for metadata (only top-level fields) */ -}} |
6 | | -{{- $lines := split .Inner "\n" -}} |
7 | | -{{- $id := "" -}} |
8 | | -{{- $scope := "" -}} |
9 | | -{{- range $lines -}} |
10 | | - {{- /* Only process lines that don't start with whitespace (top-level fields) */ -}} |
11 | | - {{- if and (gt (len .) 0) (ne (index . 0) 32) (ne (index . 0) 9) -}} |
12 | | - {{- $trimmed := strings.TrimSpace . -}} |
13 | | - {{- if strings.HasPrefix $trimmed "id:" -}} |
14 | | - {{- $afterPrefix := strings.Replace $trimmed "id:" "" 1 -}} |
15 | | - {{- $id = strings.TrimSpace $afterPrefix -}} |
16 | | - {{- end -}} |
17 | | - {{- if strings.HasPrefix $trimmed "scope:" -}} |
18 | | - {{- $afterPrefix := strings.Replace $trimmed "scope:" "" 1 -}} |
19 | | - {{- $scope = strings.TrimSpace $afterPrefix -}} |
| 11 | + {{- /* Extract id and scope from YAML for metadata (only top-level fields) */ -}} |
| 12 | + {{- $lines := split .Inner "\n" -}} |
| 13 | + {{- $id := "" -}} |
| 14 | + {{- $scope := "" -}} |
| 15 | + {{- range $lines -}} |
| 16 | + {{- /* Only process lines that don't start with whitespace (top-level fields) */ -}} |
| 17 | + {{- if and (gt (len .) 0) (ne (index . 0) 32) (ne (index . 0) 9) -}} |
| 18 | + {{- $trimmed := strings.TrimSpace . -}} |
| 19 | + {{- if strings.HasPrefix $trimmed "id:" -}} |
| 20 | + {{- $afterPrefix := strings.Replace $trimmed "id:" "" 1 -}} |
| 21 | + {{- $id = strings.TrimSpace $afterPrefix -}} |
| 22 | + {{- end -}} |
| 23 | + {{- if strings.HasPrefix $trimmed "scope:" -}} |
| 24 | + {{- $afterPrefix := strings.Replace $trimmed "scope:" "" 1 -}} |
| 25 | + {{- $scope = strings.TrimSpace $afterPrefix -}} |
| 26 | + {{- end -}} |
20 | 27 | {{- end -}} |
21 | 28 | {{- end -}} |
22 | | -{{- end -}} |
23 | 29 |
|
24 | | -{{- /* Embed metadata as custom JSON for AI agents */ -}} |
25 | | -{{- $metadata := dict "type" "decision-tree" "id" $id "scope" $scope -}} |
| 30 | + {{- /* Embed metadata as custom JSON for AI agents */ -}} |
| 31 | + {{- $metadata := dict "type" "decision-tree" "id" $id "scope" $scope -}} |
26 | 32 |
|
27 | | -{{ $jsonMetadata := $metadata | jsonify (dict "indent" " ") }} |
28 | | -{{ printf "<script type=\"application/json\" data-redis-metadata=\"decision-tree\">\n%s\n</script>" $jsonMetadata | safeHTML }} |
| 33 | + {{ $jsonMetadata := $metadata | jsonify (dict "indent" " ") }} |
| 34 | + {{ printf "<script type=\"application/json\" data-redis-metadata=\"decision-tree\">\n%s\n</script>" $jsonMetadata | safeHTML }} |
29 | 35 |
|
30 | | -{{ .Page.Store.Set "hasDecisionTree" true }} |
| 36 | + {{ .Page.Store.Set "hasDecisionTree" true }} |
| 37 | +{{- end -}} |
31 | 38 |
|
0 commit comments