@bookshop/hugo-engine 3.3.2 → 3.4.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/.nyc_output/{396c364e-fec4-4f27-9ff2-8b236061ef8f.json → 0f70a16f-6a79-48c7-8b16-3b4665e247b2.json} +0 -0
- package/.nyc_output/{4ef43740-059b-4329-96cd-0643fd8fe8d8.json → 6285d5fa-be3d-49e4-8f2f-82157d95dcd8.json} +0 -0
- package/.nyc_output/{656275f4-66d6-4d27-bfab-c2f7a3087670.json → 8b5e1314-6e86-4197-a3ae-3c40e4c2f39e.json} +0 -0
- package/.nyc_output/{6aec5420-0b83-4260-b300-4d595dfd0660.json → c5490eb0-70c0-468f-a43f-e58c75dd34c8.json} +0 -0
- package/.nyc_output/{874bd79b-45da-4726-9afc-1f6cab44be1f.json → ee1a9bec-d318-4aea-af93-7269debcf6df.json} +0 -0
- package/.nyc_output/processinfo/{396c364e-fec4-4f27-9ff2-8b236061ef8f.json → 0f70a16f-6a79-48c7-8b16-3b4665e247b2.json} +1 -1
- package/.nyc_output/processinfo/6285d5fa-be3d-49e4-8f2f-82157d95dcd8.json +1 -0
- package/.nyc_output/processinfo/{4ef43740-059b-4329-96cd-0643fd8fe8d8.json → 8b5e1314-6e86-4197-a3ae-3c40e4c2f39e.json} +1 -1
- package/.nyc_output/processinfo/{656275f4-66d6-4d27-bfab-c2f7a3087670.json → c5490eb0-70c0-468f-a43f-e58c75dd34c8.json} +1 -1
- package/.nyc_output/processinfo/{874bd79b-45da-4726-9afc-1f6cab44be1f.json → ee1a9bec-d318-4aea-af93-7269debcf6df.json} +1 -1
- package/.nyc_output/processinfo/index.json +1 -1
- package/bookshop-hugo-templates/bookshop.html +56 -0
- package/bookshop-hugo-templates/bookshop_bindings.html +29 -0
- package/bookshop-hugo-templates/bookshop_component_browser.html +30 -0
- package/bookshop-hugo-templates/bookshop_partial.html +42 -0
- package/bookshop-hugo-templates/bookshop_scss.html +9 -0
- package/bookshop-hugo-templates/errors/bad_bookshop_tag.html +39 -0
- package/bookshop-hugo-templates/errors/err.html +6 -0
- package/bookshop-hugo-templates/helpers/component.html +25 -0
- package/bookshop-hugo-templates/helpers/component_key.html +11 -0
- package/bookshop-hugo-templates/helpers/partial.html +25 -0
- package/bookshop-hugo-templates/helpers/partial_key.html +9 -0
- package/full-hugo-renderer/build.sh +34 -0
- package/full-hugo-renderer/go.mod +87 -0
- package/{hugo-renderer → full-hugo-renderer}/go.sum +204 -12
- package/full-hugo-renderer/hugo_renderer.wasm +0 -0
- package/full-hugo-renderer/hugo_renderer.wasm.gz +0 -0
- package/full-hugo-renderer/main.go +215 -0
- package/{hugo-renderer → full-hugo-renderer}/wasm_exec.js +6 -2
- package/lib/builder.js +2 -2
- package/lib/engine.js +109 -42
- package/lib/hugoIdentifierParser.js +5 -0
- package/lib/translateTextTemplate.js +3 -0
- package/lib/translateTextTemplate.test.js +22 -16
- package/package.json +4 -4
- package/.nyc_output/processinfo/6aec5420-0b83-4260-b300-4d595dfd0660.json +0 -1
- package/hugo-renderer/build.sh +0 -66
- package/hugo-renderer/deps/bookshop_modified_deps.go +0 -6
- package/hugo-renderer/go.mod +0 -19
- package/hugo-renderer/helpers/bookshop_modified_content.go +0 -98
- package/hugo-renderer/helpers/bookshop_modified_general.go +0 -33
- package/hugo-renderer/helpers/emoji.go +0 -96
- package/hugo-renderer/hugo_renderer.wasm +0 -0
- package/hugo-renderer/hugo_renderer.wasm.gz +0 -0
- package/hugo-renderer/main.go +0 -42
- package/hugo-renderer/tpl/bookshop_engine/bookshop_func_importer.go +0 -35
- package/hugo-renderer/tpl/bookshop_engine/bookshop_render.go +0 -64
- package/hugo-renderer/tpl/bookshop_library/bookshop_components.go +0 -129
- package/hugo-renderer/tpl/bookshop_library/bookshop_data.go +0 -53
- package/hugo-renderer/tpl/cast/cast.go +0 -63
- package/hugo-renderer/tpl/cast/init.go +0 -57
- package/hugo-renderer/tpl/collections/append.go +0 -37
- package/hugo-renderer/tpl/collections/apply.go +0 -131
- package/hugo-renderer/tpl/collections/collections.go +0 -768
- package/hugo-renderer/tpl/collections/complement.go +0 -55
- package/hugo-renderer/tpl/collections/index.go +0 -133
- package/hugo-renderer/tpl/collections/init.go +0 -214
- package/hugo-renderer/tpl/collections/merge.go +0 -126
- package/hugo-renderer/tpl/collections/reflect_helpers.go +0 -216
- package/hugo-renderer/tpl/collections/sort.go +0 -183
- package/hugo-renderer/tpl/collections/symdiff.go +0 -68
- package/hugo-renderer/tpl/collections/where.go +0 -517
- package/hugo-renderer/tpl/compare/compare.go +0 -324
- package/hugo-renderer/tpl/compare/init.go +0 -85
- package/hugo-renderer/tpl/crypto/crypto.go +0 -109
- package/hugo-renderer/tpl/crypto/init.go +0 -65
- package/hugo-renderer/tpl/debug/debug.go +0 -40
- package/hugo-renderer/tpl/debug/init.go +0 -45
- package/hugo-renderer/tpl/encoding/encoding.go +0 -90
- package/hugo-renderer/tpl/encoding/init.go +0 -59
- package/hugo-renderer/tpl/fmt/fmt.go +0 -66
- package/hugo-renderer/tpl/fmt/init.go +0 -77
- package/hugo-renderer/tpl/inflect/inflect.go +0 -79
- package/hugo-renderer/tpl/inflect/init.go +0 -60
- package/hugo-renderer/tpl/internal/bookshop_modified_templatefuncsRegistry.go +0 -88
- package/hugo-renderer/tpl/math/init.go +0 -134
- package/hugo-renderer/tpl/math/math.go +0 -164
- package/hugo-renderer/tpl/math/round.go +0 -61
- package/hugo-renderer/tpl/partials/init.go +0 -55
- package/hugo-renderer/tpl/partials/partials.go +0 -88
- package/hugo-renderer/tpl/path/init.go +0 -60
- package/hugo-renderer/tpl/path/path.go +0 -159
- package/hugo-renderer/tpl/reflect/init.go +0 -51
- package/hugo-renderer/tpl/reflect/reflect.go +0 -36
- package/hugo-renderer/tpl/safe/init.go +0 -80
- package/hugo-renderer/tpl/safe/safe.go +0 -72
- package/hugo-renderer/tpl/site/bookshop_site.go +0 -67
- package/hugo-renderer/tpl/site/init.go +0 -41
- package/hugo-renderer/tpl/strings/init.go +0 -229
- package/hugo-renderer/tpl/strings/regexp.go +0 -125
- package/hugo-renderer/tpl/strings/strings.go +0 -500
- package/hugo-renderer/tpl/strings/truncate.go +0 -157
- package/hugo-renderer/tpl/transform/bookshop_unmarshal.go +0 -39
- package/hugo-renderer/tpl/transform/init.go +0 -113
- package/hugo-renderer/tpl/transform/transform.go +0 -116
- package/hugo-renderer/update-from-hugo.sh +0 -19
package/hugo-renderer/build.sh
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
|
|
3
|
-
TMPFILENAME="hugo_renderer_$(date +%s).wasm"
|
|
4
|
-
OUTPUTFILENAME="hugo_renderer.wasm"
|
|
5
|
-
|
|
6
|
-
# Clean
|
|
7
|
-
rm -f $OUTPUTFILENAME
|
|
8
|
-
if [ -f $OUTPUTFILENAME ]; then
|
|
9
|
-
echo "ERROR: previous $OUTPUTFILENAME still in directory"
|
|
10
|
-
exit 1
|
|
11
|
-
fi
|
|
12
|
-
|
|
13
|
-
# Build temp module (For Windows use `$Env:GOOS = "js"; $Env:GOARCH = "wasm"` )
|
|
14
|
-
GOOS=js GOARCH=wasm go build -tags nodeploy -o $TMPFILENAME
|
|
15
|
-
printf "Built Hugo WASM via $TMPFILENAME : "
|
|
16
|
-
ls -lh $TMPFILENAME | awk '{print $5}'
|
|
17
|
-
|
|
18
|
-
# Link repo module
|
|
19
|
-
mv $TMPFILENAME $OUTPUTFILENAME
|
|
20
|
-
if [ ! -f $OUTPUTFILENAME ]; then
|
|
21
|
-
echo "ERROR: hugo_renderer.wasm not complete"
|
|
22
|
-
exit 1
|
|
23
|
-
fi
|
|
24
|
-
echo "Done. Repo Hugo WASM available at hugo_renderer.wasm"
|
|
25
|
-
|
|
26
|
-
gzip --keep $OUTPUTFILENAME
|
|
27
|
-
echo "Repo Hugo WASM also available at hugo_renderer.wasm.gz"
|
|
28
|
-
|
|
29
|
-
# If we're just in a test run we don't want to touch the CDN repo
|
|
30
|
-
if [[ -z "${PUBLISH_BOOKSHOP_CDN}" ]]; then
|
|
31
|
-
echo "Not publishing to CDN."
|
|
32
|
-
exit 0
|
|
33
|
-
fi
|
|
34
|
-
|
|
35
|
-
if [[ -z "${BOOKSHOP_VERSION}" ]]; then
|
|
36
|
-
echo "ERROR: BOOKSHOP_VERSION environment variable does not exist"
|
|
37
|
-
exit 1
|
|
38
|
-
fi
|
|
39
|
-
|
|
40
|
-
CDNFILENAME="../../../../../bookshopcdn/hugo/hugo_renderer_$BOOKSHOP_VERSION.wasm"
|
|
41
|
-
|
|
42
|
-
# Check CDN
|
|
43
|
-
if [ ! -d ../../../../../bookshopcdn/hugo ]; then
|
|
44
|
-
echo "ERROR: bookshopcdn repo does not exist alongside bookshop repo"
|
|
45
|
-
exit 1
|
|
46
|
-
fi
|
|
47
|
-
|
|
48
|
-
# Link CDN module
|
|
49
|
-
cp $OUTPUTFILENAME $CDNFILENAME
|
|
50
|
-
if [ ! -f $CDNFILENAME ]; then
|
|
51
|
-
echo "ERROR: $CDNFILENAME not complete"
|
|
52
|
-
exit 1
|
|
53
|
-
fi
|
|
54
|
-
echo "Done. CDN Hugo WASM available at $CDNFILENAME"
|
|
55
|
-
|
|
56
|
-
gzip -k $CDNFILENAME
|
|
57
|
-
echo "Done. Compressed CDN Hugo WASM available at $CDNFILENAME.gz"
|
|
58
|
-
|
|
59
|
-
cd ../../../../../bookshopcdn
|
|
60
|
-
|
|
61
|
-
git add -A \
|
|
62
|
-
&& git commit -m "build: releasing $BOOKSHOP_VERSION" \
|
|
63
|
-
&& git tag -a v$BOOKSHOP_VERSION -m "build: releasing $BOOKSHOP_VERSION" \
|
|
64
|
-
&& git push --tags && git push
|
|
65
|
-
|
|
66
|
-
exit 0
|
package/hugo-renderer/go.mod
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
module hugo-renderer
|
|
2
|
-
|
|
3
|
-
go 1.17
|
|
4
|
-
|
|
5
|
-
require (
|
|
6
|
-
github.com/gohugoio/hugo v0.89.4
|
|
7
|
-
github.com/mitchellh/hashstructure v1.1.0
|
|
8
|
-
github.com/pkg/errors v0.9.1
|
|
9
|
-
github.com/spf13/cast v1.4.1
|
|
10
|
-
)
|
|
11
|
-
|
|
12
|
-
require (
|
|
13
|
-
github.com/gobuffalo/flect v0.2.4
|
|
14
|
-
github.com/gomarkdown/markdown v0.0.0-20220114203417-14399d5448c4
|
|
15
|
-
github.com/kyokomi/emoji/v2 v2.2.8
|
|
16
|
-
github.com/sanity-io/litter v1.5.1
|
|
17
|
-
)
|
|
18
|
-
|
|
19
|
-
require github.com/gobwas/glob v0.2.3 // indirect
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
// Copyright 2019 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 helpers implements general utility functions that work with
|
|
15
|
-
// and on content. The helper functions defined here lay down the
|
|
16
|
-
// foundation of how Hugo works with files and filepaths, and perform
|
|
17
|
-
// string operations on content.
|
|
18
|
-
package helpers
|
|
19
|
-
|
|
20
|
-
import (
|
|
21
|
-
"bytes"
|
|
22
|
-
"html/template"
|
|
23
|
-
"strings"
|
|
24
|
-
"unicode"
|
|
25
|
-
|
|
26
|
-
bp "github.com/gohugoio/hugo/bufferpool"
|
|
27
|
-
)
|
|
28
|
-
|
|
29
|
-
var (
|
|
30
|
-
openingPTag = []byte("<p>")
|
|
31
|
-
closingPTag = []byte("</p>")
|
|
32
|
-
paragraphIndicator = []byte("<p")
|
|
33
|
-
closingIndicator = []byte("</")
|
|
34
|
-
)
|
|
35
|
-
|
|
36
|
-
var stripHTMLReplacer = strings.NewReplacer("\n", " ", "</p>", "\n", "<br>", "\n", "<br />", "\n")
|
|
37
|
-
|
|
38
|
-
// StripHTML accepts a string, strips out all HTML tags and returns it.
|
|
39
|
-
func StripHTML(s string) string {
|
|
40
|
-
// Shortcut strings with no tags in them
|
|
41
|
-
if !strings.ContainsAny(s, "<>") {
|
|
42
|
-
return s
|
|
43
|
-
}
|
|
44
|
-
s = stripHTMLReplacer.Replace(s)
|
|
45
|
-
|
|
46
|
-
// Walk through the string removing all tags
|
|
47
|
-
b := bp.GetBuffer()
|
|
48
|
-
defer bp.PutBuffer(b)
|
|
49
|
-
var inTag, isSpace, wasSpace bool
|
|
50
|
-
for _, r := range s {
|
|
51
|
-
if !inTag {
|
|
52
|
-
isSpace = false
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
switch {
|
|
56
|
-
case r == '<':
|
|
57
|
-
inTag = true
|
|
58
|
-
case r == '>':
|
|
59
|
-
inTag = false
|
|
60
|
-
case unicode.IsSpace(r):
|
|
61
|
-
isSpace = true
|
|
62
|
-
fallthrough
|
|
63
|
-
default:
|
|
64
|
-
if !inTag && (!isSpace || (isSpace && !wasSpace)) {
|
|
65
|
-
b.WriteRune(r)
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
wasSpace = isSpace
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
return b.String()
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// BytesToHTML converts bytes to type template.HTML.
|
|
76
|
-
func BytesToHTML(b []byte) template.HTML {
|
|
77
|
-
return template.HTML(string(b))
|
|
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
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
// Copyright 2019 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 helpers
|
|
15
|
-
|
|
16
|
-
import (
|
|
17
|
-
"unicode"
|
|
18
|
-
"unicode/utf8"
|
|
19
|
-
)
|
|
20
|
-
|
|
21
|
-
// FirstUpper returns a string with the first character as upper case.
|
|
22
|
-
func FirstUpper(s string) string {
|
|
23
|
-
if s == "" {
|
|
24
|
-
return ""
|
|
25
|
-
}
|
|
26
|
-
r, n := utf8.DecodeRuneInString(s)
|
|
27
|
-
return string(unicode.ToUpper(r)) + s[n:]
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// IsWhitespace determines if the given rune is whitespace.
|
|
31
|
-
func IsWhitespace(r rune) bool {
|
|
32
|
-
return r == ' ' || r == '\t' || r == '\n' || r == '\r'
|
|
33
|
-
}
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
// Copyright 2016 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 helpers
|
|
15
|
-
|
|
16
|
-
import (
|
|
17
|
-
"bytes"
|
|
18
|
-
"sync"
|
|
19
|
-
|
|
20
|
-
"github.com/kyokomi/emoji/v2"
|
|
21
|
-
)
|
|
22
|
-
|
|
23
|
-
var (
|
|
24
|
-
emojiInit sync.Once
|
|
25
|
-
|
|
26
|
-
emojis = make(map[string][]byte)
|
|
27
|
-
|
|
28
|
-
emojiDelim = []byte(":")
|
|
29
|
-
emojiWordDelim = []byte(" ")
|
|
30
|
-
emojiMaxSize int
|
|
31
|
-
)
|
|
32
|
-
|
|
33
|
-
// Emoji returns the emojy given a key, e.g. ":smile:", nil if not found.
|
|
34
|
-
func Emoji(key string) []byte {
|
|
35
|
-
emojiInit.Do(initEmoji)
|
|
36
|
-
return emojis[key]
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// Emojify "emojifies" the input source.
|
|
40
|
-
// Note that the input byte slice will be modified if needed.
|
|
41
|
-
// See http://www.emoji-cheat-sheet.com/
|
|
42
|
-
func Emojify(source []byte) []byte {
|
|
43
|
-
emojiInit.Do(initEmoji)
|
|
44
|
-
|
|
45
|
-
start := 0
|
|
46
|
-
k := bytes.Index(source[start:], emojiDelim)
|
|
47
|
-
|
|
48
|
-
for k != -1 {
|
|
49
|
-
|
|
50
|
-
j := start + k
|
|
51
|
-
|
|
52
|
-
upper := j + emojiMaxSize
|
|
53
|
-
|
|
54
|
-
if upper > len(source) {
|
|
55
|
-
upper = len(source)
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
endEmoji := bytes.Index(source[j+1:upper], emojiDelim)
|
|
59
|
-
nextWordDelim := bytes.Index(source[j:upper], emojiWordDelim)
|
|
60
|
-
|
|
61
|
-
if endEmoji < 0 {
|
|
62
|
-
start++
|
|
63
|
-
} else if endEmoji == 0 || (nextWordDelim != -1 && nextWordDelim < endEmoji) {
|
|
64
|
-
start += endEmoji + 1
|
|
65
|
-
} else {
|
|
66
|
-
endKey := endEmoji + j + 2
|
|
67
|
-
emojiKey := source[j:endKey]
|
|
68
|
-
|
|
69
|
-
if emoji, ok := emojis[string(emojiKey)]; ok {
|
|
70
|
-
source = append(source[:j], append(emoji, source[endKey:]...)...)
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
start += endEmoji
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
if start >= len(source) {
|
|
77
|
-
break
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
k = bytes.Index(source[start:], emojiDelim)
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return source
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
func initEmoji() {
|
|
87
|
-
emojiMap := emoji.CodeMap()
|
|
88
|
-
|
|
89
|
-
for k, v := range emojiMap {
|
|
90
|
-
emojis[k] = []byte(v)
|
|
91
|
-
|
|
92
|
-
if len(k) > emojiMaxSize {
|
|
93
|
-
emojiMaxSize = len(k)
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
Binary file
|
|
Binary file
|
package/hugo-renderer/main.go
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
package main
|
|
2
|
-
|
|
3
|
-
import (
|
|
4
|
-
"syscall/js"
|
|
5
|
-
|
|
6
|
-
engine "hugo-renderer/tpl/bookshop_engine"
|
|
7
|
-
library "hugo-renderer/tpl/bookshop_library"
|
|
8
|
-
)
|
|
9
|
-
|
|
10
|
-
func main() {
|
|
11
|
-
c := make(chan struct{}, 0)
|
|
12
|
-
js.Global().Set("renderHugo", js.FuncOf(renderHugo))
|
|
13
|
-
js.Global().Set("loadHugoBookshopPartials", js.FuncOf(loadHugoBookshopPartials))
|
|
14
|
-
js.Global().Set("loadHugoBookshopData", js.FuncOf(loadHugoBookshopData))
|
|
15
|
-
js.Global().Set("loadHugoBookshopMeta", js.FuncOf(loadHugoBookshopMeta))
|
|
16
|
-
<-c
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
func renderHugo(this js.Value, args []js.Value) interface{} {
|
|
20
|
-
templateString := args[0].String()
|
|
21
|
-
propsString := args[1].String()
|
|
22
|
-
|
|
23
|
-
return engine.RenderHugo(templateString, propsString)
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
func loadHugoBookshopPartials(this js.Value, args []js.Value) interface{} {
|
|
27
|
-
bookshopPartials := args[0].String()
|
|
28
|
-
|
|
29
|
-
return library.LoadHugoBookshopPartials(bookshopPartials)
|
|
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
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
package engine
|
|
2
|
-
|
|
3
|
-
import (
|
|
4
|
-
_ "hugo-renderer/tpl/cast"
|
|
5
|
-
_ "hugo-renderer/tpl/collections" // ———————————— 🥴 TODO: `apply` NYI, relies on tpl.TemplateHandler & co. Reimplement based on bookshop_render -> createFuncMap
|
|
6
|
-
_ "hugo-renderer/tpl/compare"
|
|
7
|
-
_ "hugo-renderer/tpl/crypto"
|
|
8
|
-
|
|
9
|
-
// _ "hugo-renderer/tpl/data" // ———————————————— ⏭️ NTBI: Networking / FS / Resources
|
|
10
|
-
_ "hugo-renderer/tpl/debug"
|
|
11
|
-
_ "hugo-renderer/tpl/encoding"
|
|
12
|
-
_ "hugo-renderer/tpl/fmt"
|
|
13
|
-
|
|
14
|
-
// _ "hugo-renderer/tpl/hugo" // ———————————————— ❗ TODO: Should this be stubbed out ??
|
|
15
|
-
// _ "hugo-renderer/tpl/images" // —————————————— ❗ TODO: Should this be mocked ??
|
|
16
|
-
_ "hugo-renderer/tpl/inflect"
|
|
17
|
-
// _ "hugo-renderer/tpl/js" // —————————————————— ⏭️ NTBI: Shouldn't be done inside a component
|
|
18
|
-
// _ "hugo-renderer/tpl/lang" // ———————————————— ❗ TODO: Not sure how this would interact in the Bookshop environment
|
|
19
|
-
_ "hugo-renderer/tpl/math"
|
|
20
|
-
// _ "hugo-renderer/tpl/openapi/openapi3" // ———— ❗ TODO: Maybe a rabbit hole
|
|
21
|
-
// _ "hugo-renderer/tpl/os" // —————————————————— ⏭️ NTBI: We don't have an OS
|
|
22
|
-
_ "hugo-renderer/tpl/partials" // ——————————————— ❗ TODO: Return partials / use bookshop module partials
|
|
23
|
-
_ "hugo-renderer/tpl/path"
|
|
24
|
-
_ "hugo-renderer/tpl/reflect"
|
|
25
|
-
|
|
26
|
-
// _ "hugo-renderer/tpl/resources" // ——————————— ⏭️ NTBI: Bookshop components won't support resources
|
|
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
|
-
_ "hugo-renderer/tpl/strings" // ———————————————— 🥴 TODO: Only the "Go" title formatting is supported
|
|
30
|
-
|
|
31
|
-
// _ "hugo-renderer/tpl/templates" // ——————————— ❗ TODO: Maybe a rabbit hole
|
|
32
|
-
// _ "hugo-renderer/tpl/time" // ———————————————— ❗ TODO: This relies on lang stuff that is thus far excluded
|
|
33
|
-
_ "hugo-renderer/tpl/transform" // —————————————— 🥴 TODO: Highlight, unmarshal, commonmark compat
|
|
34
|
-
// _ "hugo-renderer/tpl/urls" // ———————————————— ❗ TODO: Relies on pathspec that relies on FS impls
|
|
35
|
-
)
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
package engine
|
|
2
|
-
|
|
3
|
-
import (
|
|
4
|
-
"bytes"
|
|
5
|
-
"encoding/json"
|
|
6
|
-
"fmt"
|
|
7
|
-
"html/template"
|
|
8
|
-
|
|
9
|
-
"hugo-renderer/deps"
|
|
10
|
-
"hugo-renderer/tpl/internal"
|
|
11
|
-
)
|
|
12
|
-
|
|
13
|
-
// TODO(bookshop): DRY
|
|
14
|
-
func createFuncMap(d *deps.Deps) map[string]interface{} {
|
|
15
|
-
funcMap := template.FuncMap{}
|
|
16
|
-
|
|
17
|
-
// Merge the namespace funcs
|
|
18
|
-
for _, nsf := range internal.TemplateFuncsNamespaceRegistry {
|
|
19
|
-
ns := nsf(d)
|
|
20
|
-
if _, exists := funcMap[ns.Name]; exists {
|
|
21
|
-
panic(ns.Name + " is a duplicate template func")
|
|
22
|
-
}
|
|
23
|
-
funcMap[ns.Name] = ns.Context
|
|
24
|
-
for _, mm := range ns.MethodMappings {
|
|
25
|
-
for _, alias := range mm.Aliases {
|
|
26
|
-
if _, exists := funcMap[alias]; exists {
|
|
27
|
-
panic(alias + " is a duplicate template func")
|
|
28
|
-
}
|
|
29
|
-
funcMap[alias] = mm.Method
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return funcMap
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// RenderHugo takes a component from the browser,
|
|
38
|
-
// as well as a JSON blob of its data,
|
|
39
|
-
// and renders it.
|
|
40
|
-
func RenderHugo(templateString string, props string) interface{} {
|
|
41
|
-
var parsedProps interface{}
|
|
42
|
-
err := json.Unmarshal([]byte(props), &parsedProps)
|
|
43
|
-
if err != nil {
|
|
44
|
-
buf := bytes.NewBufferString(fmt.Sprintf("BKSHERR: bad json unmarshal: %s", err.Error()))
|
|
45
|
-
return buf.String()
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
d := deps.Deps{}
|
|
49
|
-
funcMap := createFuncMap(&d)
|
|
50
|
-
|
|
51
|
-
templ, err := template.New("").Funcs(funcMap).Parse(templateString)
|
|
52
|
-
if err != nil {
|
|
53
|
-
buf := bytes.NewBufferString(fmt.Sprintf("BKSHERR: bad template parse: %s", err.Error()))
|
|
54
|
-
return buf.String()
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
buf := bytes.NewBufferString("")
|
|
58
|
-
err = templ.Execute(buf, parsedProps)
|
|
59
|
-
if err != nil {
|
|
60
|
-
buf := bytes.NewBufferString(fmt.Sprintf("BKSHERR: bad template render: %s", err.Error()))
|
|
61
|
-
return buf.String()
|
|
62
|
-
}
|
|
63
|
-
return buf.String()
|
|
64
|
-
}
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
package bookshop_library
|
|
2
|
-
|
|
3
|
-
import (
|
|
4
|
-
"bytes"
|
|
5
|
-
"encoding/json"
|
|
6
|
-
"fmt"
|
|
7
|
-
"html/template"
|
|
8
|
-
"strings"
|
|
9
|
-
|
|
10
|
-
"hugo-renderer/deps"
|
|
11
|
-
"hugo-renderer/tpl/internal"
|
|
12
|
-
)
|
|
13
|
-
|
|
14
|
-
// TODO(bookshop): DRY
|
|
15
|
-
func createFuncMap(d *deps.Deps) map[string]interface{} {
|
|
16
|
-
funcMap := template.FuncMap{}
|
|
17
|
-
|
|
18
|
-
// Merge the namespace funcs
|
|
19
|
-
for _, nsf := range internal.TemplateFuncsNamespaceRegistry {
|
|
20
|
-
ns := nsf(d)
|
|
21
|
-
if _, exists := funcMap[ns.Name]; exists {
|
|
22
|
-
panic(ns.Name + " is a duplicate template func")
|
|
23
|
-
}
|
|
24
|
-
funcMap[ns.Name] = ns.Context
|
|
25
|
-
for _, mm := range ns.MethodMappings {
|
|
26
|
-
for _, alias := range mm.Aliases {
|
|
27
|
-
if _, exists := funcMap[alias]; exists {
|
|
28
|
-
panic(alias + " is a duplicate template func")
|
|
29
|
-
}
|
|
30
|
-
funcMap[alias] = mm.Method
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return funcMap
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
type bookshopPartial struct {
|
|
39
|
-
Contents string `json:"contents"`
|
|
40
|
-
ParsedContents *template.Template
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
var componentLibrary map[string]bookshopPartial
|
|
44
|
-
|
|
45
|
-
// LoadHugoBookshopPartials takes all files that the
|
|
46
|
-
// @bookshop/hugo-engine was given and stashes them away
|
|
47
|
-
// on this side of the wasm boundary, for the partials
|
|
48
|
-
// function to use.
|
|
49
|
-
func LoadHugoBookshopPartials(partials string) interface{} {
|
|
50
|
-
err := json.Unmarshal([]byte(partials), &componentLibrary)
|
|
51
|
-
if err != nil {
|
|
52
|
-
buf := bytes.NewBufferString(fmt.Sprintf("bad json unmarshal: %s", err.Error()))
|
|
53
|
-
return buf.String()
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
buf := bytes.NewBufferString(fmt.Sprintf("loaded %d components", len(componentLibrary)))
|
|
57
|
-
return buf.String()
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// RetrieveBookshopPartial looks for a Bookshop file
|
|
61
|
-
// and returns its template in a standard lib go html/template.
|
|
62
|
-
// TODO(bookshop): This should probably one day play
|
|
63
|
-
// nicer with the Hugo templating packages.
|
|
64
|
-
func RetrieveBookshopPartial(bookshop_key string) (*template.Template, bool) {
|
|
65
|
-
if component, ok := componentLibrary[bookshop_key]; ok {
|
|
66
|
-
if component.ParsedContents == nil {
|
|
67
|
-
d := deps.Deps{}
|
|
68
|
-
funcMap := createFuncMap(&d)
|
|
69
|
-
templ, err := template.New("").Funcs(funcMap).Parse(component.Contents)
|
|
70
|
-
if err != nil {
|
|
71
|
-
return nil, false
|
|
72
|
-
}
|
|
73
|
-
component.ParsedContents = templ
|
|
74
|
-
}
|
|
75
|
-
return component.ParsedContents, true
|
|
76
|
-
}
|
|
77
|
-
return nil, false
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
func bookshopKey(full_key string) string {
|
|
81
|
-
split := strings.Split(full_key, "/")
|
|
82
|
-
base := split[len(split)-1]
|
|
83
|
-
return fmt.Sprintf("components/%s/%s.hugo.html", full_key, base)
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// UnwrapBookshopPartial takes the dict or slice that the {{ partial "bookshop" ... }}
|
|
87
|
-
// was given, and pulls out the component / partial name that should be rendered.
|
|
88
|
-
// TODO(bookshop): Ideally our templating support gets better,
|
|
89
|
-
// and we can call the production bookshop module partials.
|
|
90
|
-
func UnwrapBookshopComponent(context interface{}) (string, interface{}) {
|
|
91
|
-
if componentData, ok := context.(map[string]interface{}); ok {
|
|
92
|
-
if component, ok := componentData["_bookshop_name"]; ok {
|
|
93
|
-
key := bookshopKey(component.(string))
|
|
94
|
-
return key, context
|
|
95
|
-
}
|
|
96
|
-
return "err_no_bookshop_name_key", context
|
|
97
|
-
}
|
|
98
|
-
if componentData, ok := context.([]interface{}); ok {
|
|
99
|
-
if component, ok := componentData[0].(string); ok {
|
|
100
|
-
key := bookshopKey(component)
|
|
101
|
-
return key, componentData[1]
|
|
102
|
-
}
|
|
103
|
-
return "err_slice_zero_not_string", context
|
|
104
|
-
}
|
|
105
|
-
if componentData, ok := context.([]string); ok {
|
|
106
|
-
key := bookshopKey(componentData[0])
|
|
107
|
-
return key, componentData[1]
|
|
108
|
-
}
|
|
109
|
-
if componentName, ok := context.(string); ok {
|
|
110
|
-
key := bookshopKey(componentName)
|
|
111
|
-
return key, nil
|
|
112
|
-
}
|
|
113
|
-
return "err_not_map_slice_or_string", context
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
func UnwrapBookshopPartial(context interface{}) (string, interface{}) {
|
|
117
|
-
if partialData, ok := context.([]interface{}); ok {
|
|
118
|
-
if partial, ok := partialData[0].(string); ok {
|
|
119
|
-
key := fmt.Sprintf("shared/hugo/%s.hugo.html", partial)
|
|
120
|
-
return key, partialData[1]
|
|
121
|
-
}
|
|
122
|
-
return "err_slice_zero_not_string", context
|
|
123
|
-
}
|
|
124
|
-
if partialName, ok := context.(string); ok {
|
|
125
|
-
key := fmt.Sprintf("shared/hugo/%s.hugo.html", partialName)
|
|
126
|
-
return key, nil
|
|
127
|
-
}
|
|
128
|
-
return "err_not_slice_or_string", context
|
|
129
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
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
|
-
}
|