@bookshop/hugo-engine 3.14.0 → 3.15.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/full-hugo-renderer/hugo_renderer.wasm.gz +0 -0
- package/package.json +7 -8
- package/.npmrc +0 -1
- package/.nyc_output/132e7b4a-afdf-418e-b365-774d529faa43.json +0 -1
- package/.nyc_output/2c506fb0-f1f8-47d7-af8c-ccdd651ee51d.json +0 -1
- package/.nyc_output/5e37d726-0046-4e64-9faa-5f344cb00c97.json +0 -1
- package/.nyc_output/95826c24-bb14-4904-85da-cb2e4024b1a9.json +0 -1
- package/.nyc_output/b070f025-72c1-460d-b0a9-3b685ed91a62.json +0 -1
- package/.nyc_output/processinfo/132e7b4a-afdf-418e-b365-774d529faa43.json +0 -1
- package/.nyc_output/processinfo/2c506fb0-f1f8-47d7-af8c-ccdd651ee51d.json +0 -1
- package/.nyc_output/processinfo/5e37d726-0046-4e64-9faa-5f344cb00c97.json +0 -1
- package/.nyc_output/processinfo/95826c24-bb14-4904-85da-cb2e4024b1a9.json +0 -1
- package/.nyc_output/processinfo/b070f025-72c1-460d-b0a9-3b685ed91a62.json +0 -1
- package/.nyc_output/processinfo/index.json +0 -1
- package/full-hugo-renderer/build.sh +0 -34
- package/full-hugo-renderer/go.mod +0 -109
- package/full-hugo-renderer/go.sum +0 -780
- package/full-hugo-renderer/hugo_renderer.wasm +0 -0
- package/full-hugo-renderer/main.go +0 -219
- package/full-hugo-renderer/wasm_exec.js +0 -568
- package/lib/engine.test.js +0 -82
- package/lib/engine__test__.js +0 -461
- package/lib/hugoIdentifierParser.test.js +0 -110
- package/lib/translateTextTemplate.test.js +0 -229
- package/main.test.js +0 -5
- package/prep__test__.js +0 -5
|
@@ -1,229 +0,0 @@
|
|
|
1
|
-
import test from 'ava';
|
|
2
|
-
import translateTextTemplate from './translateTextTemplate.js';
|
|
3
|
-
|
|
4
|
-
test("add live markup to bookshop tags", t => {
|
|
5
|
-
const input = `{{ partial "bookshop" (slice "content" (dict "content_html" .Params.note_html "type" "note")) }}`;
|
|
6
|
-
const expected = [
|
|
7
|
-
`{{ \`<!--bookshop-live name(content) params(.: ((dict "content_html" .Params.note_html "type" "note")))-->\` | safeHTML }}`,
|
|
8
|
-
`{{ partial "bookshop" (slice "content" (dict "content_html" .Params.note_html "type" "note")) }}`,
|
|
9
|
-
`{{ \`<!--bookshop-live end-->\` | safeHTML }}`
|
|
10
|
-
].join('');
|
|
11
|
-
t.is(translateTextTemplate(input, {}), expected);
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
test("add live markup to bookshop tags referencing variables", t => {
|
|
15
|
-
const input = `{{ partial "bookshop" (slice .item._bookshop_name .item.something )}}`;
|
|
16
|
-
const expected = [
|
|
17
|
-
`{{ (printf \`<!--bookshop-live name(%s) params(.: (.item.something))-->\` (.item._bookshop_name)) | safeHTML }}`,
|
|
18
|
-
`{{ partial "bookshop" (slice .item._bookshop_name .item.something )}}`,
|
|
19
|
-
`{{ \`<!--bookshop-live end-->\` | safeHTML }}`
|
|
20
|
-
].join('');
|
|
21
|
-
t.is(translateTextTemplate(input, {}), expected);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
test("add live markup to scoped bookshop tags", t => {
|
|
25
|
-
const input = `{{ partial "bookshop" . }}`;
|
|
26
|
-
const expected = [
|
|
27
|
-
`{{ if reflect.IsSlice . }}{{ (printf \`<!--bookshop-live name(%s) params(.: .)-->\` (index . 0)) | safeHTML }}`,
|
|
28
|
-
`{{- else if reflect.IsMap . -}}{{ (printf \`<!--bookshop-live name(%s) params(.: .)-->\` ._bookshop_name) | safeHTML }}{{ end }}`,
|
|
29
|
-
`{{ partial "bookshop" . }}`,
|
|
30
|
-
`{{ \`<!--bookshop-live end-->\` | safeHTML }}`
|
|
31
|
-
].join('');
|
|
32
|
-
t.is(translateTextTemplate(input, {}), expected);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
test("don't add live markup to bookshop_partial tags", t => {
|
|
36
|
-
const input = `{{ partial "bookshop_partial" (slice "helper" (dict "text" "input")) }}`;
|
|
37
|
-
const expected = `{{ partial "bookshop_partial" (slice "helper" (dict "text" "input")) }}`;
|
|
38
|
-
t.is(translateTextTemplate(input, {}), expected);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
test("don't add live markup if no bookshop found", t => {
|
|
42
|
-
let input = `{{ $a := .b }}`;
|
|
43
|
-
t.is(translateTextTemplate(input, {}), input);
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
test("don't add live markup to commented out regions", t => {
|
|
47
|
-
const input = [
|
|
48
|
-
`{{/* comment start <div>`,
|
|
49
|
-
` . {{ partial "bookshop" (slice "content" (dict "content_html" .Params.note_html "type" "note")) }}`,
|
|
50
|
-
` <h1> Hello World </h1>`,
|
|
51
|
-
` . {{ partial "bookshop" . }}`,
|
|
52
|
-
`</div> comment end */}}`
|
|
53
|
-
].join('\n');
|
|
54
|
-
t.is(translateTextTemplate(input, {}), input);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
test("add live markup to assigns", t => {
|
|
58
|
-
let input = `{{ $a := .b }}bookshop`;
|
|
59
|
-
let expected = `{{ $a := .b }}{{ \`<!--bookshop-live context($a: (.b))-->\` | safeHTML }}bookshop`;
|
|
60
|
-
t.is(translateTextTemplate(input, {}), expected);
|
|
61
|
-
|
|
62
|
-
input = `{{ $a := .b | chomp }}bookshop`;
|
|
63
|
-
expected = `{{ $a := .b | chomp }}{{ \`<!--bookshop-live context($a: (.b | chomp))-->\` | safeHTML }}bookshop`;
|
|
64
|
-
t.is(translateTextTemplate(input, {}), expected);
|
|
65
|
-
|
|
66
|
-
input = `{{ $a = .b }}bookshop`;
|
|
67
|
-
expected = `{{ $a = .b }}{{ \`<!--bookshop-live reassign($a: (.b))-->\` | safeHTML }}bookshop`;
|
|
68
|
-
t.is(translateTextTemplate(input, {}), expected);
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
test("add live markup to withs", t => {
|
|
72
|
-
const input = `{{ with .b }}<p>{{.}}</p>{{ end }}bookshop`;
|
|
73
|
-
const expected = [`{{ with .b }}`,
|
|
74
|
-
`{{ \`<!--bookshop-live stack-->\` | safeHTML }}`,
|
|
75
|
-
`{{ \`<!--bookshop-live context(.: (.b))-->\` | safeHTML }}`,
|
|
76
|
-
`<p>{{.}}</p>`,
|
|
77
|
-
`{{ \`<!--bookshop-live unstack-->\` | safeHTML }}`,
|
|
78
|
-
`{{ end }}bookshop`
|
|
79
|
-
].join('');
|
|
80
|
-
t.is(translateTextTemplate(input, {}), expected);
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
test("add live markup to loops", t => {
|
|
84
|
-
const input = `{{ range .items }}<p>{{ . }}</p>{{ end }}bookshop`;
|
|
85
|
-
const expected = [`{{ $bookshop__live__iterator__keys := (slice) }}`,
|
|
86
|
-
`{{ range $i, $e := (.items) }}{{ $bookshop__live__iterator__keys = $bookshop__live__iterator__keys | append $i }}{{ end }}`,
|
|
87
|
-
`{{ $bookshop__live__iterator := 0 }}`,
|
|
88
|
-
`{{ range .items }}`,
|
|
89
|
-
`{{ \`<!--bookshop-live stack-->\` | safeHTML }}`,
|
|
90
|
-
`{{ $bookshop__live__iterator__key := (index ($bookshop__live__iterator__keys) $bookshop__live__iterator) }}`,
|
|
91
|
-
`{{ (printf \`<!--bookshop-live context(.: (index (.items) %v))-->\` (jsonify $bookshop__live__iterator__key)) | safeHTML }}`,
|
|
92
|
-
`{{ $bookshop__live__iterator = (add $bookshop__live__iterator 1) }}`,
|
|
93
|
-
`<p>{{ . }}</p>`,
|
|
94
|
-
`{{ \`<!--bookshop-live unstack-->\` | safeHTML }}`,
|
|
95
|
-
`{{ end }}bookshop`
|
|
96
|
-
].join('');
|
|
97
|
-
t.is(translateTextTemplate(input, {}), expected);
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
test("add live markup to loops with iterators", t => {
|
|
101
|
-
const input = `{{range $loop_index, $element := .columns}}<p>{{$element}}</p>{{ end }}bookshop`;
|
|
102
|
-
const expected = [`{{range $loop_index, $element := .columns}}`,
|
|
103
|
-
`{{ \`<!--bookshop-live stack-->\` | safeHTML }}`,
|
|
104
|
-
`{{ (printf \`<!--bookshop-live context(.: (index (.columns) %v))-->\` (jsonify $loop_index)) | safeHTML }}`,
|
|
105
|
-
`<p>{{$element}}</p>`,
|
|
106
|
-
`{{ \`<!--bookshop-live unstack-->\` | safeHTML }}`,
|
|
107
|
-
`{{ end }}bookshop`
|
|
108
|
-
].join('');
|
|
109
|
-
t.is(translateTextTemplate(input, {}), expected);
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
test("escape backticks in values", t => {
|
|
113
|
-
let input = `{{ $a := "hi\`:)" }}bookshop`;
|
|
114
|
-
let expected = `{{ $a := "hi\`:)" }}{{ replace \`<!--bookshop-live context($a: ("hiBKSH_BACKTICK:)"))-->\` "BKSH_BACKTICK" "\`" | safeHTML }}bookshop`;
|
|
115
|
-
t.is(translateTextTemplate(input, {}), expected);
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
test("add live markup to complex end structures", t => {
|
|
119
|
-
const input = `
|
|
120
|
-
{{ range .items }}
|
|
121
|
-
|
|
122
|
-
{{with .text}}
|
|
123
|
-
<p>{{ . }}</p>
|
|
124
|
-
{{ end }}
|
|
125
|
-
|
|
126
|
-
{{ if .subtitle }}
|
|
127
|
-
<h2>{{ .subtitle }}</h2>
|
|
128
|
-
{{ else }}
|
|
129
|
-
{{ with .excerpt }}
|
|
130
|
-
<p>{{ . }}</p>
|
|
131
|
-
{{end}}
|
|
132
|
-
{{ end }}
|
|
133
|
-
|
|
134
|
-
{{ end }}bookshop`;
|
|
135
|
-
const expected = `
|
|
136
|
-
{{ $bookshop__live__iterator__keys := (slice) }}{{ range $i, $e := (.items) }}{{ $bookshop__live__iterator__keys = $bookshop__live__iterator__keys | append $i }}{{ end }}{{ $bookshop__live__iterator := 0 }}{{ range .items }}{{ \`<!--bookshop-live stack-->\` | safeHTML }}{{ $bookshop__live__iterator__key := (index ($bookshop__live__iterator__keys) $bookshop__live__iterator) }}{{ (printf \`<!--bookshop-live context(.: (index (.items) %v))-->\` (jsonify $bookshop__live__iterator__key)) | safeHTML }}{{ $bookshop__live__iterator = (add $bookshop__live__iterator 1) }}
|
|
137
|
-
|
|
138
|
-
{{with .text}}{{ \`<!--bookshop-live stack-->\` | safeHTML }}{{ \`<!--bookshop-live context(.: (.text))-->\` | safeHTML }}
|
|
139
|
-
<p>{{ . }}</p>
|
|
140
|
-
{{ \`<!--bookshop-live unstack-->\` | safeHTML }}{{ end }}
|
|
141
|
-
|
|
142
|
-
{{ if .subtitle }}
|
|
143
|
-
<h2>{{ .subtitle }}</h2>
|
|
144
|
-
{{ else }}
|
|
145
|
-
{{ with .excerpt }}{{ \`<!--bookshop-live stack-->\` | safeHTML }}{{ \`<!--bookshop-live context(.: (.excerpt))-->\` | safeHTML }}
|
|
146
|
-
<p>{{ . }}</p>
|
|
147
|
-
{{ \`<!--bookshop-live unstack-->\` | safeHTML }}{{end}}
|
|
148
|
-
{{ end }}
|
|
149
|
-
|
|
150
|
-
{{ \`<!--bookshop-live unstack-->\` | safeHTML }}{{ end }}bookshop`;
|
|
151
|
-
t.is(translateTextTemplate(input, {}), expected);
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
test("add live markup to complex components", t => {
|
|
155
|
-
const input = `
|
|
156
|
-
{{ $level := default 2 .level }}
|
|
157
|
-
{{ $level = string
|
|
158
|
-
$level }}
|
|
159
|
-
{{ $level_classes := dict
|
|
160
|
-
"1" "border-b py-8 text-4xl"
|
|
161
|
-
"2" "border-b py-6 text-3xl"
|
|
162
|
-
"3" "border-b py-4 text-2xl font-bold"
|
|
163
|
-
"4" "border-b text-xl font-bold"
|
|
164
|
-
}}
|
|
165
|
-
{{ $level_class := "lg" }}
|
|
166
|
-
{{ with index $level_classes $level }}
|
|
167
|
-
{{ $level_class = . }}
|
|
168
|
-
{{ end }}
|
|
169
|
-
{{ $open := printf \`<h%s class="%s">\` $level $level_class }}
|
|
170
|
-
{{ $close := printf \`</h%s>\` $level }}
|
|
171
|
-
{{ with .copy }}
|
|
172
|
-
{{ safeHTML $open }}
|
|
173
|
-
{{ markdownify . }} | bookshop
|
|
174
|
-
{{ safeHTML $close }}
|
|
175
|
-
{{ end }}`;
|
|
176
|
-
const expected = `
|
|
177
|
-
{{ $level := default 2 .level }}{{ \`<!--bookshop-live context($level: (default 2 .level))-->\` | safeHTML }}
|
|
178
|
-
{{ $level = string
|
|
179
|
-
$level }}{{ \`<!--bookshop-live reassign($level: (string $level))-->\` | safeHTML }}
|
|
180
|
-
{{ $level_classes := dict
|
|
181
|
-
"1" "border-b py-8 text-4xl"
|
|
182
|
-
"2" "border-b py-6 text-3xl"
|
|
183
|
-
"3" "border-b py-4 text-2xl font-bold"
|
|
184
|
-
"4" "border-b text-xl font-bold"
|
|
185
|
-
}}{{ \`<!--bookshop-live context($level_classes: (dict "1" "border-b py-8 text-4xl" "2" "border-b py-6 text-3xl" "3" "border-b py-4 text-2xl font-bold" "4" "border-b text-xl font-bold"))-->\` | safeHTML }}
|
|
186
|
-
{{ $level_class := "lg" }}{{ \`<!--bookshop-live context($level_class: ("lg"))-->\` | safeHTML }}
|
|
187
|
-
{{ with index $level_classes $level }}{{ \`<!--bookshop-live stack-->\` | safeHTML }}{{ \`<!--bookshop-live context(.: (index $level_classes $level))-->\` | safeHTML }}
|
|
188
|
-
{{ $level_class = . }}{{ \`<!--bookshop-live reassign($level_class: (.))-->\` | safeHTML }}
|
|
189
|
-
{{ \`<!--bookshop-live unstack-->\` | safeHTML }}{{ end }}
|
|
190
|
-
{{ $open := printf \`<h%s class="%s">\` $level $level_class }}{{ replace \`<!--bookshop-live context($open: (printf BKSH_BACKTICK<h%s class="%s">BKSH_BACKTICK $level $level_class))-->\` "BKSH_BACKTICK" "\`" | safeHTML }}
|
|
191
|
-
{{ $close := printf \`</h%s>\` $level }}{{ replace \`<!--bookshop-live context($close: (printf BKSH_BACKTICK</h%s>BKSH_BACKTICK $level))-->\` "BKSH_BACKTICK" "\`" | safeHTML }}
|
|
192
|
-
{{ with .copy }}{{ \`<!--bookshop-live stack-->\` | safeHTML }}{{ \`<!--bookshop-live context(.: (.copy))-->\` | safeHTML }}
|
|
193
|
-
{{ safeHTML $open }}
|
|
194
|
-
{{ markdownify . }} | bookshop
|
|
195
|
-
{{ safeHTML $close }}
|
|
196
|
-
{{ \`<!--bookshop-live unstack-->\` | safeHTML }}{{ end }}`;
|
|
197
|
-
t.is(translateTextTemplate(input, {}), expected);
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
// test("add live markup to another complex component", t => {
|
|
201
|
-
// const input = `
|
|
202
|
-
// {{ if site.Params.env_bookshop_live }}
|
|
203
|
-
|
|
204
|
-
// {{ partial "bookshop" (slice "layout_options" (slice (partial "bookshop" (slice "filtered_posts/component" .)) .)) }}
|
|
205
|
-
|
|
206
|
-
// {{ else }}
|
|
207
|
-
// {{ $content := partial "bookshop" (slice "filtered_posts/component" .) }}
|
|
208
|
-
// {{ $content = $content | strings.ReplaceRE \`<!--.*?-->\` "" | strings.ReplaceRE \`^\s+(.*?)\s+$\` "$1" | safeHTML }}
|
|
209
|
-
|
|
210
|
-
// {{ if $content }}
|
|
211
|
-
// {{ partial "bookshop" (slice "layout_options" (slice $content .)) }}
|
|
212
|
-
// {{ end }}
|
|
213
|
-
// {{ end }}`;
|
|
214
|
-
// const expected = `
|
|
215
|
-
// {{ if site.Params.env_bookshop_live }}
|
|
216
|
-
|
|
217
|
-
// {{ partial "bookshop" (slice "layout_options" (slice (partial "bookshop" (slice "filtered_posts/component" .)) .)) }}
|
|
218
|
-
|
|
219
|
-
// {{ else }}
|
|
220
|
-
// {{ $content := partial "bookshop" (slice "filtered_posts/component" .) }}
|
|
221
|
-
// {{ $content = $content | strings.ReplaceRE \`<!--.*?-->\` "" | strings.ReplaceRE \`^\s+(.*?)\s+$\` "$1" | safeHTML }}
|
|
222
|
-
|
|
223
|
-
// {{ if $content }}
|
|
224
|
-
// {{ partial "bookshop" (slice "layout_options" (slice $content .)) }}
|
|
225
|
-
// {{ end }}
|
|
226
|
-
// {{ end }}`;
|
|
227
|
-
// console.log(translateTextTemplate(input, {}))
|
|
228
|
-
// t.is(translateTextTemplate(input, {}), expected);
|
|
229
|
-
// });
|
package/main.test.js
DELETED
package/prep__test__.js
DELETED