mikser-io-render-liquid 1.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/LICENSE +21 -0
- package/README.md +49 -0
- package/index.js +37 -0
- package/package.json +24 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Almero Digital Marketing
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# mikser-io-render-liquid
|
|
2
|
+
|
|
3
|
+
[LiquidJS](https://www.npmjs.com/package/liquidjs) renderer for [Mikser](https://github.com/almero-digital-marketing/mikser-io). Renders entities whose layout uses the `.liquid` template engine.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install mikser-io-render-liquid
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```js
|
|
14
|
+
// mikser.config.js
|
|
15
|
+
export default {
|
|
16
|
+
renderer: 'liquid',
|
|
17
|
+
'render-liquid': {
|
|
18
|
+
jsTruthy: true,
|
|
19
|
+
strictFilters: false
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
The `render-liquid` config object is passed through to the `Liquid` constructor — see [LiquidJS options](https://liquidjs.com/api/interfaces/LiquidOptions.html). Defaults applied by the plugin:
|
|
25
|
+
|
|
26
|
+
- `root: options.layoutsFolder`
|
|
27
|
+
- `extname: '.liquid'`
|
|
28
|
+
- `cache: !options.watch` (cached for one-shot builds, disabled in watch mode)
|
|
29
|
+
|
|
30
|
+
## Runtime → Filters
|
|
31
|
+
|
|
32
|
+
Every function exposed on the render runtime (by Mikser itself or by other `render-*` helper plugins) is auto-registered as a Liquid filter. So if you load `render-markdown`, this works in any template:
|
|
33
|
+
|
|
34
|
+
```liquid
|
|
35
|
+
{{ entity.meta.title }}
|
|
36
|
+
{{ entity.meta.body | markdown }}
|
|
37
|
+
{{ entity.meta.summary | removeMarkdown }}
|
|
38
|
+
{{ '/blog/welcome' | href: 'en' }}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Includes resolve from the layouts folder:
|
|
42
|
+
|
|
43
|
+
```liquid
|
|
44
|
+
{% include 'partials/header' %}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## License
|
|
48
|
+
|
|
49
|
+
MIT
|
package/index.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Liquid } from 'liquidjs'
|
|
2
|
+
import path from 'node:path'
|
|
3
|
+
|
|
4
|
+
let engine
|
|
5
|
+
|
|
6
|
+
export function load({ runtime, options, config }) {
|
|
7
|
+
if (!engine) {
|
|
8
|
+
engine = new Liquid({
|
|
9
|
+
root: options.layoutsFolder,
|
|
10
|
+
extname: '.liquid',
|
|
11
|
+
cache: !options.watch,
|
|
12
|
+
...config,
|
|
13
|
+
})
|
|
14
|
+
}
|
|
15
|
+
runtime.liquid = (name, data) => engine.renderFile(name, data)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export async function render({ entity, options, runtime }) {
|
|
19
|
+
// Expose every function on runtime as a Liquid filter,
|
|
20
|
+
// so render-helper plugins (markdown, href, ...) keep working without per-plugin glue.
|
|
21
|
+
for (let key in runtime) {
|
|
22
|
+
if (typeof runtime[key] === 'function') {
|
|
23
|
+
engine.registerFilter(key, (input, ...args) => runtime[key](input, ...args))
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const name = path.relative(options.layoutsFolder, entity.layout.uri).replace(/\.liquid$/, '')
|
|
27
|
+
try {
|
|
28
|
+
return await runtime.liquid(name, runtime)
|
|
29
|
+
} catch (err) {
|
|
30
|
+
// LiquidJS RenderError/ParseError carry a `token` with file/line/col.
|
|
31
|
+
const token = err?.token
|
|
32
|
+
err.layoutUri ??= token?.file || entity.layout.uri
|
|
33
|
+
if (token?.line && err.line == null) err.line = token.line
|
|
34
|
+
if (token?.col && err.column == null) err.column = token.col
|
|
35
|
+
throw err
|
|
36
|
+
}
|
|
37
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "mikser-io-render-liquid",
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"scripts": {},
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/almero-digital-marketing/mikser-io-render-liquid.git"
|
|
11
|
+
},
|
|
12
|
+
"author": "",
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/almero-digital-marketing/mikser-io-render-liquid/issues"
|
|
16
|
+
},
|
|
17
|
+
"homepage": "https://github.com/almero-digital-marketing/mikser-io-render-liquid#readme",
|
|
18
|
+
"peerDependencies": {
|
|
19
|
+
"mikser-io": "^6.0.0"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"liquidjs": "^10.16.0"
|
|
23
|
+
}
|
|
24
|
+
}
|