@bookshop/hugo-engine 2.4.0-hugo.2 → 2.4.1
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/{b63b1b97-4b16-4cde-9e6e-60a2ff0c075f.json → 0285db3a-0bb1-48c5-a949-061f568eaab6.json} +0 -0
- package/.nyc_output/{bc05c575-6f03-4c35-bddb-43fcb1616060.json → 222873c9-9975-439a-a423-1e8cdec80767.json} +0 -0
- package/.nyc_output/{bc613327-aa07-4b95-a1fc-bbf3c9e29952.json → 3abd89cc-3259-442a-a584-30ba1c47f41f.json} +0 -0
- package/.nyc_output/{dc9d7295-1c20-414a-9d4b-db9ba1048bff.json → 72cd08d5-81da-4a01-af7e-b82f5c58bfe2.json} +0 -0
- package/.nyc_output/{f5078748-1e55-4d0b-ae19-a8a1cb800295.json → 85ee537c-1dd7-4a62-96e1-954d77437eb0.json} +0 -0
- package/.nyc_output/processinfo/{b63b1b97-4b16-4cde-9e6e-60a2ff0c075f.json → 0285db3a-0bb1-48c5-a949-061f568eaab6.json} +1 -1
- package/.nyc_output/processinfo/222873c9-9975-439a-a423-1e8cdec80767.json +1 -0
- package/.nyc_output/processinfo/{bc05c575-6f03-4c35-bddb-43fcb1616060.json → 3abd89cc-3259-442a-a584-30ba1c47f41f.json} +1 -1
- package/.nyc_output/processinfo/{bc613327-aa07-4b95-a1fc-bbf3c9e29952.json → 72cd08d5-81da-4a01-af7e-b82f5c58bfe2.json} +1 -1
- package/.nyc_output/processinfo/{dc9d7295-1c20-414a-9d4b-db9ba1048bff.json → 85ee537c-1dd7-4a62-96e1-954d77437eb0.json} +1 -1
- package/.nyc_output/processinfo/index.json +1 -1
- package/hugo-renderer/build.sh +51 -10
- package/lib/engine.js +34 -7
- package/lib/hugoIdentifierParser.js +7 -1
- package/lib/hugoIdentifierParser.test.js +21 -2
- package/lib/translateTextTemplate.js +18 -5
- package/lib/translateTextTemplate.test.js +33 -10
- package/package.json +2 -2
- package/.nyc_output/processinfo/f5078748-1e55-4d0b-ae19-a8a1cb800295.json +0 -1
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"parent":"
|
|
1
|
+
{"parent":"222873c9-9975-439a-a423-1e8cdec80767","pid":37259,"argv":["/Users/liambigelow/.nvm/versions/node/v14.16.0/bin/node","/Users/liambigelow/Projects/CC/bookshop/javascript-modules/node_modules/ava/lib/worker/subprocess.js"],"execArgv":[],"cwd":"/Users/liambigelow/Projects/CC/bookshop/javascript-modules/engines/hugo-engine","time":1643741988315,"ppid":37256,"coverageFilename":"/Users/liambigelow/Projects/CC/bookshop/javascript-modules/engines/hugo-engine/.nyc_output/0285db3a-0bb1-48c5-a949-061f568eaab6.json","externalId":"","uuid":"0285db3a-0bb1-48c5-a949-061f568eaab6","files":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"parent":null,"pid":37256,"argv":["/Users/liambigelow/.nvm/versions/node/v14.16.0/bin/node","/Users/liambigelow/Projects/CC/bookshop/javascript-modules/node_modules/ava/cli.js","-v"],"execArgv":[],"cwd":"/Users/liambigelow/Projects/CC/bookshop/javascript-modules/engines/hugo-engine","time":1643741987817,"ppid":37255,"coverageFilename":"/Users/liambigelow/Projects/CC/bookshop/javascript-modules/engines/hugo-engine/.nyc_output/222873c9-9975-439a-a423-1e8cdec80767.json","externalId":"","uuid":"222873c9-9975-439a-a423-1e8cdec80767","files":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"parent":"
|
|
1
|
+
{"parent":"222873c9-9975-439a-a423-1e8cdec80767","pid":37260,"argv":["/Users/liambigelow/.nvm/versions/node/v14.16.0/bin/node","/Users/liambigelow/Projects/CC/bookshop/javascript-modules/node_modules/ava/lib/worker/subprocess.js"],"execArgv":[],"cwd":"/Users/liambigelow/Projects/CC/bookshop/javascript-modules/engines/hugo-engine","time":1643741988320,"ppid":37256,"coverageFilename":"/Users/liambigelow/Projects/CC/bookshop/javascript-modules/engines/hugo-engine/.nyc_output/3abd89cc-3259-442a-a584-30ba1c47f41f.json","externalId":"","uuid":"3abd89cc-3259-442a-a584-30ba1c47f41f","files":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"parent":"
|
|
1
|
+
{"parent":"222873c9-9975-439a-a423-1e8cdec80767","pid":37258,"argv":["/Users/liambigelow/.nvm/versions/node/v14.16.0/bin/node","/Users/liambigelow/Projects/CC/bookshop/javascript-modules/node_modules/ava/lib/worker/subprocess.js"],"execArgv":[],"cwd":"/Users/liambigelow/Projects/CC/bookshop/javascript-modules/engines/hugo-engine","time":1643741988310,"ppid":37256,"coverageFilename":"/Users/liambigelow/Projects/CC/bookshop/javascript-modules/engines/hugo-engine/.nyc_output/72cd08d5-81da-4a01-af7e-b82f5c58bfe2.json","externalId":"","uuid":"72cd08d5-81da-4a01-af7e-b82f5c58bfe2","files":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"parent":"
|
|
1
|
+
{"parent":"222873c9-9975-439a-a423-1e8cdec80767","pid":37257,"argv":["/Users/liambigelow/.nvm/versions/node/v14.16.0/bin/node","/Users/liambigelow/Projects/CC/bookshop/javascript-modules/node_modules/ava/lib/worker/subprocess.js"],"execArgv":[],"cwd":"/Users/liambigelow/Projects/CC/bookshop/javascript-modules/engines/hugo-engine","time":1643741988307,"ppid":37256,"coverageFilename":"/Users/liambigelow/Projects/CC/bookshop/javascript-modules/engines/hugo-engine/.nyc_output/85ee537c-1dd7-4a62-96e1-954d77437eb0.json","externalId":"","uuid":"85ee537c-1dd7-4a62-96e1-954d77437eb0","files":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"processes":{"
|
|
1
|
+
{"processes":{"0285db3a-0bb1-48c5-a949-061f568eaab6":{"parent":"222873c9-9975-439a-a423-1e8cdec80767","children":[]},"222873c9-9975-439a-a423-1e8cdec80767":{"parent":null,"children":["0285db3a-0bb1-48c5-a949-061f568eaab6","3abd89cc-3259-442a-a584-30ba1c47f41f","72cd08d5-81da-4a01-af7e-b82f5c58bfe2","85ee537c-1dd7-4a62-96e1-954d77437eb0"]},"3abd89cc-3259-442a-a584-30ba1c47f41f":{"parent":"222873c9-9975-439a-a423-1e8cdec80767","children":[]},"72cd08d5-81da-4a01-af7e-b82f5c58bfe2":{"parent":"222873c9-9975-439a-a423-1e8cdec80767","children":[]},"85ee537c-1dd7-4a62-96e1-954d77437eb0":{"parent":"222873c9-9975-439a-a423-1e8cdec80767","children":[]}},"files":{},"externalIds":{}}
|
package/hugo-renderer/build.sh
CHANGED
|
@@ -1,16 +1,57 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
GOOS=js GOARCH=wasm go build -tags nodeploy -o $FILENAME
|
|
4
|
-
printf "Built Hugo WASM via $FILENAME : "
|
|
5
|
-
ls -lh $FILENAME | awk '{print $5}'
|
|
6
|
-
if [ -f hugo_renderer.wasm ]; then
|
|
7
|
-
echo "ERROR: previous hugo_renderer.wasm still in directory"
|
|
1
|
+
if [[ -z "${BOOKSHOP_VERSION}" ]]; then
|
|
2
|
+
echo "ERROR: BOOKSHOP_VERSION environment variable does not exist"
|
|
8
3
|
exit 1
|
|
9
4
|
fi
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
|
|
6
|
+
TMPFILENAME="hugo_renderer_$(date +%s).wasm"
|
|
7
|
+
OUTPUTFILENAME="hugo_renderer.wasm"
|
|
8
|
+
CDNFILENAME="../../../../../bookshopcdn/hugo/hugo_renderer_$BOOKSHOP_VERSION.wasm"
|
|
9
|
+
|
|
10
|
+
# Clean
|
|
11
|
+
rm -f $OUTPUTFILENAME
|
|
12
|
+
if [ -f $OUTPUTFILENAME ]; then
|
|
13
|
+
echo "ERROR: previous $OUTPUTFILENAME still in directory"
|
|
14
|
+
exit 1
|
|
15
|
+
fi
|
|
16
|
+
|
|
17
|
+
# Build temp module
|
|
18
|
+
GOOS=js GOARCH=wasm go build -tags nodeploy -o $TMPFILENAME
|
|
19
|
+
printf "Built Hugo WASM via $TMPFILENAME : "
|
|
20
|
+
ls -lh $TMPFILENAME | awk '{print $5}'
|
|
21
|
+
|
|
22
|
+
# Link repo module
|
|
23
|
+
mv $TMPFILENAME $OUTPUTFILENAME
|
|
24
|
+
if [ ! -f $OUTPUTFILENAME ]; then
|
|
12
25
|
echo "ERROR: hugo_renderer.wasm not complete"
|
|
13
26
|
exit 1
|
|
14
27
|
fi
|
|
15
|
-
echo "Done. Hugo WASM available at hugo_renderer.wasm"
|
|
28
|
+
echo "Done. Repo Hugo WASM available at hugo_renderer.wasm"
|
|
29
|
+
|
|
30
|
+
# If we're just in a test run we don't want to touch the CDN repo
|
|
31
|
+
if [[ -z "${PUBLISH_BOOKSHOP_CDN}" ]]; then
|
|
32
|
+
echo "Not publishing to CDN."
|
|
33
|
+
exit 0
|
|
34
|
+
fi
|
|
35
|
+
|
|
36
|
+
# Check CDN
|
|
37
|
+
if [ ! -d ../../../../../bookshopcdn/hugo ]; then
|
|
38
|
+
echo "ERROR: bookshopcdn repo does not exist alongside bookshop repo"
|
|
39
|
+
exit 1
|
|
40
|
+
fi
|
|
41
|
+
|
|
42
|
+
# Link CDN module
|
|
43
|
+
cp $OUTPUTFILENAME $CDNFILENAME
|
|
44
|
+
if [ ! -f $CDNFILENAME ]; then
|
|
45
|
+
echo "ERROR: $CDNFILENAME not complete"
|
|
46
|
+
exit 1
|
|
47
|
+
fi
|
|
48
|
+
echo "Done. CDN Hugo WASM available at $CDNFILENAME"
|
|
49
|
+
|
|
50
|
+
cd ../../../../../bookshopcdn
|
|
51
|
+
|
|
52
|
+
git add -A \
|
|
53
|
+
&& git commit -m "build: releasing $BOOKSHOP_VERSION" \
|
|
54
|
+
&& git tag -a v$BOOKSHOP_VERSION -m "build: releasing $BOOKSHOP_VERSION" \
|
|
55
|
+
&& git push --tags && git push
|
|
56
|
+
|
|
16
57
|
exit 0
|
package/lib/engine.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import hugoWasm from "../hugo-renderer/hugo_renderer.wasm";
|
|
2
2
|
import translateTextTemplate from './translateTextTemplate.js';
|
|
3
3
|
import { IdentifierParser } from './hugoIdentifierParser.js';
|
|
4
|
+
import { version } from '../package.json';
|
|
4
5
|
|
|
5
6
|
const sleep = (ms = 0) => {
|
|
6
7
|
return new Promise(r => setTimeout(r, ms));
|
|
@@ -24,18 +25,17 @@ export class Engine {
|
|
|
24
25
|
this.key = 'hugo';
|
|
25
26
|
this.name = options.name;
|
|
26
27
|
this.files = options.files;
|
|
28
|
+
this.origin = document.currentScript?.src || `/bookshop.js`;
|
|
27
29
|
|
|
28
30
|
this.initializeHugo();
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
async initializeHugo() {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const result = await WebAssembly.instantiate(buffer, go.importObject);
|
|
38
|
-
go.run(result.instance)
|
|
34
|
+
if (window.CloudCannon?.isMocked) {
|
|
35
|
+
await this.initializeLocalHugo();
|
|
36
|
+
} else {
|
|
37
|
+
await this.initializeRemoteHugo();
|
|
38
|
+
}
|
|
39
39
|
|
|
40
40
|
// TODO: Tidy
|
|
41
41
|
const mappedFiles = {};
|
|
@@ -48,6 +48,33 @@ export class Engine {
|
|
|
48
48
|
const success = window.loadHugoBookshopPartials(JSON.stringify(mappedFiles));
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
+
async initializeRemoteHugo() {
|
|
52
|
+
try {
|
|
53
|
+
const go = new Go();
|
|
54
|
+
const remoteWasmOrigin = `https://cdn.bookshop.build/hugo/hugo_renderer_${version}.wasm`;
|
|
55
|
+
const remoteResponse = await fetch(remoteWasmOrigin);
|
|
56
|
+
const remoteBuffer = await remoteResponse.arrayBuffer();
|
|
57
|
+
|
|
58
|
+
// Check the magic word at the start of the buffer as a way to verify the CDN download worked.
|
|
59
|
+
const isWasm = ([...new Uint8Array(remoteBuffer, 0, 4)]).map(g => g.toString(16).padStart(2, '0')).join('') === "0061736d";
|
|
60
|
+
if (!isWasm) throw "Not WASM";
|
|
61
|
+
|
|
62
|
+
const remoteResult = await WebAssembly.instantiate(remoteBuffer, go.importObject);
|
|
63
|
+
go.run(remoteResult.instance);
|
|
64
|
+
} catch (e) {
|
|
65
|
+
await this.initializeLocalHugo();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async initializeLocalHugo() {
|
|
70
|
+
const go = new Go();
|
|
71
|
+
const wasmOrigin = this.origin.replace(/\/[^\.\/]+\.js$/, hugoWasm.replace(/^\./, ''));
|
|
72
|
+
const response = await fetch(wasmOrigin);
|
|
73
|
+
const buffer = await response.arrayBuffer();
|
|
74
|
+
const result = await WebAssembly.instantiate(buffer, go.importObject);
|
|
75
|
+
go.run(result.instance);
|
|
76
|
+
}
|
|
77
|
+
|
|
51
78
|
getShared(name) {
|
|
52
79
|
const key = `shared/hugo/${name}.hugo.html`
|
|
53
80
|
return this.files?.[key];
|
|
@@ -22,6 +22,13 @@ export class IdentifierParser {
|
|
|
22
22
|
|
|
23
23
|
// Some short-circuits for easy to regex patterns to skip the parser
|
|
24
24
|
tryShortCircuit() {
|
|
25
|
+
// change an index of . to be only the index
|
|
26
|
+
const indexDotFunc = /^\s*\(\s*index\s+(?:\(\s*\.\s*\)|\.)\s+(\d+)\s*\)\s*$/
|
|
27
|
+
if (indexDotFunc.test(this.input)) {
|
|
28
|
+
const [, index] = this.input.match(indexDotFunc);
|
|
29
|
+
return `${index}`;
|
|
30
|
+
}
|
|
31
|
+
|
|
25
32
|
// change the index function into Bookshop dot notation
|
|
26
33
|
const indexFunc = /^\s*\(\s*index\s+\(?\.?(.+?)\)?\s+(\d+)\s*\)\s*$/
|
|
27
34
|
if (indexFunc.test(this.input)) {
|
|
@@ -30,7 +37,6 @@ export class IdentifierParser {
|
|
|
30
37
|
}
|
|
31
38
|
|
|
32
39
|
// strip the leading . from basic variable references
|
|
33
|
-
const variableDot = /^\s*\.([^\.\s])/;
|
|
34
40
|
if (/^\s*\./.test(this.input)) {
|
|
35
41
|
return this.input.replace(/^\s*\.([^\.\s])/, '$1');
|
|
36
42
|
}
|
|
@@ -66,7 +66,26 @@ test(`Nested dicts and slices`, async t => {
|
|
|
66
66
|
});
|
|
67
67
|
|
|
68
68
|
test(`Converts an index into dot notation`, async t => {
|
|
69
|
-
|
|
70
|
-
|
|
69
|
+
let ident = `(index (.items) 5)`;
|
|
70
|
+
let output = (new IdentifierParser(ident)).build();
|
|
71
71
|
t.deepEqual(output, `items.5`);
|
|
72
|
+
|
|
73
|
+
ident = `(index .array 5)`;
|
|
74
|
+
output = (new IdentifierParser(ident)).build();
|
|
75
|
+
t.deepEqual(output, `array.5`);
|
|
76
|
+
|
|
77
|
+
ident = `(index $variable 5)`;
|
|
78
|
+
output = (new IdentifierParser(ident)).build();
|
|
79
|
+
t.deepEqual(output, `$variable.5`);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
test(`Converts a dot index into a JS object property`, async t => {
|
|
84
|
+
let ident = `(index (.) 5)`;
|
|
85
|
+
let output = (new IdentifierParser(ident)).build();
|
|
86
|
+
t.deepEqual(output, `5`);
|
|
87
|
+
|
|
88
|
+
ident = `(index . 1234)`;
|
|
89
|
+
output = (new IdentifierParser(ident)).build();
|
|
90
|
+
t.deepEqual(output, `1234`);
|
|
72
91
|
});
|
|
@@ -5,9 +5,11 @@ const tokens = {
|
|
|
5
5
|
BEGIN: /{{\s*(if)/,
|
|
6
6
|
BEGIN_SCOPED: /{{\s*(range|with|define|block|template)/,
|
|
7
7
|
LOOP: /{{\s*range\s+(.+?)\s*}}/,
|
|
8
|
+
INDEX_LOOP: /{{\s*range\s+(\$.+), \$.+ := (.+?)\s*}}/,
|
|
8
9
|
ASSIGN: /{{\s*(\$\S+)\s+:=\s+(.+?)\s*}}/,
|
|
9
10
|
WITH: /{{\s*with\s+(.+?)\s*}}/,
|
|
10
|
-
BOOKSHOP: /{{\s*partial\s+"bookshop
|
|
11
|
+
BOOKSHOP: /{{\s*partial\s+"bookshop"\s+\(\s*slice\s+"(.+?)" (.+?)\s*\)\s*}}/,
|
|
12
|
+
BOOKSHOP_SCOPED: /{{\s*partial\s+"bookshop"\s+\(?\s*\.\s*\)?\s*}}/,
|
|
11
13
|
}
|
|
12
14
|
|
|
13
15
|
/**
|
|
@@ -39,7 +41,12 @@ const rewriteTag = function (token, src, endTags, liveMarkup) {
|
|
|
39
41
|
matchingEnd.text = `{{ \`<!--bookshop-live unstack-->\` | safeHTML }}${matchingEnd.text}`;
|
|
40
42
|
}
|
|
41
43
|
|
|
42
|
-
if (liveMarkup && tokens.
|
|
44
|
+
if (liveMarkup && tokens.INDEX_LOOP.test(raw)) {
|
|
45
|
+
let [, index_variable, iterator] = raw.match(tokens.INDEX_LOOP);
|
|
46
|
+
outputToken.text = [`${outputToken.text}`,
|
|
47
|
+
`{{ (printf \`<!--bookshop-live context(.: (index (${iterator}) %d))-->\` ${index_variable}) | safeHTML }}`
|
|
48
|
+
].join('')
|
|
49
|
+
} else if (liveMarkup && tokens.LOOP.test(raw)) {
|
|
43
50
|
let [, iterator] = raw.match(tokens.LOOP);
|
|
44
51
|
outputToken.text = [`{{ $bookshop__live__iterator := 0 }}`,
|
|
45
52
|
`${outputToken.text}`,
|
|
@@ -48,13 +55,19 @@ const rewriteTag = function (token, src, endTags, liveMarkup) {
|
|
|
48
55
|
].join('')
|
|
49
56
|
} else if (liveMarkup && tokens.ASSIGN.test(raw)) {
|
|
50
57
|
let [, identifier, value] = raw.match(tokens.ASSIGN);
|
|
51
|
-
outputToken.text = `${outputToken.text}{{ \`<!--bookshop-live context(${identifier}: ${value})-->\` | safeHTML }}`
|
|
58
|
+
outputToken.text = `${outputToken.text}{{ \`<!--bookshop-live context(${identifier}: (${value}))-->\` | safeHTML }}`
|
|
52
59
|
} else if (liveMarkup && tokens.WITH.test(raw)) {
|
|
53
60
|
let [, value] = raw.match(tokens.WITH);
|
|
54
|
-
outputToken.text = `${outputToken.text}{{ \`<!--bookshop-live context(.: ${value})-->\` | safeHTML }}`
|
|
61
|
+
outputToken.text = `${outputToken.text}{{ \`<!--bookshop-live context(.: (${value}))-->\` | safeHTML }}`
|
|
55
62
|
} else if (liveMarkup && tokens.BOOKSHOP.test(raw)) {
|
|
56
63
|
let [, name, params] = raw.match(tokens.BOOKSHOP);
|
|
57
|
-
outputToken.text = `{{ \`<!--bookshop-live name(${name}) params(.: ${params})-->\` | safeHTML }}${outputToken.text}{{ \`<!--bookshop-live end-->\` | safeHTML }}`
|
|
64
|
+
outputToken.text = `{{ \`<!--bookshop-live name(${name}) params(.: (${params}))-->\` | safeHTML }}${outputToken.text}{{ \`<!--bookshop-live end-->\` | safeHTML }}`
|
|
65
|
+
} else if (liveMarkup && tokens.BOOKSHOP_SCOPED.test(raw)) {
|
|
66
|
+
outputToken.text = [`{{ if reflect.IsSlice . }}{{ (printf \`<!--bookshop-live name(%s) params(.: .)-->\` (index . 0)) | safeHTML }}`,
|
|
67
|
+
`{{- else if reflect.IsMap . -}}{{ (printf \`<!--bookshop-live name(%s) params(.: .)-->\` ._bookshop_name) | safeHTML }}{{ end }}`,
|
|
68
|
+
`${outputToken.text}`,
|
|
69
|
+
`{{ \`<!--bookshop-live end-->\` | safeHTML }}`
|
|
70
|
+
].join('');
|
|
58
71
|
}
|
|
59
72
|
|
|
60
73
|
return outputToken;
|
|
@@ -4,26 +4,37 @@ import translateTextTemplate from './translateTextTemplate.js';
|
|
|
4
4
|
test("add live markup to bookshop tags", t => {
|
|
5
5
|
const input = `{{ partial "bookshop" (slice "content" (dict "content_html" .Params.note_html "type" "note")) }}`;
|
|
6
6
|
const expected = [
|
|
7
|
-
`{{ \`<!--bookshop-live name(content) params(.: (dict "content_html" .Params.note_html "type" "note"))-->\` | safeHTML }}`,
|
|
7
|
+
`{{ \`<!--bookshop-live name(content) params(.: ((dict "content_html" .Params.note_html "type" "note")))-->\` | safeHTML }}`,
|
|
8
8
|
`{{ partial "bookshop" (slice "content" (dict "content_html" .Params.note_html "type" "note")) }}`,
|
|
9
9
|
`{{ \`<!--bookshop-live end-->\` | safeHTML }}`
|
|
10
10
|
].join('');
|
|
11
11
|
t.is(translateTextTemplate(input, {}), expected);
|
|
12
12
|
});
|
|
13
13
|
|
|
14
|
-
test("add live markup to
|
|
15
|
-
const input = `{{ partial "
|
|
14
|
+
test("add live markup to scoped bookshop tags", t => {
|
|
15
|
+
const input = `{{ partial "bookshop" . }}`;
|
|
16
16
|
const expected = [
|
|
17
|
-
`{{ \`<!--bookshop-live name(
|
|
18
|
-
`{{
|
|
17
|
+
`{{ if reflect.IsSlice . }}{{ (printf \`<!--bookshop-live name(%s) params(.: .)-->\` (index . 0)) | safeHTML }}`,
|
|
18
|
+
`{{- else if reflect.IsMap . -}}{{ (printf \`<!--bookshop-live name(%s) params(.: .)-->\` ._bookshop_name) | safeHTML }}{{ end }}`,
|
|
19
|
+
`{{ partial "bookshop" . }}`,
|
|
19
20
|
`{{ \`<!--bookshop-live end-->\` | safeHTML }}`
|
|
20
21
|
].join('');
|
|
21
22
|
t.is(translateTextTemplate(input, {}), expected);
|
|
22
23
|
});
|
|
23
24
|
|
|
25
|
+
test("don't add live markup to bookshop_partial tags", t => {
|
|
26
|
+
const input = `{{ partial "bookshop_partial" (slice "helper" (dict "text" "input")) }}`;
|
|
27
|
+
const expected = `{{ partial "bookshop_partial" (slice "helper" (dict "text" "input")) }}`;
|
|
28
|
+
t.is(translateTextTemplate(input, {}), expected);
|
|
29
|
+
});
|
|
30
|
+
|
|
24
31
|
test("add live markup to assigns", t => {
|
|
25
|
-
|
|
26
|
-
|
|
32
|
+
let input = `{{ $a := .b }}`;
|
|
33
|
+
let expected = `{{ $a := .b }}{{ \`<!--bookshop-live context($a: (.b))-->\` | safeHTML }}`;
|
|
34
|
+
t.is(translateTextTemplate(input, {}), expected);
|
|
35
|
+
|
|
36
|
+
input = `{{ $a := .b | chomp }}`;
|
|
37
|
+
expected = `{{ $a := .b | chomp }}{{ \`<!--bookshop-live context($a: (.b | chomp))-->\` | safeHTML }}`;
|
|
27
38
|
t.is(translateTextTemplate(input, {}), expected);
|
|
28
39
|
});
|
|
29
40
|
|
|
@@ -31,7 +42,7 @@ test("add live markup to withs", t => {
|
|
|
31
42
|
const input = `{{ with .b }}<p>{{.}}</p>{{ end }}`;
|
|
32
43
|
const expected = [`{{ with .b }}`,
|
|
33
44
|
`{{ \`<!--bookshop-live stack-->\` | safeHTML }}`,
|
|
34
|
-
`{{ \`<!--bookshop-live context(.: .b)-->\` | safeHTML }}`,
|
|
45
|
+
`{{ \`<!--bookshop-live context(.: (.b))-->\` | safeHTML }}`,
|
|
35
46
|
`<p>{{.}}</p>`,
|
|
36
47
|
`{{ \`<!--bookshop-live unstack-->\` | safeHTML }}`,
|
|
37
48
|
`{{ end }}`
|
|
@@ -53,6 +64,18 @@ test("add live markup to loops", t => {
|
|
|
53
64
|
t.is(translateTextTemplate(input, {}), expected);
|
|
54
65
|
});
|
|
55
66
|
|
|
67
|
+
test("add live markup to loops with iterators", t => {
|
|
68
|
+
const input = `{{range $loop_index, $element := .columns}}<p>{{$element}}</p>{{ end }}`;
|
|
69
|
+
const expected = [`{{range $loop_index, $element := .columns}}`,
|
|
70
|
+
`{{ \`<!--bookshop-live stack-->\` | safeHTML }}`,
|
|
71
|
+
`{{ (printf \`<!--bookshop-live context(.: (index (.columns) %d))-->\` $loop_index) | safeHTML }}`,
|
|
72
|
+
`<p>{{$element}}</p>`,
|
|
73
|
+
`{{ \`<!--bookshop-live unstack-->\` | safeHTML }}`,
|
|
74
|
+
`{{ end }}`
|
|
75
|
+
].join('');
|
|
76
|
+
t.is(translateTextTemplate(input, {}), expected);
|
|
77
|
+
});
|
|
78
|
+
|
|
56
79
|
test("add live markup to complex end structures", t => {
|
|
57
80
|
const input = `
|
|
58
81
|
{{ range .items }}
|
|
@@ -73,14 +96,14 @@ test("add live markup to complex end structures", t => {
|
|
|
73
96
|
const expected = `
|
|
74
97
|
{{ $bookshop__live__iterator := 0 }}{{ range .items }}{{ \`<!--bookshop-live stack-->\` | safeHTML }}{{ (printf \`<!--bookshop-live context(.: (index (.items) %d))-->\` $bookshop__live__iterator) | safeHTML }}{{ $bookshop__live__iterator = (add $bookshop__live__iterator 1) }}
|
|
75
98
|
|
|
76
|
-
{{with .text}}{{ \`<!--bookshop-live stack-->\` | safeHTML }}{{ \`<!--bookshop-live context(.: .text)-->\` | safeHTML }}
|
|
99
|
+
{{with .text}}{{ \`<!--bookshop-live stack-->\` | safeHTML }}{{ \`<!--bookshop-live context(.: (.text))-->\` | safeHTML }}
|
|
77
100
|
<p>{{ . }}</p>
|
|
78
101
|
{{ \`<!--bookshop-live unstack-->\` | safeHTML }}{{ end }}
|
|
79
102
|
|
|
80
103
|
{{ if .subtitle }}
|
|
81
104
|
<h2>{{ .subtitle }}</h2>
|
|
82
105
|
{{ else }}
|
|
83
|
-
{{ with .excerpt }}{{ \`<!--bookshop-live stack-->\` | safeHTML }}{{ \`<!--bookshop-live context(.: .excerpt)-->\` | safeHTML }}
|
|
106
|
+
{{ with .excerpt }}{{ \`<!--bookshop-live stack-->\` | safeHTML }}{{ \`<!--bookshop-live context(.: (.excerpt))-->\` | safeHTML }}
|
|
84
107
|
<p>{{ . }}</p>
|
|
85
108
|
{{ \`<!--bookshop-live unstack-->\` | safeHTML }}{{end}}
|
|
86
109
|
{{ end }}
|
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": "2.4.
|
|
4
|
+
"version": "2.4.1",
|
|
5
5
|
"description": "Bookshop frontend Hugo renderer",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"sideEffects": false,
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"nyc": "^15.1.0"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@bookshop/helpers": "2.4.
|
|
32
|
+
"@bookshop/helpers": "2.4.1",
|
|
33
33
|
"esbuild": "^0.13.10",
|
|
34
34
|
"liquidjs": "9.28.0"
|
|
35
35
|
},
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"parent":null,"pid":33681,"argv":["/Users/liambigelow/.nvm/versions/node/v14.16.0/bin/node","/Users/liambigelow/Projects/CC/bookshop/javascript-modules/node_modules/ava/cli.js","-v"],"execArgv":[],"cwd":"/Users/liambigelow/Projects/CC/bookshop/javascript-modules/engines/hugo-engine","time":1643512427154,"ppid":33680,"coverageFilename":"/Users/liambigelow/Projects/CC/bookshop/javascript-modules/engines/hugo-engine/.nyc_output/f5078748-1e55-4d0b-ae19-a8a1cb800295.json","externalId":"","uuid":"f5078748-1e55-4d0b-ae19-a8a1cb800295","files":[]}
|