mikser-io-render-liquid 2.0.0 → 2.1.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/index.js +10 -11
- package/package.json +3 -3
package/index.js
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import { Liquid } from 'liquidjs'
|
|
2
|
-
import path from 'node:path'
|
|
3
2
|
|
|
4
3
|
let engine
|
|
5
4
|
|
|
6
5
|
export function load({ runtime, options, config }) {
|
|
7
6
|
if (!engine) {
|
|
7
|
+
// `root` still points at the layouts folder so LiquidJS's own
|
|
8
|
+
// `{% include 'partial' %}` / `{% layout 'wrapper' %}`
|
|
9
|
+
// directives can resolve from disk. The top-level layout body
|
|
10
|
+
// is rendered from `entity.layout.content` (populated by the
|
|
11
|
+
// layouts plugin and stripped of YAML by front-matter) —
|
|
12
|
+
// single source of truth for layout bodies.
|
|
8
13
|
engine = new Liquid({
|
|
9
14
|
root: options.layoutsFolder,
|
|
10
15
|
extname: '.liquid',
|
|
@@ -12,10 +17,10 @@ export function load({ runtime, options, config }) {
|
|
|
12
17
|
...config,
|
|
13
18
|
})
|
|
14
19
|
}
|
|
15
|
-
runtime.liquid = (
|
|
20
|
+
runtime.liquid = (source, data) => engine.parseAndRender(source, data)
|
|
16
21
|
}
|
|
17
22
|
|
|
18
|
-
export async function render({ entity,
|
|
23
|
+
export async function render({ entity, runtime }) {
|
|
19
24
|
// Expose every function on runtime as a Liquid filter,
|
|
20
25
|
// so render-helper plugins (markdown, href, ...) keep working without per-plugin glue.
|
|
21
26
|
for (let key in runtime) {
|
|
@@ -23,15 +28,9 @@ export async function render({ entity, options, runtime }) {
|
|
|
23
28
|
engine.registerFilter(key, (input, ...args) => runtime[key](input, ...args))
|
|
24
29
|
}
|
|
25
30
|
}
|
|
26
|
-
|
|
27
|
-
// skips its own `extname` append for names that already have a
|
|
28
|
-
// file-ish extension — and `path.extname('foo.html-pdf')` is
|
|
29
|
-
// `.html-pdf`, which Liquid treats as "extension already present".
|
|
30
|
-
// Stripping would make multi-segment layout names (e.g.
|
|
31
|
-
// `franchises.html-pdf.liquid`) fail with ENOENT.
|
|
32
|
-
const name = path.relative(options.layoutsFolder, entity.layout.uri)
|
|
31
|
+
const source = entity.layout.content ?? ''
|
|
33
32
|
try {
|
|
34
|
-
return await runtime.liquid(
|
|
33
|
+
return await runtime.liquid(source, runtime)
|
|
35
34
|
} catch (err) {
|
|
36
35
|
// LiquidJS RenderError/ParseError carry a `token` with file/line/col.
|
|
37
36
|
const token = err?.token
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mikser-io-render-liquid",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -16,9 +16,9 @@
|
|
|
16
16
|
},
|
|
17
17
|
"homepage": "https://github.com/almero-digital-marketing/mikser-io-render-liquid#readme",
|
|
18
18
|
"peerDependencies": {
|
|
19
|
-
"mikser-io": "^7.
|
|
19
|
+
"mikser-io": "^7.12.0"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"liquidjs": "^10.
|
|
22
|
+
"liquidjs": "^10.27.0"
|
|
23
23
|
}
|
|
24
24
|
}
|