Xylo.js is a static site generator using pure HTML template like Vue.js and Thymeleaf.
Install from npm:
npm install xylo
Node.js 12 or higher is required.
const { generate } = require('xylo');
const template = '<!DOCTYPE html><html><body><p x-text="message">Hello World</p><body></html>';
const data = {message: 'Hello Xylo!'};
const html = generate(template, data);
console.log(html); // `<!DOCTYPE html><html><body><p>Hello Xylo!</p><body></html>`
Template:
<p x-text="message">Hello World</p>
Data:
{
"message": "Hello Xylo!"
}
HTML:
<p>Hello Xylo!</p>
Template:
<ul>
<li x-for="todo in todos"><span x-text="todo.title">Todo 1</span></li>
</ul>
Data:
{
"todos": [
{
"title": "Todo1"
},
{
"title": "Todo2"
},
{
"title": "Todo3"
},
]
}
HTML:
<ul>
<li><span>Todo 1</span></li>
<li><span>Todo 2</span></li>
<li><span>Todo 3</span></li>
</ul>
Template:
<span x-if="todo1.done">✅</span><span x-text="todo1.title">Todo 0</span>
<span x-if="todo2.done">✅</span><span x-text="todo2.title">Todo 0</span>
Data:
{
"todo1": {
"done": true,
"title": "Todo 1"
},
"todo2": {
"done": false,
"title": "Todo 2"
}
}
HTML:
<span>✅</span><span>Todo 1</span>
<span>Todo 2</span>
Template:
<img src="logo.png" x-attr:title="message"/>
Data:
{
"message": "Hello Xylo!"
}
HTML:
<img src="logo.png" title="Hello Xylo!" />
Template:
<div x-html="description">This is a description.</div>
Data:
{
"description": "Xylo.js is a static site generator using <strong>pure HTML template</strong> like Vue.js and Thymeleaf.",
}
HTML:
<div>Xylo.js is a static site generator using <strong>pure HTML template</strong> like Vue.js and Thymeleaf.</div>
You can use a customized Jexl.
const { generate } = require('xylo');
const template = '<html><head></head><body><ul><li x-for="item in items|split(' ')" x-text="item"></li></ul></body></html>';
const data = {items: 'A B C'};
const jexl = new jexl.Jexl();
jexl.addTransform('split', (val, sep) => val.split(sep));
const html = generate(template, data, jaxl);
console.log(html); // `<html><head></head><body><ul><li>A</li><li>B</li><li>C</li></ul></body></html>`