Server Side Includes for NodeJS
npm install @abutkeev/ssinode-ssi
========

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.
``html
`
`bash`
npm install ssi
`javascript
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 or , just enable the fourth argument: new ssi(inputDirectory, outputDirectory, matcher, true).
#### BrowserSync Middleware
`js`
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();
}]
#### 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.
MIT