@bookshop/hugo-engine 3.4.0-beta.1 → 3.4.0-beta.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/.nyc_output/{4266a04d-f79f-4e25-82b5-a5503aad4653.json → 0d71b778-7933-4ad7-b3a3-a0ab8fb25087.json} +0 -0
- package/.nyc_output/{5a2007e8-1bda-4eda-b271-6d7323d49bdd.json → 288189b4-5618-4616-9a86-8209c52bfa78.json} +0 -0
- package/.nyc_output/{6dd4f497-4c32-412e-906a-d5f84380dee6.json → 3a20cbf5-03a8-4e28-9134-bcbe4e3999da.json} +0 -0
- package/.nyc_output/{bc1d4fe0-2b67-4190-bcd2-9fd06daf74c0.json → 440df8ed-01d8-4b4a-86a4-141986b1c583.json} +0 -0
- package/.nyc_output/{bc6fd14e-b803-4750-ac28-dfe4b8d1c235.json → df2bb669-e900-4e87-9cf0-f9673bdda2d5.json} +0 -0
- package/.nyc_output/processinfo/{4266a04d-f79f-4e25-82b5-a5503aad4653.json → 0d71b778-7933-4ad7-b3a3-a0ab8fb25087.json} +1 -1
- package/.nyc_output/processinfo/288189b4-5618-4616-9a86-8209c52bfa78.json +1 -0
- package/.nyc_output/processinfo/{6dd4f497-4c32-412e-906a-d5f84380dee6.json → 3a20cbf5-03a8-4e28-9134-bcbe4e3999da.json} +1 -1
- package/.nyc_output/processinfo/{bc1d4fe0-2b67-4190-bcd2-9fd06daf74c0.json → 440df8ed-01d8-4b4a-86a4-141986b1c583.json} +1 -1
- package/.nyc_output/processinfo/{bc6fd14e-b803-4750-ac28-dfe4b8d1c235.json → df2bb669-e900-4e87-9cf0-f9673bdda2d5.json} +1 -1
- package/.nyc_output/processinfo/index.json +1 -1
- package/full-hugo-renderer/hugo_renderer.wasm +0 -0
- package/full-hugo-renderer/hugo_renderer.wasm.gz +0 -0
- package/lib/translateTextTemplate.js +28 -6
- package/lib/translateTextTemplate.test.js +54 -3
- package/package.json +2 -2
- package/.nyc_output/processinfo/5a2007e8-1bda-4eda-b271-6d7323d49bdd.json +0 -1
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"parent":"
|
|
1
|
+
{"parent":"288189b4-5618-4616-9a86-8209c52bfa78","pid":5524,"argv":["/opt/hostedtoolcache/node/16.18.1/x64/bin/node","/home/runner/work/bookshop/bookshop/javascript-modules/node_modules/ava/lib/worker/subprocess.js"],"execArgv":[],"cwd":"/home/runner/work/bookshop/bookshop/javascript-modules/engines/hugo-engine","time":1670976826633,"ppid":5513,"coverageFilename":"/home/runner/work/bookshop/bookshop/javascript-modules/engines/hugo-engine/.nyc_output/0d71b778-7933-4ad7-b3a3-a0ab8fb25087.json","externalId":"","uuid":"0d71b778-7933-4ad7-b3a3-a0ab8fb25087","files":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"parent":null,"pid":5513,"argv":["/opt/hostedtoolcache/node/16.18.1/x64/bin/node","/home/runner/work/bookshop/bookshop/javascript-modules/node_modules/ava/cli.js","-v"],"execArgv":[],"cwd":"/home/runner/work/bookshop/bookshop/javascript-modules/engines/hugo-engine","time":1670976826223,"ppid":5502,"coverageFilename":"/home/runner/work/bookshop/bookshop/javascript-modules/engines/hugo-engine/.nyc_output/288189b4-5618-4616-9a86-8209c52bfa78.json","externalId":"","uuid":"288189b4-5618-4616-9a86-8209c52bfa78","files":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"parent":"
|
|
1
|
+
{"parent":"288189b4-5618-4616-9a86-8209c52bfa78","pid":5547,"argv":["/opt/hostedtoolcache/node/16.18.1/x64/bin/node","/home/runner/work/bookshop/bookshop/javascript-modules/node_modules/ava/lib/worker/subprocess.js"],"execArgv":[],"cwd":"/home/runner/work/bookshop/bookshop/javascript-modules/engines/hugo-engine","time":1670976826988,"ppid":5513,"coverageFilename":"/home/runner/work/bookshop/bookshop/javascript-modules/engines/hugo-engine/.nyc_output/3a20cbf5-03a8-4e28-9134-bcbe4e3999da.json","externalId":"","uuid":"3a20cbf5-03a8-4e28-9134-bcbe4e3999da","files":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"parent":"
|
|
1
|
+
{"parent":"288189b4-5618-4616-9a86-8209c52bfa78","pid":5530,"argv":["/opt/hostedtoolcache/node/16.18.1/x64/bin/node","/home/runner/work/bookshop/bookshop/javascript-modules/node_modules/ava/lib/worker/subprocess.js"],"execArgv":[],"cwd":"/home/runner/work/bookshop/bookshop/javascript-modules/engines/hugo-engine","time":1670976826639,"ppid":5513,"coverageFilename":"/home/runner/work/bookshop/bookshop/javascript-modules/engines/hugo-engine/.nyc_output/440df8ed-01d8-4b4a-86a4-141986b1c583.json","externalId":"","uuid":"440df8ed-01d8-4b4a-86a4-141986b1c583","files":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"parent":"
|
|
1
|
+
{"parent":"288189b4-5618-4616-9a86-8209c52bfa78","pid":5546,"argv":["/opt/hostedtoolcache/node/16.18.1/x64/bin/node","/home/runner/work/bookshop/bookshop/javascript-modules/node_modules/ava/lib/worker/subprocess.js"],"execArgv":[],"cwd":"/home/runner/work/bookshop/bookshop/javascript-modules/engines/hugo-engine","time":1670976826985,"ppid":5513,"coverageFilename":"/home/runner/work/bookshop/bookshop/javascript-modules/engines/hugo-engine/.nyc_output/df2bb669-e900-4e87-9cf0-f9673bdda2d5.json","externalId":"","uuid":"df2bb669-e900-4e87-9cf0-f9673bdda2d5","files":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"processes":{"
|
|
1
|
+
{"processes":{"0d71b778-7933-4ad7-b3a3-a0ab8fb25087":{"parent":"288189b4-5618-4616-9a86-8209c52bfa78","children":[]},"288189b4-5618-4616-9a86-8209c52bfa78":{"parent":null,"children":["0d71b778-7933-4ad7-b3a3-a0ab8fb25087","3a20cbf5-03a8-4e28-9134-bcbe4e3999da","440df8ed-01d8-4b4a-86a4-141986b1c583","df2bb669-e900-4e87-9cf0-f9673bdda2d5"]},"3a20cbf5-03a8-4e28-9134-bcbe4e3999da":{"parent":"288189b4-5618-4616-9a86-8209c52bfa78","children":[]},"440df8ed-01d8-4b4a-86a4-141986b1c583":{"parent":"288189b4-5618-4616-9a86-8209c52bfa78","children":[]},"df2bb669-e900-4e87-9cf0-f9673bdda2d5":{"parent":"288189b4-5618-4616-9a86-8209c52bfa78","children":[]}},"files":{},"externalIds":{}}
|
|
Binary file
|
|
Binary file
|
|
@@ -2,6 +2,8 @@ import { Tokenizer } from 'liquidjs';
|
|
|
2
2
|
|
|
3
3
|
// Homebrewed pretty-regex writer
|
|
4
4
|
const tokens = {
|
|
5
|
+
ENTER_COMMENT: `\\*/}}`,
|
|
6
|
+
EXIT_COMMENT: `{{/\\*`,
|
|
5
7
|
END: `{{ end }}`,
|
|
6
8
|
BEGIN: `{{ (if)`,
|
|
7
9
|
BEGIN_SCOPED: `{{ (range|with|define|block|template)`,
|
|
@@ -11,6 +13,7 @@ const tokens = {
|
|
|
11
13
|
REASSIGN: `{{ (\\$\\S+) = () }}`,
|
|
12
14
|
WITH: `{{ with () }}`,
|
|
13
15
|
BOOKSHOP: `{{ partial "bookshop" \\( slice "()" () \\) }}`,
|
|
16
|
+
BOOKSHOP_VAR: `{{ partial "bookshop" \\( slice (\\S+) () \\) }}`,
|
|
14
17
|
BOOKSHOP_SCOPED: `{{ partial "bookshop" \\(? \\. \\)? }}`,
|
|
15
18
|
}
|
|
16
19
|
|
|
@@ -26,30 +29,42 @@ Object.entries(tokens).forEach(([name, r]) => {
|
|
|
26
29
|
* that we already have in the bundle.
|
|
27
30
|
* All go templating tags will come through as value tokens.
|
|
28
31
|
*/
|
|
29
|
-
const rewriteTag = function (token, src,
|
|
32
|
+
const rewriteTag = function (token, src, state, liveMarkup) {
|
|
30
33
|
let raw = token.getText();
|
|
31
34
|
let outputToken = {
|
|
32
35
|
text: raw
|
|
33
36
|
}
|
|
34
37
|
|
|
38
|
+
if (TOKENS.ENTER_COMMENT.test(raw)) {
|
|
39
|
+
state.inComment = true
|
|
40
|
+
}
|
|
41
|
+
if (TOKENS.EXIT_COMMENT.test(raw)) {
|
|
42
|
+
state.inComment = false
|
|
43
|
+
return outputToken;
|
|
44
|
+
}
|
|
45
|
+
if (state.inComment) {
|
|
46
|
+
return outputToken;
|
|
47
|
+
}
|
|
35
48
|
// Skip non-value tags
|
|
36
49
|
if (token.kind !== 8) return outputToken;
|
|
50
|
+
|
|
37
51
|
if (TOKENS.END.test(raw)) {
|
|
38
|
-
endTags.push(outputToken);
|
|
52
|
+
state.endTags.push(outputToken);
|
|
39
53
|
return outputToken;
|
|
40
54
|
}
|
|
41
55
|
|
|
42
56
|
if (TOKENS.BEGIN.test(raw)) {
|
|
43
|
-
endTags.pop();
|
|
57
|
+
state.endTags.pop();
|
|
44
58
|
}
|
|
45
59
|
|
|
46
60
|
if (TOKENS.BEGIN_SCOPED.test(raw)) {
|
|
47
61
|
outputToken.text = `${outputToken.text}{{ \`<!--bookshop-live stack-->\` | safeHTML }}`;
|
|
48
62
|
|
|
49
|
-
let matchingEnd = endTags.pop();
|
|
63
|
+
let matchingEnd = state.endTags.pop();
|
|
50
64
|
matchingEnd.text = `{{ \`<!--bookshop-live unstack-->\` | safeHTML }}${matchingEnd.text}`;
|
|
51
65
|
}
|
|
52
66
|
|
|
67
|
+
|
|
53
68
|
if (liveMarkup && TOKENS.INDEX_LOOP.test(raw)) {
|
|
54
69
|
let [, index_variable, iterator] = raw.match(TOKENS.INDEX_LOOP);
|
|
55
70
|
const r = required_wrapper_hugo_func(iterator);
|
|
@@ -89,6 +104,10 @@ const rewriteTag = function (token, src, endTags, liveMarkup) {
|
|
|
89
104
|
`${outputToken.text}`,
|
|
90
105
|
`{{ \`<!--bookshop-live end-->\` | safeHTML }}`
|
|
91
106
|
].join('');
|
|
107
|
+
} else if (liveMarkup && TOKENS.BOOKSHOP_VAR.test(raw)) {
|
|
108
|
+
let [, variable, params] = raw.match(TOKENS.BOOKSHOP_VAR);
|
|
109
|
+
const r = required_wrapper_hugo_func(params);
|
|
110
|
+
outputToken.text = `{{${r[0]} (printf \`<!--bookshop-live name(%s) params(.: (${tidy(params)}))-->\`${r[1]} (${variable})) | safeHTML }}${outputToken.text}{{ \`<!--bookshop-live end-->\` | safeHTML }}`
|
|
92
111
|
}
|
|
93
112
|
|
|
94
113
|
return outputToken;
|
|
@@ -111,10 +130,13 @@ export default function (text, opts) {
|
|
|
111
130
|
const tokenizer = new Tokenizer(text.toString());
|
|
112
131
|
const tokens = tokenizer.readTopLevelTokens();
|
|
113
132
|
const output = [];
|
|
114
|
-
const
|
|
133
|
+
const state = {
|
|
134
|
+
endTags: [],
|
|
135
|
+
inComment: false
|
|
136
|
+
};
|
|
115
137
|
|
|
116
138
|
tokens.reverse().forEach(tag => {
|
|
117
|
-
output.unshift(rewriteTag(tag, text,
|
|
139
|
+
output.unshift(rewriteTag(tag, text, state, opts.liveMarkup));
|
|
118
140
|
});
|
|
119
141
|
|
|
120
142
|
return output.map(t => t.text).join('');
|
|
@@ -11,6 +11,16 @@ test("add live markup to bookshop tags", t => {
|
|
|
11
11
|
t.is(translateTextTemplate(input, {}), expected);
|
|
12
12
|
});
|
|
13
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
|
+
|
|
14
24
|
test("add live markup to scoped bookshop tags", t => {
|
|
15
25
|
const input = `{{ partial "bookshop" . }}`;
|
|
16
26
|
const expected = [
|
|
@@ -30,8 +40,18 @@ test("don't add live markup to bookshop_partial tags", t => {
|
|
|
30
40
|
|
|
31
41
|
test("don't add live markup if no bookshop found", t => {
|
|
32
42
|
let input = `{{ $a := .b }}`;
|
|
33
|
-
|
|
34
|
-
|
|
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);
|
|
35
55
|
});
|
|
36
56
|
|
|
37
57
|
test("add live markup to assigns", t => {
|
|
@@ -175,4 +195,35 @@ test("add live markup to complex components", t => {
|
|
|
175
195
|
{{ safeHTML $close }}
|
|
176
196
|
{{ \`<!--bookshop-live unstack-->\` | safeHTML }}{{ end }}`;
|
|
177
197
|
t.is(translateTextTemplate(input, {}), expected);
|
|
178
|
-
});
|
|
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/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bookshop/hugo-engine",
|
|
3
3
|
"packageManager": "yarn@3.0.0",
|
|
4
|
-
"version": "3.4.0-beta.
|
|
4
|
+
"version": "3.4.0-beta.2",
|
|
5
5
|
"description": "Bookshop frontend Hugo renderer",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"sideEffects": false,
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"nyc": "^15.1.0"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@bookshop/helpers": "3.4.0-beta.
|
|
33
|
+
"@bookshop/helpers": "3.4.0-beta.2",
|
|
34
34
|
"esbuild": "^0.13.10",
|
|
35
35
|
"fflate": "^0.7.3",
|
|
36
36
|
"liquidjs": "9.28.0"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"parent":null,"pid":5578,"argv":["/opt/hostedtoolcache/node/16.18.1/x64/bin/node","/home/runner/work/bookshop/bookshop/javascript-modules/node_modules/ava/cli.js","-v"],"execArgv":[],"cwd":"/home/runner/work/bookshop/bookshop/javascript-modules/engines/hugo-engine","time":1670907491400,"ppid":5566,"coverageFilename":"/home/runner/work/bookshop/bookshop/javascript-modules/engines/hugo-engine/.nyc_output/5a2007e8-1bda-4eda-b271-6d7323d49bdd.json","externalId":"","uuid":"5a2007e8-1bda-4eda-b271-6d7323d49bdd","files":[]}
|