jm-ssi

1.0.4 • Public • Published

jm-ssi

NPM version npm download

nodejs 解析ssi库。

支持以下语法:

 <!--# include file="path" -->
<!--# include virtual="path" -->
 
<!--# set var="k" value="v" -->
 
<!--# echo var="name" default="default" -->
 
<!--# if expr="$name = /text/" -->
<!--# if expr="$name != text" -->
<!--# else -->
<!--# endif -->

Install

$ npm i jm-ssi --save

Usage

const ssi = require('jm-ssi');
 
ssi.run(`<!--#if expr="\${HTTP_HOST} = /www.tenganxinxi.com/"-->
<title>腾讯腾安</title>
<!--#elif expr="\${HTTP_HOST} = /www.txfund.com/-->
<title>腾讯腾安2</title>
<!--#else-->
<title>腾讯理财通</title>
<!--#endif-->`, {
    // 指定执行变量
    data: {
        "HTTP_HOST": "www.txfund.com"
    }
}).then((result) => {
    console.log(result);
});
 

文件模板解析

index.shtml

<!--#if expr="${HTTP_HOST} = www.tenganxinxi.com"-->
<title>腾讯腾安</title>
<!--#else-->
<title>腾讯理财通</title>
<!--#endif-->
 
<div>test $ ````</div>
 
<!--#echo var="HTTP_USER_AGENT" -->
 
<!--# include virtual="/if.shtml" stub="one" -->
const path = require('path');
const ssi = require('jm-ssi');
 
const root = path.join(__dirname, 'templates');
ssi.parse('index.shtml', {
    // 指定执行变量
    data: {
        "name": 'fefeding',
        "HTTP_HOST": "www.txfund.com",
        "HTTP_USER_AGENT": "Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1 wechatdevtools/1.02.1907300 MicroMessenger/6.7.3 Language/zh_CN webview/1568882530032134 webdebugger port/31804",
    },
    root
}).then(result => {
    console.log(result);
});

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i jm-ssi

Weekly Downloads

2

Version

1.0.4

License

MIT

Unpacked Size

15.4 kB

Total Files

9

Last publish

Collaborators

  • jiamao