0.3.2-beta.3 • Published 3 months ago
liquid-to-js v0.3.2-beta.3
liquid-to-js - 编译liquid主题文件至可直接nodejs中运行的js模块
安装
npm i -D liquid-to-js
# or
pnpm add -D liquid-to-js
编译示例
import parseThemeDir from 'liquid-to-js/parser';
(async () => {
const liquidThemeDir = 'some-liquid-theme-dir';
const mjsThemeDir = 'dist-mjs-theme-dir';
const themeEntryInfo = await parseThemeDir(liquidThemeDir, mjsThemeDir);
console.log(themeEntryInfo);
})();
运行示例
import renderTemplate from 'liquid-to-js/runner';
import fsPromises from 'fs/promises';
(async () => {
const liquidThemeDir = 'some-liquid-theme-dir';
const mjsThemeDir = 'dist-mjs-theme-dir';
const themeIndexJsonPath = mjsThemeDir + '/.index.json';
const themeIndexJsonString = await fsPromises.readFile(themeIndexJsonPath);
const themeEntryInfo = JSON.parse(themeIndexJsonString);
const defaultRenderOptions = {
themeEntryInfo,
contextCode: '',
localeCode: 'zh-CN',
tags: {},
filters: {},
drops: {},
params: {},
async loadAsset({ source: path }) {
// return content
},
async loadObjectsByNames(keys) {
// return objects
},
async loadObjectByHandle(type, handle) {
// return object
},
};
const renderThemeTemplate = async (pageName, options) =>
await renderTemplate(pageName, { ...defaultRenderOptions, ...options });
const pageName = 'index';
const html = await renderThemeTemplate(pageName, { params: {} });
console.log(html);
})();
0.3.2-beta.3
3 months ago
0.3.2-beta.2
3 months ago
0.3.2-beta.1
3 months ago
0.3.1
3 months ago
0.3.0
3 months ago
0.2.0
3 months ago
0.1.0
4 months ago