@bookshop/hugo-engine 2.4.2 → 2.5.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/{05c20625-d974-4cff-8627-ffd39eb87964.json → 3912b392-2912-48cc-9cca-bf322bf0d4e6.json} +0 -0
- package/.nyc_output/{1c8dd4f5-9b2f-4218-9c39-615aa7a79f1a.json → 73434d66-94ab-46e8-a516-e2fb6d961625.json} +0 -0
- package/.nyc_output/{55d11bd3-216d-42c2-970e-55360a3aa1f7.json → 81517a6e-3da5-4c5a-85fb-c3782bc44a31.json} +0 -0
- package/.nyc_output/{bb3f1e57-7efe-4f35-852c-6971836aa288.json → 90c0d905-7a53-48a0-9c22-a39b1b831857.json} +0 -0
- package/.nyc_output/{e6440686-4e4c-487d-9abc-bb15eb8663e1.json → c8f28bb3-0364-45d6-858b-7fe760a39c33.json} +0 -0
- package/.nyc_output/processinfo/{1c8dd4f5-9b2f-4218-9c39-615aa7a79f1a.json → 3912b392-2912-48cc-9cca-bf322bf0d4e6.json} +1 -1
- package/.nyc_output/processinfo/{55d11bd3-216d-42c2-970e-55360a3aa1f7.json → 73434d66-94ab-46e8-a516-e2fb6d961625.json} +1 -1
- package/.nyc_output/processinfo/{bb3f1e57-7efe-4f35-852c-6971836aa288.json → 81517a6e-3da5-4c5a-85fb-c3782bc44a31.json} +1 -1
- package/.nyc_output/processinfo/90c0d905-7a53-48a0-9c22-a39b1b831857.json +1 -0
- package/.nyc_output/processinfo/{e6440686-4e4c-487d-9abc-bb15eb8663e1.json → c8f28bb3-0364-45d6-858b-7fe760a39c33.json} +1 -1
- package/.nyc_output/processinfo/index.json +1 -1
- package/hugo-renderer/helpers/bookshop_modified_content.go +28 -0
- package/hugo-renderer/hugo_renderer.wasm +0 -0
- package/hugo-renderer/tpl/transform/transform.go +3 -0
- package/lib/builder.js +2 -2
- package/lib/engine.js +15 -3
- package/package.json +2 -2
- package/.nyc_output/processinfo/05c20625-d974-4cff-8627-ffd39eb87964.json +0 -1
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"parent":"
|
|
1
|
+
{"parent":"90c0d905-7a53-48a0-9c22-a39b1b831857","pid":36200,"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":1645506759846,"ppid":36197,"coverageFilename":"/Users/liambigelow/Projects/CC/bookshop/javascript-modules/engines/hugo-engine/.nyc_output/3912b392-2912-48cc-9cca-bf322bf0d4e6.json","externalId":"","uuid":"3912b392-2912-48cc-9cca-bf322bf0d4e6","files":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"parent":"
|
|
1
|
+
{"parent":"90c0d905-7a53-48a0-9c22-a39b1b831857","pid":36198,"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":1645506759839,"ppid":36197,"coverageFilename":"/Users/liambigelow/Projects/CC/bookshop/javascript-modules/engines/hugo-engine/.nyc_output/73434d66-94ab-46e8-a516-e2fb6d961625.json","externalId":"","uuid":"73434d66-94ab-46e8-a516-e2fb6d961625","files":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"parent":"
|
|
1
|
+
{"parent":"90c0d905-7a53-48a0-9c22-a39b1b831857","pid":36201,"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":1645506759852,"ppid":36197,"coverageFilename":"/Users/liambigelow/Projects/CC/bookshop/javascript-modules/engines/hugo-engine/.nyc_output/81517a6e-3da5-4c5a-85fb-c3782bc44a31.json","externalId":"","uuid":"81517a6e-3da5-4c5a-85fb-c3782bc44a31","files":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"parent":null,"pid":36197,"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":1645506759370,"ppid":36196,"coverageFilename":"/Users/liambigelow/Projects/CC/bookshop/javascript-modules/engines/hugo-engine/.nyc_output/90c0d905-7a53-48a0-9c22-a39b1b831857.json","externalId":"","uuid":"90c0d905-7a53-48a0-9c22-a39b1b831857","files":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"parent":"
|
|
1
|
+
{"parent":"90c0d905-7a53-48a0-9c22-a39b1b831857","pid":36199,"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":1645506759846,"ppid":36197,"coverageFilename":"/Users/liambigelow/Projects/CC/bookshop/javascript-modules/engines/hugo-engine/.nyc_output/c8f28bb3-0364-45d6-858b-7fe760a39c33.json","externalId":"","uuid":"c8f28bb3-0364-45d6-858b-7fe760a39c33","files":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"processes":{"
|
|
1
|
+
{"processes":{"3912b392-2912-48cc-9cca-bf322bf0d4e6":{"parent":"90c0d905-7a53-48a0-9c22-a39b1b831857","children":[]},"73434d66-94ab-46e8-a516-e2fb6d961625":{"parent":"90c0d905-7a53-48a0-9c22-a39b1b831857","children":[]},"81517a6e-3da5-4c5a-85fb-c3782bc44a31":{"parent":"90c0d905-7a53-48a0-9c22-a39b1b831857","children":[]},"90c0d905-7a53-48a0-9c22-a39b1b831857":{"parent":null,"children":["3912b392-2912-48cc-9cca-bf322bf0d4e6","73434d66-94ab-46e8-a516-e2fb6d961625","81517a6e-3da5-4c5a-85fb-c3782bc44a31","c8f28bb3-0364-45d6-858b-7fe760a39c33"]},"c8f28bb3-0364-45d6-858b-7fe760a39c33":{"parent":"90c0d905-7a53-48a0-9c22-a39b1b831857","children":[]}},"files":{},"externalIds":{}}
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
package helpers
|
|
19
19
|
|
|
20
20
|
import (
|
|
21
|
+
"bytes"
|
|
21
22
|
"html/template"
|
|
22
23
|
"strings"
|
|
23
24
|
"unicode"
|
|
@@ -25,6 +26,13 @@ import (
|
|
|
25
26
|
bp "github.com/gohugoio/hugo/bufferpool"
|
|
26
27
|
)
|
|
27
28
|
|
|
29
|
+
var (
|
|
30
|
+
openingPTag = []byte("<p>")
|
|
31
|
+
closingPTag = []byte("</p>")
|
|
32
|
+
paragraphIndicator = []byte("<p")
|
|
33
|
+
closingIndicator = []byte("</")
|
|
34
|
+
)
|
|
35
|
+
|
|
28
36
|
var stripHTMLReplacer = strings.NewReplacer("\n", " ", "</p>", "\n", "<br>", "\n", "<br />", "\n")
|
|
29
37
|
|
|
30
38
|
// StripHTML accepts a string, strips out all HTML tags and returns it.
|
|
@@ -68,3 +76,23 @@ func StripHTML(s string) string {
|
|
|
68
76
|
func BytesToHTML(b []byte) template.HTML {
|
|
69
77
|
return template.HTML(string(b))
|
|
70
78
|
}
|
|
79
|
+
|
|
80
|
+
// TrimShortHTML removes the <p>/</p> tags from HTML input in the situation
|
|
81
|
+
// where said tags are the only <p> tags in the input and enclose the content
|
|
82
|
+
// of the input (whitespace excluded).
|
|
83
|
+
// Bookshop: Changed this to _not_ be a method of *ContentSpec
|
|
84
|
+
func TrimShortHTML(input []byte) []byte {
|
|
85
|
+
firstOpeningP := bytes.Index(input, paragraphIndicator)
|
|
86
|
+
lastOpeningP := bytes.LastIndex(input, paragraphIndicator)
|
|
87
|
+
|
|
88
|
+
lastClosingP := bytes.LastIndex(input, closingPTag)
|
|
89
|
+
lastClosing := bytes.LastIndex(input, closingIndicator)
|
|
90
|
+
|
|
91
|
+
if firstOpeningP == lastOpeningP && lastClosingP == lastClosing {
|
|
92
|
+
input = bytes.TrimSpace(input)
|
|
93
|
+
input = bytes.TrimPrefix(input, openingPTag)
|
|
94
|
+
input = bytes.TrimSuffix(input, closingPTag)
|
|
95
|
+
input = bytes.TrimSpace(input)
|
|
96
|
+
}
|
|
97
|
+
return input
|
|
98
|
+
}
|
|
Binary file
|
|
@@ -99,6 +99,9 @@ func (ns *Namespace) Markdownify(s interface{}) (template.HTML, error) {
|
|
|
99
99
|
// This includes using a different (smaller) markdown implementation.
|
|
100
100
|
output := markdown.ToHTML([]byte(ss), nil, nil)
|
|
101
101
|
|
|
102
|
+
// Strip if this is a short inline type of text.
|
|
103
|
+
output = helpers.TrimShortHTML(output)
|
|
104
|
+
|
|
102
105
|
return helpers.BytesToHTML(output), nil
|
|
103
106
|
}
|
|
104
107
|
|
package/lib/builder.js
CHANGED
|
@@ -6,11 +6,11 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
|
6
6
|
|
|
7
7
|
export const extensions = [".hugo.html"];
|
|
8
8
|
|
|
9
|
-
export const esbuildConfigFn = (esbuildConfig) => {
|
|
9
|
+
export const esbuildConfigFn = (esbuildConfig, options) => {
|
|
10
10
|
esbuildConfig.loader = {
|
|
11
11
|
...esbuildConfig.loader,
|
|
12
12
|
".hugo.html": "text",
|
|
13
|
-
".wasm": "file"
|
|
13
|
+
".wasm": options?.hosted ? "file" : "binary"
|
|
14
14
|
};
|
|
15
15
|
|
|
16
16
|
const wasm_exec_banner = fs.readFileSync(path.join(__dirname, "../hugo-renderer/wasm_exec.js"));
|
package/lib/engine.js
CHANGED
|
@@ -31,10 +31,15 @@ export class Engine {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
async initializeHugo() {
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
// When this script is run locally, the hugo wasm is loaded as binary rather than output as a file.
|
|
35
|
+
if (hugoWasm?.constructor === Uint8Array) {
|
|
36
|
+
await this.initializeInlineHugo();
|
|
36
37
|
} else {
|
|
37
|
-
|
|
38
|
+
if (window.CloudCannon?.isMocked) {
|
|
39
|
+
await this.initializeLocalHugo();
|
|
40
|
+
} else {
|
|
41
|
+
await this.initializeRemoteHugo();
|
|
42
|
+
}
|
|
38
43
|
}
|
|
39
44
|
|
|
40
45
|
// TODO: Tidy
|
|
@@ -75,6 +80,13 @@ export class Engine {
|
|
|
75
80
|
go.run(result.instance);
|
|
76
81
|
}
|
|
77
82
|
|
|
83
|
+
async initializeInlineHugo() {
|
|
84
|
+
const go = new Go();
|
|
85
|
+
const buffer = hugoWasm.buffer;
|
|
86
|
+
const result = await WebAssembly.instantiate(buffer, go.importObject);
|
|
87
|
+
go.run(result.instance);
|
|
88
|
+
}
|
|
89
|
+
|
|
78
90
|
getShared(name) {
|
|
79
91
|
const key = `shared/hugo/${name}.hugo.html`
|
|
80
92
|
return this.files?.[key];
|
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
|
+
"version": "2.5.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": "2.
|
|
32
|
+
"@bookshop/helpers": "2.5.0",
|
|
33
33
|
"esbuild": "^0.13.10",
|
|
34
34
|
"liquidjs": "9.28.0"
|
|
35
35
|
},
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"parent":null,"pid":94690,"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":1643783907226,"ppid":94689,"coverageFilename":"/Users/liambigelow/Projects/CC/bookshop/javascript-modules/engines/hugo-engine/.nyc_output/05c20625-d974-4cff-8627-ffd39eb87964.json","externalId":"","uuid":"05c20625-d974-4cff-8627-ffd39eb87964","files":[]}
|