@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.
Files changed (96) hide show
  1. package/.nyc_output/{396c364e-fec4-4f27-9ff2-8b236061ef8f.json → 0f70a16f-6a79-48c7-8b16-3b4665e247b2.json} +0 -0
  2. package/.nyc_output/{4ef43740-059b-4329-96cd-0643fd8fe8d8.json → 6285d5fa-be3d-49e4-8f2f-82157d95dcd8.json} +0 -0
  3. package/.nyc_output/{656275f4-66d6-4d27-bfab-c2f7a3087670.json → 8b5e1314-6e86-4197-a3ae-3c40e4c2f39e.json} +0 -0
  4. package/.nyc_output/{6aec5420-0b83-4260-b300-4d595dfd0660.json → c5490eb0-70c0-468f-a43f-e58c75dd34c8.json} +0 -0
  5. package/.nyc_output/{874bd79b-45da-4726-9afc-1f6cab44be1f.json → ee1a9bec-d318-4aea-af93-7269debcf6df.json} +0 -0
  6. package/.nyc_output/processinfo/{396c364e-fec4-4f27-9ff2-8b236061ef8f.json → 0f70a16f-6a79-48c7-8b16-3b4665e247b2.json} +1 -1
  7. package/.nyc_output/processinfo/6285d5fa-be3d-49e4-8f2f-82157d95dcd8.json +1 -0
  8. package/.nyc_output/processinfo/{4ef43740-059b-4329-96cd-0643fd8fe8d8.json → 8b5e1314-6e86-4197-a3ae-3c40e4c2f39e.json} +1 -1
  9. package/.nyc_output/processinfo/{656275f4-66d6-4d27-bfab-c2f7a3087670.json → c5490eb0-70c0-468f-a43f-e58c75dd34c8.json} +1 -1
  10. package/.nyc_output/processinfo/{874bd79b-45da-4726-9afc-1f6cab44be1f.json → ee1a9bec-d318-4aea-af93-7269debcf6df.json} +1 -1
  11. package/.nyc_output/processinfo/index.json +1 -1
  12. package/bookshop-hugo-templates/bookshop.html +56 -0
  13. package/bookshop-hugo-templates/bookshop_bindings.html +29 -0
  14. package/bookshop-hugo-templates/bookshop_component_browser.html +30 -0
  15. package/bookshop-hugo-templates/bookshop_partial.html +42 -0
  16. package/bookshop-hugo-templates/bookshop_scss.html +9 -0
  17. package/bookshop-hugo-templates/errors/bad_bookshop_tag.html +39 -0
  18. package/bookshop-hugo-templates/errors/err.html +6 -0
  19. package/bookshop-hugo-templates/helpers/component.html +25 -0
  20. package/bookshop-hugo-templates/helpers/component_key.html +11 -0
  21. package/bookshop-hugo-templates/helpers/partial.html +25 -0
  22. package/bookshop-hugo-templates/helpers/partial_key.html +9 -0
  23. package/full-hugo-renderer/build.sh +34 -0
  24. package/full-hugo-renderer/go.mod +87 -0
  25. package/{hugo-renderer → full-hugo-renderer}/go.sum +204 -12
  26. package/full-hugo-renderer/hugo_renderer.wasm +0 -0
  27. package/full-hugo-renderer/hugo_renderer.wasm.gz +0 -0
  28. package/full-hugo-renderer/main.go +215 -0
  29. package/{hugo-renderer → full-hugo-renderer}/wasm_exec.js +6 -2
  30. package/lib/builder.js +2 -2
  31. package/lib/engine.js +109 -42
  32. package/lib/hugoIdentifierParser.js +5 -0
  33. package/lib/translateTextTemplate.js +3 -0
  34. package/lib/translateTextTemplate.test.js +22 -16
  35. package/package.json +4 -4
  36. package/.nyc_output/processinfo/6aec5420-0b83-4260-b300-4d595dfd0660.json +0 -1
  37. package/hugo-renderer/build.sh +0 -66
  38. package/hugo-renderer/deps/bookshop_modified_deps.go +0 -6
  39. package/hugo-renderer/go.mod +0 -19
  40. package/hugo-renderer/helpers/bookshop_modified_content.go +0 -98
  41. package/hugo-renderer/helpers/bookshop_modified_general.go +0 -33
  42. package/hugo-renderer/helpers/emoji.go +0 -96
  43. package/hugo-renderer/hugo_renderer.wasm +0 -0
  44. package/hugo-renderer/hugo_renderer.wasm.gz +0 -0
  45. package/hugo-renderer/main.go +0 -42
  46. package/hugo-renderer/tpl/bookshop_engine/bookshop_func_importer.go +0 -35
  47. package/hugo-renderer/tpl/bookshop_engine/bookshop_render.go +0 -64
  48. package/hugo-renderer/tpl/bookshop_library/bookshop_components.go +0 -129
  49. package/hugo-renderer/tpl/bookshop_library/bookshop_data.go +0 -53
  50. package/hugo-renderer/tpl/cast/cast.go +0 -63
  51. package/hugo-renderer/tpl/cast/init.go +0 -57
  52. package/hugo-renderer/tpl/collections/append.go +0 -37
  53. package/hugo-renderer/tpl/collections/apply.go +0 -131
  54. package/hugo-renderer/tpl/collections/collections.go +0 -768
  55. package/hugo-renderer/tpl/collections/complement.go +0 -55
  56. package/hugo-renderer/tpl/collections/index.go +0 -133
  57. package/hugo-renderer/tpl/collections/init.go +0 -214
  58. package/hugo-renderer/tpl/collections/merge.go +0 -126
  59. package/hugo-renderer/tpl/collections/reflect_helpers.go +0 -216
  60. package/hugo-renderer/tpl/collections/sort.go +0 -183
  61. package/hugo-renderer/tpl/collections/symdiff.go +0 -68
  62. package/hugo-renderer/tpl/collections/where.go +0 -517
  63. package/hugo-renderer/tpl/compare/compare.go +0 -324
  64. package/hugo-renderer/tpl/compare/init.go +0 -85
  65. package/hugo-renderer/tpl/crypto/crypto.go +0 -109
  66. package/hugo-renderer/tpl/crypto/init.go +0 -65
  67. package/hugo-renderer/tpl/debug/debug.go +0 -40
  68. package/hugo-renderer/tpl/debug/init.go +0 -45
  69. package/hugo-renderer/tpl/encoding/encoding.go +0 -90
  70. package/hugo-renderer/tpl/encoding/init.go +0 -59
  71. package/hugo-renderer/tpl/fmt/fmt.go +0 -66
  72. package/hugo-renderer/tpl/fmt/init.go +0 -77
  73. package/hugo-renderer/tpl/inflect/inflect.go +0 -79
  74. package/hugo-renderer/tpl/inflect/init.go +0 -60
  75. package/hugo-renderer/tpl/internal/bookshop_modified_templatefuncsRegistry.go +0 -88
  76. package/hugo-renderer/tpl/math/init.go +0 -134
  77. package/hugo-renderer/tpl/math/math.go +0 -164
  78. package/hugo-renderer/tpl/math/round.go +0 -61
  79. package/hugo-renderer/tpl/partials/init.go +0 -55
  80. package/hugo-renderer/tpl/partials/partials.go +0 -88
  81. package/hugo-renderer/tpl/path/init.go +0 -60
  82. package/hugo-renderer/tpl/path/path.go +0 -159
  83. package/hugo-renderer/tpl/reflect/init.go +0 -51
  84. package/hugo-renderer/tpl/reflect/reflect.go +0 -36
  85. package/hugo-renderer/tpl/safe/init.go +0 -80
  86. package/hugo-renderer/tpl/safe/safe.go +0 -72
  87. package/hugo-renderer/tpl/site/bookshop_site.go +0 -67
  88. package/hugo-renderer/tpl/site/init.go +0 -41
  89. package/hugo-renderer/tpl/strings/init.go +0 -229
  90. package/hugo-renderer/tpl/strings/regexp.go +0 -125
  91. package/hugo-renderer/tpl/strings/strings.go +0 -500
  92. package/hugo-renderer/tpl/strings/truncate.go +0 -157
  93. package/hugo-renderer/tpl/transform/bookshop_unmarshal.go +0 -39
  94. package/hugo-renderer/tpl/transform/init.go +0 -113
  95. package/hugo-renderer/tpl/transform/transform.go +0 -116
  96. package/hugo-renderer/update-from-hugo.sh +0 -19
@@ -1,324 +0,0 @@
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 compare provides template functions for comparing values.
15
- package compare
16
-
17
- import (
18
- "fmt"
19
- "reflect"
20
- "strconv"
21
- "time"
22
-
23
- "github.com/gohugoio/hugo/compare"
24
-
25
- "github.com/gohugoio/hugo/common/types"
26
- )
27
-
28
- // New returns a new instance of the compare-namespaced template functions.
29
- func New(caseInsensitive bool) *Namespace {
30
- return &Namespace{caseInsensitive: caseInsensitive}
31
- }
32
-
33
- // Namespace provides template functions for the "compare" namespace.
34
- type Namespace struct {
35
- // Enable to do case insensitive string compares.
36
- caseInsensitive bool
37
- }
38
-
39
- // Default checks whether a given value is set and returns a default value if it
40
- // is not. "Set" in this context means non-zero for numeric types and times;
41
- // non-zero length for strings, arrays, slices, and maps;
42
- // any boolean or struct value; or non-nil for any other types.
43
- func (*Namespace) Default(dflt interface{}, given ...interface{}) (interface{}, error) {
44
- // given is variadic because the following construct will not pass a piped
45
- // argument when the key is missing: {{ index . "key" | default "foo" }}
46
- // The Go template will complain that we got 1 argument when we expected 2.
47
-
48
- if len(given) == 0 {
49
- return dflt, nil
50
- }
51
- if len(given) != 1 {
52
- return nil, fmt.Errorf("wrong number of args for default: want 2 got %d", len(given)+1)
53
- }
54
-
55
- g := reflect.ValueOf(given[0])
56
- if !g.IsValid() {
57
- return dflt, nil
58
- }
59
-
60
- set := false
61
-
62
- switch g.Kind() {
63
- case reflect.Bool:
64
- set = true
65
- case reflect.String, reflect.Array, reflect.Slice, reflect.Map:
66
- set = g.Len() != 0
67
- case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
68
- set = g.Int() != 0
69
- case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
70
- set = g.Uint() != 0
71
- case reflect.Float32, reflect.Float64:
72
- set = g.Float() != 0
73
- case reflect.Complex64, reflect.Complex128:
74
- set = g.Complex() != 0
75
- case reflect.Struct:
76
- switch actual := given[0].(type) {
77
- case time.Time:
78
- set = !actual.IsZero()
79
- default:
80
- set = true
81
- }
82
- default:
83
- set = !g.IsNil()
84
- }
85
-
86
- if set {
87
- return given[0], nil
88
- }
89
-
90
- return dflt, nil
91
- }
92
-
93
- // Eq returns the boolean truth of arg1 == arg2 || arg1 == arg3 || arg1 == arg4.
94
- func (n *Namespace) Eq(first interface{}, others ...interface{}) bool {
95
- if n.caseInsensitive {
96
- panic("caseInsensitive not implemented for Eq")
97
- }
98
- if len(others) == 0 {
99
- panic("missing arguments for comparison")
100
- }
101
-
102
- normalize := func(v interface{}) interface{} {
103
- if types.IsNil(v) {
104
- return nil
105
- }
106
- vv := reflect.ValueOf(v)
107
- switch vv.Kind() {
108
- case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
109
- return vv.Int()
110
- case reflect.Float32, reflect.Float64:
111
- return vv.Float()
112
- case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
113
- return vv.Uint()
114
- case reflect.String:
115
- return vv.String()
116
- default:
117
- return v
118
- }
119
- }
120
-
121
- normFirst := normalize(first)
122
- for _, other := range others {
123
- if e, ok := first.(compare.Eqer); ok {
124
- if e.Eq(other) {
125
- return true
126
- }
127
- continue
128
- }
129
-
130
- if e, ok := other.(compare.Eqer); ok {
131
- if e.Eq(first) {
132
- return true
133
- }
134
- continue
135
- }
136
-
137
- other = normalize(other)
138
- if reflect.DeepEqual(normFirst, other) {
139
- return true
140
- }
141
- }
142
-
143
- return false
144
- }
145
-
146
- // Ne returns the boolean truth of arg1 != arg2 && arg1 != arg3 && arg1 != arg4.
147
- func (n *Namespace) Ne(first interface{}, others ...interface{}) bool {
148
- for _, other := range others {
149
- if n.Eq(first, other) {
150
- return false
151
- }
152
- }
153
- return true
154
- }
155
-
156
- // Ge returns the boolean truth of arg1 >= arg2 && arg1 >= arg3 && arg1 >= arg4.
157
- func (n *Namespace) Ge(first interface{}, others ...interface{}) bool {
158
- for _, other := range others {
159
- left, right := n.compareGet(first, other)
160
- if !(left >= right) {
161
- return false
162
- }
163
- }
164
- return true
165
- }
166
-
167
- // Gt returns the boolean truth of arg1 > arg2 && arg1 > arg3 && arg1 > arg4.
168
- func (n *Namespace) Gt(first interface{}, others ...interface{}) bool {
169
- for _, other := range others {
170
- left, right := n.compareGet(first, other)
171
- if !(left > right) {
172
- return false
173
- }
174
- }
175
- return true
176
- }
177
-
178
- // Le returns the boolean truth of arg1 <= arg2 && arg1 <= arg3 && arg1 <= arg4.
179
- func (n *Namespace) Le(first interface{}, others ...interface{}) bool {
180
- for _, other := range others {
181
- left, right := n.compareGet(first, other)
182
- if !(left <= right) {
183
- return false
184
- }
185
- }
186
- return true
187
- }
188
-
189
- // Lt returns the boolean truth of arg1 < arg2 && arg1 < arg3 && arg1 < arg4.
190
- func (n *Namespace) Lt(first interface{}, others ...interface{}) bool {
191
- for _, other := range others {
192
- left, right := n.compareGet(first, other)
193
- if !(left < right) {
194
- return false
195
- }
196
- }
197
- return true
198
- }
199
-
200
- // Conditional can be used as a ternary operator.
201
- // It returns a if condition, else b.
202
- func (n *Namespace) Conditional(condition bool, a, b interface{}) interface{} {
203
- if condition {
204
- return a
205
- }
206
- return b
207
- }
208
-
209
- func (ns *Namespace) compareGet(a interface{}, b interface{}) (float64, float64) {
210
- if ac, ok := a.(compare.Comparer); ok {
211
- c := ac.Compare(b)
212
- if c < 0 {
213
- return 1, 0
214
- } else if c == 0 {
215
- return 0, 0
216
- } else {
217
- return 0, 1
218
- }
219
- }
220
-
221
- if bc, ok := b.(compare.Comparer); ok {
222
- c := bc.Compare(a)
223
- if c < 0 {
224
- return 0, 1
225
- } else if c == 0 {
226
- return 0, 0
227
- } else {
228
- return 1, 0
229
- }
230
- }
231
-
232
- var left, right float64
233
- var leftStr, rightStr *string
234
- av := reflect.ValueOf(a)
235
-
236
- switch av.Kind() {
237
- case reflect.Array, reflect.Chan, reflect.Map, reflect.Slice:
238
- left = float64(av.Len())
239
- case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
240
- left = float64(av.Int())
241
- case reflect.Float32, reflect.Float64:
242
- left = av.Float()
243
- case reflect.String:
244
- var err error
245
- left, err = strconv.ParseFloat(av.String(), 64)
246
- if err != nil {
247
- str := av.String()
248
- leftStr = &str
249
- }
250
- case reflect.Struct:
251
- switch av.Type() {
252
- case timeType:
253
- left = float64(toTimeUnix(av))
254
- }
255
- case reflect.Bool:
256
- left = 0
257
- if av.Bool() {
258
- left = 1
259
- }
260
- }
261
-
262
- bv := reflect.ValueOf(b)
263
-
264
- switch bv.Kind() {
265
- case reflect.Array, reflect.Chan, reflect.Map, reflect.Slice:
266
- right = float64(bv.Len())
267
- case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
268
- right = float64(bv.Int())
269
- case reflect.Float32, reflect.Float64:
270
- right = bv.Float()
271
- case reflect.String:
272
- var err error
273
- right, err = strconv.ParseFloat(bv.String(), 64)
274
- if err != nil {
275
- str := bv.String()
276
- rightStr = &str
277
- }
278
- case reflect.Struct:
279
- switch bv.Type() {
280
- case timeType:
281
- right = float64(toTimeUnix(bv))
282
- }
283
- case reflect.Bool:
284
- right = 0
285
- if bv.Bool() {
286
- right = 1
287
- }
288
- }
289
-
290
- if ns.caseInsensitive && leftStr != nil && rightStr != nil {
291
- c := compare.Strings(*leftStr, *rightStr)
292
- if c < 0 {
293
- return 0, 1
294
- } else if c > 0 {
295
- return 1, 0
296
- } else {
297
- return 0, 0
298
- }
299
- }
300
-
301
- switch {
302
- case leftStr == nil || rightStr == nil:
303
- case *leftStr < *rightStr:
304
- return 0, 1
305
- case *leftStr > *rightStr:
306
- return 1, 0
307
- default:
308
- return 0, 0
309
- }
310
-
311
- return left, right
312
- }
313
-
314
- var timeType = reflect.TypeOf((*time.Time)(nil)).Elem()
315
-
316
- func toTimeUnix(v reflect.Value) int64 {
317
- if v.Kind() == reflect.Interface {
318
- return toTimeUnix(v.Elem())
319
- }
320
- if v.Type() != timeType {
321
- panic("coding error: argument must be time.Time type reflect Value")
322
- }
323
- return v.MethodByName("Unix").Call([]reflect.Value{})[0].Int()
324
- }
@@ -1,85 +0,0 @@
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 compare
15
-
16
- import (
17
- "hugo-renderer/deps"
18
- "hugo-renderer/tpl/internal"
19
- )
20
-
21
- const name = "compare"
22
-
23
- func init() {
24
- f := func(d *deps.Deps) *internal.TemplateFuncsNamespace {
25
- ctx := New(false)
26
-
27
- ns := &internal.TemplateFuncsNamespace{
28
- Name: name,
29
- Context: func(args ...interface{}) (interface{}, error) { return ctx, nil },
30
- }
31
-
32
- ns.AddMethodMapping(ctx.Default,
33
- []string{"default"},
34
- [][2]string{
35
- {`{{ "Hugo Rocks!" | default "Hugo Rules!" }}`, `Hugo Rocks!`},
36
- {`{{ "" | default "Hugo Rules!" }}`, `Hugo Rules!`},
37
- },
38
- )
39
-
40
- ns.AddMethodMapping(ctx.Eq,
41
- []string{"eq"},
42
- [][2]string{
43
- {`{{ if eq .Section "blog" }}current{{ end }}`, `current`},
44
- },
45
- )
46
-
47
- ns.AddMethodMapping(ctx.Ge,
48
- []string{"ge"},
49
- [][2]string{
50
- {`{{ if ge .Hugo.Version "0.36" }}Reasonable new Hugo version!{{ end }}`, `Reasonable new Hugo version!`},
51
- },
52
- )
53
-
54
- ns.AddMethodMapping(ctx.Gt,
55
- []string{"gt"},
56
- [][2]string{},
57
- )
58
-
59
- ns.AddMethodMapping(ctx.Le,
60
- []string{"le"},
61
- [][2]string{},
62
- )
63
-
64
- ns.AddMethodMapping(ctx.Lt,
65
- []string{"lt"},
66
- [][2]string{},
67
- )
68
-
69
- ns.AddMethodMapping(ctx.Ne,
70
- []string{"ne"},
71
- [][2]string{},
72
- )
73
-
74
- ns.AddMethodMapping(ctx.Conditional,
75
- []string{"cond"},
76
- [][2]string{
77
- {`{{ cond (eq (add 2 2) 4) "2+2 is 4" "what?" | safeHTML }}`, `2+2 is 4`},
78
- },
79
- )
80
-
81
- return ns
82
- }
83
-
84
- internal.AddTemplateFuncsNamespace(f)
85
- }
@@ -1,109 +0,0 @@
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 crypto provides template functions for cryptographic operations.
15
- package crypto
16
-
17
- import (
18
- "crypto/hmac"
19
- "crypto/md5"
20
- "crypto/sha1"
21
- "crypto/sha256"
22
- "crypto/sha512"
23
- "encoding/hex"
24
- "fmt"
25
- "hash"
26
-
27
- "github.com/spf13/cast"
28
- )
29
-
30
- // New returns a new instance of the crypto-namespaced template functions.
31
- func New() *Namespace {
32
- return &Namespace{}
33
- }
34
-
35
- // Namespace provides template functions for the "crypto" namespace.
36
- type Namespace struct{}
37
-
38
- // MD5 hashes the given input and returns its MD5 checksum.
39
- func (ns *Namespace) MD5(in interface{}) (string, error) {
40
- conv, err := cast.ToStringE(in)
41
- if err != nil {
42
- return "", err
43
- }
44
-
45
- hash := md5.Sum([]byte(conv))
46
- return hex.EncodeToString(hash[:]), nil
47
- }
48
-
49
- // SHA1 hashes the given input and returns its SHA1 checksum.
50
- func (ns *Namespace) SHA1(in interface{}) (string, error) {
51
- conv, err := cast.ToStringE(in)
52
- if err != nil {
53
- return "", err
54
- }
55
-
56
- hash := sha1.Sum([]byte(conv))
57
- return hex.EncodeToString(hash[:]), nil
58
- }
59
-
60
- // SHA256 hashes the given input and returns its SHA256 checksum.
61
- func (ns *Namespace) SHA256(in interface{}) (string, error) {
62
- conv, err := cast.ToStringE(in)
63
- if err != nil {
64
- return "", err
65
- }
66
-
67
- hash := sha256.Sum256([]byte(conv))
68
- return hex.EncodeToString(hash[:]), nil
69
- }
70
-
71
- // HMAC returns a cryptographic hash that uses a key to sign a message.
72
- func (ns *Namespace) HMAC(h interface{}, k interface{}, m interface{}) (string, error) {
73
- ha, err := cast.ToStringE(h)
74
- if err != nil {
75
- return "", err
76
- }
77
-
78
- var hash func() hash.Hash
79
- switch ha {
80
- case "md5":
81
- hash = md5.New
82
- case "sha1":
83
- hash = sha1.New
84
- case "sha256":
85
- hash = sha256.New
86
- case "sha512":
87
- hash = sha512.New
88
- default:
89
- return "", fmt.Errorf("hmac: %s is not a supported hash function", ha)
90
- }
91
-
92
- msg, err := cast.ToStringE(m)
93
- if err != nil {
94
- return "", err
95
- }
96
-
97
- key, err := cast.ToStringE(k)
98
- if err != nil {
99
- return "", err
100
- }
101
-
102
- mac := hmac.New(hash, []byte(key))
103
- _, err = mac.Write([]byte(msg))
104
- if err != nil {
105
- return "", err
106
- }
107
-
108
- return hex.EncodeToString(mac.Sum(nil)[:]), nil
109
- }
@@ -1,65 +0,0 @@
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 crypto
15
-
16
- import (
17
- "hugo-renderer/deps"
18
- "hugo-renderer/tpl/internal"
19
- )
20
-
21
- const name = "crypto"
22
-
23
- func init() {
24
- f := func(d *deps.Deps) *internal.TemplateFuncsNamespace {
25
- ctx := New()
26
-
27
- ns := &internal.TemplateFuncsNamespace{
28
- Name: name,
29
- Context: func(args ...interface{}) (interface{}, error) { return ctx, nil },
30
- }
31
-
32
- ns.AddMethodMapping(ctx.MD5,
33
- []string{"md5"},
34
- [][2]string{
35
- {`{{ md5 "Hello world, gophers!" }}`, `b3029f756f98f79e7f1b7f1d1f0dd53b`},
36
- {`{{ crypto.MD5 "Hello world, gophers!" }}`, `b3029f756f98f79e7f1b7f1d1f0dd53b`},
37
- },
38
- )
39
-
40
- ns.AddMethodMapping(ctx.SHA1,
41
- []string{"sha1"},
42
- [][2]string{
43
- {`{{ sha1 "Hello world, gophers!" }}`, `c8b5b0e33d408246e30f53e32b8f7627a7a649d4`},
44
- },
45
- )
46
-
47
- ns.AddMethodMapping(ctx.SHA256,
48
- []string{"sha256"},
49
- [][2]string{
50
- {`{{ sha256 "Hello world, gophers!" }}`, `6ec43b78da9669f50e4e422575c54bf87536954ccd58280219c393f2ce352b46`},
51
- },
52
- )
53
-
54
- ns.AddMethodMapping(ctx.HMAC,
55
- []string{"hmac"},
56
- [][2]string{
57
- {`{{ hmac "sha256" "Secret key" "Hello world, gophers!" }}`, `b6d11b6c53830b9d87036272ca9fe9d19306b8f9d8aa07b15da27d89e6e34f40`},
58
- },
59
- )
60
-
61
- return ns
62
- }
63
-
64
- internal.AddTemplateFuncsNamespace(f)
65
- }
@@ -1,40 +0,0 @@
1
- // Copyright 2020 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 debug provides template functions to help debugging templates.
15
- package debug
16
-
17
- import (
18
- "github.com/sanity-io/litter"
19
-
20
- "hugo-renderer/deps"
21
- )
22
-
23
- // New returns a new instance of the debug-namespaced template functions.
24
- func New(d *deps.Deps) *Namespace {
25
- return &Namespace{}
26
- }
27
-
28
- // Namespace provides template functions for the "debug" namespace.
29
- type Namespace struct {
30
- }
31
-
32
- // Dump returns a object dump of val as a string.
33
- // Note that not every value passed to Dump will print so nicely, but
34
- // we'll improve on that. We recommend using the "go" Chroma lexer to format the output
35
- // nicely.
36
- // Also note that the output from Dump may change from Hugo version to the next,
37
- // so don't depend on a specific output.
38
- func (ns *Namespace) Dump(val interface{}) string {
39
- return litter.Sdump(val)
40
- }
@@ -1,45 +0,0 @@
1
- // Copyright 2020 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 debug
15
-
16
- import (
17
- "hugo-renderer/deps"
18
- "hugo-renderer/tpl/internal"
19
- )
20
-
21
- const name = "debug"
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.Dump,
33
- nil,
34
- [][2]string{
35
- {`{{- $m := newScratch -}}
36
- {{- $m.Set "Hugo" "Rocks!" -}}
37
- {{- $m.Values | debug.Dump | safeHTML -}}`, "map[string]interface {}{\n \"Hugo\": \"Rocks!\",\n}"},
38
- },
39
- )
40
-
41
- return ns
42
- }
43
-
44
- internal.AddTemplateFuncsNamespace(f)
45
- }