Giter Site home page Giter Site logo

node-ssi's Introduction

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.