@bookshop/hugo-engine 2.6.1 → 3.0.0-beta.0
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/{51df4d42-a45e-4cd8-8872-46e9147299bf.json → 0a7e2ebb-5cd8-42e1-8a75-1a844a599cb3.json} +0 -0
- package/.nyc_output/{8ff4b2d0-5848-4ba6-9e8b-455ac526027c.json → 1792cc95-23bc-4475-8a0a-5349fa6ea252.json} +0 -0
- package/.nyc_output/{970a6ddf-4bc1-4741-8913-f05ce8e287c6.json → 23b4d867-eb11-4139-958c-db9fba067b6b.json} +0 -0
- package/.nyc_output/{ac095d2d-5d4a-449e-82ae-0e0f0dd32b01.json → 480921e8-42bb-45b3-a743-dc9866e1335b.json} +0 -0
- package/.nyc_output/{f5e4f4d9-24b3-4cb7-a369-95e27032d6ba.json → db445aca-7b0a-4fbd-b378-8f81807219e8.json} +0 -0
- package/.nyc_output/processinfo/{51df4d42-a45e-4cd8-8872-46e9147299bf.json → 0a7e2ebb-5cd8-42e1-8a75-1a844a599cb3.json} +1 -1
- package/.nyc_output/processinfo/{8ff4b2d0-5848-4ba6-9e8b-455ac526027c.json → 1792cc95-23bc-4475-8a0a-5349fa6ea252.json} +1 -1
- package/.nyc_output/processinfo/{970a6ddf-4bc1-4741-8913-f05ce8e287c6.json → 23b4d867-eb11-4139-958c-db9fba067b6b.json} +1 -1
- package/.nyc_output/processinfo/{f5e4f4d9-24b3-4cb7-a369-95e27032d6ba.json → 480921e8-42bb-45b3-a743-dc9866e1335b.json} +1 -1
- package/.nyc_output/processinfo/db445aca-7b0a-4fbd-b378-8f81807219e8.json +1 -0
- package/.nyc_output/processinfo/index.json +1 -1
- package/hugo-renderer/hugo_renderer.wasm +0 -0
- package/hugo-renderer/main.go +14 -0
- package/hugo-renderer/tpl/bookshop_engine/bookshop_func_importer.go +3 -2
- package/hugo-renderer/tpl/bookshop_library/bookshop_data.go +53 -0
- package/hugo-renderer/tpl/site/bookshop_site.go +59 -0
- package/hugo-renderer/tpl/site/init.go +41 -0
- package/lib/engine.js +26 -4
- package/lib/translateTextTemplate.js +5 -2
- package/lib/translateTextTemplate.test.js +6 -3
- package/package.json +2 -2
- package/.nyc_output/processinfo/ac095d2d-5d4a-449e-82ae-0e0f0dd32b01.json +0 -1
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"parent":"
|
|
1
|
+
{"parent":"db445aca-7b0a-4fbd-b378-8f81807219e8","pid":41226,"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":1648442969710,"ppid":41179,"coverageFilename":"/Users/liambigelow/Projects/CC/bookshop/javascript-modules/engines/hugo-engine/.nyc_output/0a7e2ebb-5cd8-42e1-8a75-1a844a599cb3.json","externalId":"","uuid":"0a7e2ebb-5cd8-42e1-8a75-1a844a599cb3","files":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"parent":"
|
|
1
|
+
{"parent":"db445aca-7b0a-4fbd-b378-8f81807219e8","pid":41228,"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":1648442969727,"ppid":41179,"coverageFilename":"/Users/liambigelow/Projects/CC/bookshop/javascript-modules/engines/hugo-engine/.nyc_output/1792cc95-23bc-4475-8a0a-5349fa6ea252.json","externalId":"","uuid":"1792cc95-23bc-4475-8a0a-5349fa6ea252","files":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"parent":"
|
|
1
|
+
{"parent":"db445aca-7b0a-4fbd-b378-8f81807219e8","pid":41225,"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":1648442969705,"ppid":41179,"coverageFilename":"/Users/liambigelow/Projects/CC/bookshop/javascript-modules/engines/hugo-engine/.nyc_output/23b4d867-eb11-4139-958c-db9fba067b6b.json","externalId":"","uuid":"23b4d867-eb11-4139-958c-db9fba067b6b","files":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"parent":"
|
|
1
|
+
{"parent":"db445aca-7b0a-4fbd-b378-8f81807219e8","pid":41227,"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":1648442969715,"ppid":41179,"coverageFilename":"/Users/liambigelow/Projects/CC/bookshop/javascript-modules/engines/hugo-engine/.nyc_output/480921e8-42bb-45b3-a743-dc9866e1335b.json","externalId":"","uuid":"480921e8-42bb-45b3-a743-dc9866e1335b","files":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"parent":null,"pid":41179,"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":1648442969247,"ppid":41160,"coverageFilename":"/Users/liambigelow/Projects/CC/bookshop/javascript-modules/engines/hugo-engine/.nyc_output/db445aca-7b0a-4fbd-b378-8f81807219e8.json","externalId":"","uuid":"db445aca-7b0a-4fbd-b378-8f81807219e8","files":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"processes":{"
|
|
1
|
+
{"processes":{"0a7e2ebb-5cd8-42e1-8a75-1a844a599cb3":{"parent":"db445aca-7b0a-4fbd-b378-8f81807219e8","children":[]},"1792cc95-23bc-4475-8a0a-5349fa6ea252":{"parent":"db445aca-7b0a-4fbd-b378-8f81807219e8","children":[]},"23b4d867-eb11-4139-958c-db9fba067b6b":{"parent":"db445aca-7b0a-4fbd-b378-8f81807219e8","children":[]},"480921e8-42bb-45b3-a743-dc9866e1335b":{"parent":"db445aca-7b0a-4fbd-b378-8f81807219e8","children":[]},"db445aca-7b0a-4fbd-b378-8f81807219e8":{"parent":null,"children":["0a7e2ebb-5cd8-42e1-8a75-1a844a599cb3","1792cc95-23bc-4475-8a0a-5349fa6ea252","23b4d867-eb11-4139-958c-db9fba067b6b","480921e8-42bb-45b3-a743-dc9866e1335b"]}},"files":{},"externalIds":{}}
|
|
Binary file
|
package/hugo-renderer/main.go
CHANGED
|
@@ -11,6 +11,8 @@ func main() {
|
|
|
11
11
|
c := make(chan struct{}, 0)
|
|
12
12
|
js.Global().Set("renderHugo", js.FuncOf(renderHugo))
|
|
13
13
|
js.Global().Set("loadHugoBookshopPartials", js.FuncOf(loadHugoBookshopPartials))
|
|
14
|
+
js.Global().Set("loadHugoBookshopData", js.FuncOf(loadHugoBookshopData))
|
|
15
|
+
js.Global().Set("loadHugoBookshopMeta", js.FuncOf(loadHugoBookshopMeta))
|
|
14
16
|
<-c
|
|
15
17
|
}
|
|
16
18
|
|
|
@@ -26,3 +28,15 @@ func loadHugoBookshopPartials(this js.Value, args []js.Value) interface{} {
|
|
|
26
28
|
|
|
27
29
|
return library.LoadHugoBookshopPartials(bookshopPartials)
|
|
28
30
|
}
|
|
31
|
+
|
|
32
|
+
func loadHugoBookshopData(this js.Value, args []js.Value) interface{} {
|
|
33
|
+
bookshopData := args[0].String()
|
|
34
|
+
|
|
35
|
+
return library.LoadHugoBookshopData(bookshopData)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
func loadHugoBookshopMeta(this js.Value, args []js.Value) interface{} {
|
|
39
|
+
bookshopMeta := args[0].String()
|
|
40
|
+
|
|
41
|
+
return library.LoadHugoBookshopMeta(bookshopMeta)
|
|
42
|
+
}
|
|
@@ -24,9 +24,10 @@ import (
|
|
|
24
24
|
_ "hugo-renderer/tpl/reflect"
|
|
25
25
|
|
|
26
26
|
// _ "hugo-renderer/tpl/resources" // ——————————— ⏭️ NTBI: Bookshop components won't support resources
|
|
27
|
-
_ "hugo-renderer/tpl/safe"
|
|
28
|
-
|
|
27
|
+
_ "hugo-renderer/tpl/safe" // ———————————————— 🥴 TODO: `SanitizeURL` NYI — helpers require is too large
|
|
28
|
+
_ "hugo-renderer/tpl/site" // ———————————————— 🥴 TODO: Partially stubbing out site variables. WIP
|
|
29
29
|
_ "hugo-renderer/tpl/strings" // ———————————————— 🥴 TODO: Only the "Go" title formatting is supported
|
|
30
|
+
|
|
30
31
|
// _ "hugo-renderer/tpl/templates" // ——————————— ❗ TODO: Maybe a rabbit hole
|
|
31
32
|
// _ "hugo-renderer/tpl/time" // ———————————————— ❗ TODO: This relies on lang stuff that is thus far excluded
|
|
32
33
|
_ "hugo-renderer/tpl/transform" // —————————————— 🥴 TODO: Highlight, unmarshal, commonmark compat
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
package bookshop_library
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"bytes"
|
|
5
|
+
"encoding/json"
|
|
6
|
+
"fmt"
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
type bookshopData struct {
|
|
10
|
+
Data map[string]interface{} `json:"data"`
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
var bookshopDataStorage bookshopData
|
|
14
|
+
|
|
15
|
+
// loadHugoBookshopData takes any data that the @bookshop/hugo-engine
|
|
16
|
+
// was given from info.json and stashes it all away
|
|
17
|
+
// on this side of the wasm boundary, for the site
|
|
18
|
+
// function to use.
|
|
19
|
+
func LoadHugoBookshopData(data string) interface{} {
|
|
20
|
+
err := json.Unmarshal([]byte(data), &bookshopDataStorage)
|
|
21
|
+
if err != nil {
|
|
22
|
+
buf := bytes.NewBufferString(fmt.Sprintf("bad json unmarshal: %s", err.Error()))
|
|
23
|
+
return buf.String()
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
buf := bytes.NewBufferString("loaded Bookshop site data")
|
|
27
|
+
return buf.String()
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
func RetrieveHugoBookshopData() *bookshopData {
|
|
31
|
+
return &bookshopDataStorage
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
var bookshopMetaStorage map[string]interface{}
|
|
35
|
+
|
|
36
|
+
// loadHugoBookshopMeta takes any data that hugo/bookshop
|
|
37
|
+
// injected into the template and stashes it all away
|
|
38
|
+
// on this side of the wasm boundary, for the site
|
|
39
|
+
// function to use.
|
|
40
|
+
func LoadHugoBookshopMeta(data string) interface{} {
|
|
41
|
+
err := json.Unmarshal([]byte(data), &bookshopMetaStorage)
|
|
42
|
+
if err != nil {
|
|
43
|
+
buf := bytes.NewBufferString(fmt.Sprintf("bad json unmarshal: %s", err.Error()))
|
|
44
|
+
return buf.String()
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
buf := bytes.NewBufferString("loaded Bookshop site data")
|
|
48
|
+
return buf.String()
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
func RetrieveHugoBookshopMeta() map[string]interface{} {
|
|
52
|
+
return bookshopMetaStorage
|
|
53
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// Copyright 2017 The Hugo Authors. All rights reserved.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
|
|
14
|
+
// Package site stubs out some of the Hugo site functions for use in Bookshop live editing.
|
|
15
|
+
package site
|
|
16
|
+
|
|
17
|
+
import (
|
|
18
|
+
"hugo-renderer/deps"
|
|
19
|
+
library "hugo-renderer/tpl/bookshop_library"
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
func New(deps *deps.Deps) *Namespace {
|
|
23
|
+
return &Namespace{
|
|
24
|
+
deps: deps,
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
type Namespace struct {
|
|
29
|
+
deps *deps.Deps
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Data returns any data that was present in the _cloudcannon/info.json
|
|
33
|
+
// This will require `data_config: true` in the site cloudcannon.config.yml
|
|
34
|
+
func (ns *Namespace) Data() (map[string]interface{}, error) {
|
|
35
|
+
data := library.RetrieveHugoBookshopData()
|
|
36
|
+
|
|
37
|
+
return data.Data, nil
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// site.Title should have been stashed inside a Bookshop meta comment
|
|
41
|
+
func (ns *Namespace) Title() (interface{}, error) {
|
|
42
|
+
meta := library.RetrieveHugoBookshopMeta()
|
|
43
|
+
|
|
44
|
+
return meta["title"], nil
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// site.Copyright should have been stashed inside a Bookshop meta comment
|
|
48
|
+
func (ns *Namespace) Copyright() (interface{}, error) {
|
|
49
|
+
meta := library.RetrieveHugoBookshopMeta()
|
|
50
|
+
|
|
51
|
+
return meta["copyright"], nil
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// site.BaseURL should have been stashed inside a Bookshop meta comment
|
|
55
|
+
func (ns *Namespace) BaseURL() (interface{}, error) {
|
|
56
|
+
meta := library.RetrieveHugoBookshopMeta()
|
|
57
|
+
|
|
58
|
+
return meta["baseurl"], nil
|
|
59
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// Copyright 2017 The Hugo Authors. All rights reserved.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
|
|
14
|
+
package site
|
|
15
|
+
|
|
16
|
+
import (
|
|
17
|
+
"hugo-renderer/deps"
|
|
18
|
+
"hugo-renderer/tpl/internal"
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
const name = "site"
|
|
22
|
+
|
|
23
|
+
func init() {
|
|
24
|
+
f := func(d *deps.Deps) *internal.TemplateFuncsNamespace {
|
|
25
|
+
ctx := New(d)
|
|
26
|
+
|
|
27
|
+
ns := &internal.TemplateFuncsNamespace{
|
|
28
|
+
Name: name,
|
|
29
|
+
Context: func(args ...interface{}) (interface{}, error) { return ctx, nil },
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
ns.AddMethodMapping(ctx.Data,
|
|
33
|
+
[]string{},
|
|
34
|
+
[][2]string{},
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
return ns
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
internal.AddTemplateFuncsNamespace(f)
|
|
41
|
+
}
|
package/lib/engine.js
CHANGED
|
@@ -31,11 +31,12 @@ export class Engine {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
async initializeHugo() {
|
|
34
|
+
const useLocalHugo = window.CloudCannon?.isMocked || /localhost|127\.0\.0\.1/i.test(window.location.host);
|
|
34
35
|
// When this script is run locally, the hugo wasm is loaded as binary rather than output as a file.
|
|
35
36
|
if (hugoWasm?.constructor === Uint8Array) {
|
|
36
37
|
await this.initializeInlineHugo();
|
|
37
38
|
} else {
|
|
38
|
-
if (
|
|
39
|
+
if (useLocalHugo) {
|
|
39
40
|
await this.initializeLocalHugo();
|
|
40
41
|
} else {
|
|
41
42
|
await this.initializeRemoteHugo();
|
|
@@ -73,7 +74,7 @@ export class Engine {
|
|
|
73
74
|
|
|
74
75
|
async initializeLocalHugo() {
|
|
75
76
|
const go = new Go();
|
|
76
|
-
const wasmOrigin = this.origin.replace(/\/[^\.\/]+\.js
|
|
77
|
+
const wasmOrigin = this.origin.replace(/\/[^\.\/]+\.js/, hugoWasm.replace(/^\./, ''));
|
|
77
78
|
const response = await fetch(wasmOrigin);
|
|
78
79
|
const buffer = await response.arrayBuffer();
|
|
79
80
|
const result = await WebAssembly.instantiate(buffer, go.importObject);
|
|
@@ -119,8 +120,25 @@ export class Engine {
|
|
|
119
120
|
};
|
|
120
121
|
}
|
|
121
122
|
|
|
122
|
-
async
|
|
123
|
-
while (!window.
|
|
123
|
+
async storeMeta(meta = {}) {
|
|
124
|
+
while (!window.loadHugoBookshopMeta) {
|
|
125
|
+
await sleep(100);
|
|
126
|
+
};
|
|
127
|
+
window.loadHugoBookshopMeta(JSON.stringify(meta));
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
async storeInfo(info = {}) {
|
|
131
|
+
while (!window.loadHugoBookshopData) {
|
|
132
|
+
await sleep(100);
|
|
133
|
+
};
|
|
134
|
+
window.loadHugoBookshopData(JSON.stringify(info));
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
async render(target, name, props, globals, logger) {
|
|
138
|
+
while (!window.renderHugo) {
|
|
139
|
+
logger?.log?.(`Waiting for the Hugo WASM to be available...`);
|
|
140
|
+
await sleep(100);
|
|
141
|
+
};
|
|
124
142
|
|
|
125
143
|
let source = this.getComponent(name);
|
|
126
144
|
// TODO: Remove the below check and update the live comments to denote shared
|
|
@@ -129,8 +147,10 @@ export class Engine {
|
|
|
129
147
|
console.warn(`[hugo-engine] No component found for ${name}`);
|
|
130
148
|
return "";
|
|
131
149
|
}
|
|
150
|
+
logger?.log?.(`Going to render ${name}`);
|
|
132
151
|
// TODO: this template already exists on the other side of the wasm bounary
|
|
133
152
|
source = translateTextTemplate(source, {});
|
|
153
|
+
logger?.log?.(`Rewritten the template for ${name}`);
|
|
134
154
|
if (!globals || typeof globals !== "object") globals = {};
|
|
135
155
|
props = { ...globals, ...props };
|
|
136
156
|
|
|
@@ -138,8 +158,10 @@ export class Engine {
|
|
|
138
158
|
if (props["."]) props = props["."];
|
|
139
159
|
const output = window.renderHugo(source, JSON.stringify(props));
|
|
140
160
|
if (/BKSHERR/.test(output)) {
|
|
161
|
+
logger?.log?.(`Failed to render ${output}`);
|
|
141
162
|
console.error(output);
|
|
142
163
|
} else {
|
|
164
|
+
logger?.log?.(`Rendered ${name}`);
|
|
143
165
|
target.innerHTML = output;
|
|
144
166
|
}
|
|
145
167
|
}
|
|
@@ -59,9 +59,12 @@ const rewriteTag = function (token, src, endTags, liveMarkup) {
|
|
|
59
59
|
} else if (liveMarkup && TOKENS.LOOP.test(raw)) {
|
|
60
60
|
let [, iterator] = raw.match(TOKENS.LOOP);
|
|
61
61
|
const r = required_wrapper_hugo_func(iterator);
|
|
62
|
-
outputToken.text = [`{{ $
|
|
62
|
+
outputToken.text = [`{{ $bookshop__live__iterator__keys := (slice) }}`,
|
|
63
|
+
`{{ range $i, $e := (${tidy(iterator)}) }}{{ $bookshop__live__iterator__keys = $bookshop__live__iterator__keys | append $i }}{{ end }}`,
|
|
64
|
+
`{{ $bookshop__live__iterator := 0 }}`,
|
|
63
65
|
`${outputToken.text}`,
|
|
64
|
-
`{{$
|
|
66
|
+
`{{ $bookshop__live__iterator__key := (index ($bookshop__live__iterator__keys) $bookshop__live__iterator) }}`,
|
|
67
|
+
`{{${r[0]} (printf \`<!--bookshop-live context(.: (index (${tidy(iterator)}) %v))-->\` (jsonify $bookshop__live__iterator__key))${r[1]} | safeHTML }}`,
|
|
65
68
|
`{{ $bookshop__live__iterator = (add $bookshop__live__iterator 1) }}`
|
|
66
69
|
].join('')
|
|
67
70
|
} else if (liveMarkup && TOKENS.ASSIGN.test(raw)) {
|
|
@@ -56,10 +56,13 @@ test("add live markup to withs", t => {
|
|
|
56
56
|
|
|
57
57
|
test("add live markup to loops", t => {
|
|
58
58
|
const input = `{{ range .items }}<p>{{ . }}</p>{{ end }}`;
|
|
59
|
-
const expected = [`{{ $
|
|
59
|
+
const expected = [`{{ $bookshop__live__iterator__keys := (slice) }}`,
|
|
60
|
+
`{{ range $i, $e := (.items) }}{{ $bookshop__live__iterator__keys = $bookshop__live__iterator__keys | append $i }}{{ end }}`,
|
|
61
|
+
`{{ $bookshop__live__iterator := 0 }}`,
|
|
60
62
|
`{{ range .items }}`,
|
|
61
63
|
`{{ \`<!--bookshop-live stack-->\` | safeHTML }}`,
|
|
62
|
-
`{{
|
|
64
|
+
`{{ $bookshop__live__iterator__key := (index ($bookshop__live__iterator__keys) $bookshop__live__iterator) }}`,
|
|
65
|
+
`{{ (printf \`<!--bookshop-live context(.: (index (.items) %v))-->\` (jsonify $bookshop__live__iterator__key)) | safeHTML }}`,
|
|
63
66
|
`{{ $bookshop__live__iterator = (add $bookshop__live__iterator 1) }}`,
|
|
64
67
|
`<p>{{ . }}</p>`,
|
|
65
68
|
`{{ \`<!--bookshop-live unstack-->\` | safeHTML }}`,
|
|
@@ -104,7 +107,7 @@ test("add live markup to complex end structures", t => {
|
|
|
104
107
|
|
|
105
108
|
{{ end }}`;
|
|
106
109
|
const expected = `
|
|
107
|
-
{{ $bookshop__live__iterator := 0 }}{{ range .items }}{{ \`<!--bookshop-live stack-->\` | safeHTML }}{{ (printf \`<!--bookshop-live context(.: (index (.items) %
|
|
110
|
+
{{ $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) }}
|
|
108
111
|
|
|
109
112
|
{{with .text}}{{ \`<!--bookshop-live stack-->\` | safeHTML }}{{ \`<!--bookshop-live context(.: (.text))-->\` | safeHTML }}
|
|
110
113
|
<p>{{ . }}</p>
|
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": "
|
|
4
|
+
"version": "3.0.0-beta.0",
|
|
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": "
|
|
32
|
+
"@bookshop/helpers": "3.0.0-beta.0",
|
|
33
33
|
"esbuild": "^0.13.10",
|
|
34
34
|
"liquidjs": "9.28.0"
|
|
35
35
|
},
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"parent":null,"pid":32139,"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":1646349108851,"ppid":32138,"coverageFilename":"/Users/liambigelow/Projects/CC/bookshop/javascript-modules/engines/hugo-engine/.nyc_output/ac095d2d-5d4a-449e-82ae-0e0f0dd32b01.json","externalId":"","uuid":"ac095d2d-5d4a-449e-82ae-0e0f0dd32b01","files":[]}
|