@abutkeev/ssi 中文文档教程

发布于 3年前 浏览 26 项目主页 更新于 3年前

node-ssi

构建状态

NodeJS 的服务器端包含

注意: 当前版本的 ssi 同步执行所有 IO。 进一步的开发计划包括异步编写方法和迁移当前方法以符合同步方法的 Node 约定。

Supported Instructions

<!--#include virtual="" -->
<!--#include file="" -->
<!--#set var="" value="" -->
<!--#echo var="" -->

<!--#if expr="" -->
<!--#elif expr="" -->
<!--#else -->
<!--#endif -->

Installation

npm install ssi

Usage

var ssi = require("ssi");

var inputDirectory = "/tmp/test";
var outputDirectory = "/tmp/output";
var matcher = "/**/*.shtml";

var includes = new ssi(inputDirectory, outputDirectory, matcher);
includes.compile();

如果你想在像

BrowserSync Middleware

middleware: [require('connect-modrewrite')([
    '^(.*)\.html$ $1.shtml'
  ]), function(req, res, next) {
    var fs = require('fs');
    var ssi = require('ssi');
    var baseDir = './';
    var pathname = require('url').parse(req.url).pathname;
    var filename = require('path').join(baseDir, pathname.substr(-1) === '/' ? pathname + 'index.shtml' : pathname);
    var parser = new ssi(baseDir, baseDir, '/**/*.shtml');
    if (filename.indexOf('.shtml') > -1 && fs.existsSync(filename))
      res.end(parser.parse(filename, fs.readFileSync(filename, {
        encoding: 'utf8'
      })).contents);
    else
      next();
  }]

Methods

parse(filename, contents)

filename String 文件路径

contents String 待解析文件

内容 方法返回解析内容

compile()

方法解析匹配器在输入目录中找到的所有文件,并将这些文件以相同的名称和目录结构写入输出目录。

License

麻省理工学院

node-ssi

Build Status

Server Side Includes for NodeJS

Note: The current version of ssi does all IO synchronously. Further development plans include writing methods asynchronously and migrating current methods to conform to Node conventions for synchronous methods.

Supported Instructions

<!--#include virtual="" -->
<!--#include file="" -->
<!--#set var="" value="" -->
<!--#echo var="" -->

<!--#if expr="" -->
<!--#elif expr="" -->
<!--#else -->
<!--#endif -->

Installation

npm install ssi

Usage

var ssi = require("ssi");

var inputDirectory = "/tmp/test";
var outputDirectory = "/tmp/output";
var matcher = "/**/*.shtml";

var includes = new ssi(inputDirectory, outputDirectory, matcher);
includes.compile();

If you want to support loosened spaces in directive like <!-- #include file="" --> or <!-- #include file="" -->, just enable the fourth argument: new ssi(inputDirectory, outputDirectory, matcher, true).

BrowserSync Middleware

middleware: [require('connect-modrewrite')([
    '^(.*)\.html$ $1.shtml'
  ]), function(req, res, next) {
    var fs = require('fs');
    var ssi = require('ssi');
    var baseDir = './';
    var pathname = require('url').parse(req.url).pathname;
    var filename = require('path').join(baseDir, pathname.substr(-1) === '/' ? pathname + 'index.shtml' : pathname);
    var parser = new ssi(baseDir, baseDir, '/**/*.shtml');
    if (filename.indexOf('.shtml') > -1 && fs.existsSync(filename))
      res.end(parser.parse(filename, fs.readFileSync(filename, {
        encoding: 'utf8'
      })).contents);
    else
      next();
  }]

Methods

parse(filename, contents)

filename String path to the file

contents String Contents of the file to be parsed

Method returns the parsed contents

compile()

Method parses all of the files found by the matcher in the input directory, and writes the files to the output directory with identical names and directory structure.

License

MIT

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文