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

node-ssi's People

Contributors

67726e avatar kidwm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

node-ssi's Issues

problem with content type

My browser actually tries to download the compiled shtml page, I think there is some problem with http headers.

Support Multiple Directories

I am currently porting an nginx site to express/node server and was wondering if it is possible that this module will support ssi includes from multiple paths?

For example I might have root, modules, components, library and assets directories all with different paths. Is it possible to render files from these paths not just root path. These includes may also include ssi variables etc that may need to be inherited. Is this possible with your module?

Implement control flow

Implement control flow structures:

<!--#if expr="${expression}" -->
  <!--#include virtual="file.html" -->
<!--#elif expr="${expresssion2}" -->
  <!--#include virtual="file2.html" -->
<!--#else -->
  <!--#include vritual="file3.html" -->
<!--#endif -->

Else while not inside of If block

Hi,

I have an high complex ssi website and try to use it with grunt-connect and middleware. i've implementing your plugin like on github described and run "grunt connect". first it looks good no error message given.

But if I request localhost:PORT i got the message "Else while not inside of If block".

I have no clue, where i can start to find the position the error occures. Did u have any idea whre i can start searching?

i use following ssi directives:
#config
#if/elif
#set
#include
#echo

among others expressions:
timefmt
$QUERY_STRING_UNESCAPED
${HTTP_HOST}
${HTTP_USER_AGENT}

Thanks

Implement #exec

Either takes the form of

<!--#exec cmd="ls /some/path" -->

or

<!--#exec cgi="/path/to/file.cgi" -->

Support to use variable in expr

This snippet works on nginx.

<!--#set var="release_date" value="2015-08-28" -->
<time datetime='<!--#echo var="date" -->'>
          <!--#if expr="$date = /(\\d+)-0?(\\d+)-0?(\\d+)/" -->
          <!--#echo var="1" --> Year
          <!--#echo var="2" --> Month
          <!--#echo var="3" --> Day
          <!--#endif -->
</time>

ssi package name on npmjs

Hey :) Found no other easy way to contact you directly. I'm working for a company called "SSI Schaefer" - you might already be guessing where this is going :D

We tried to register the company prefix 'ssi' with npmjs.org, and guess what - it's already taken, for the node-ssi package :D

Is there a chance you would be willing to rename your package and give up the 'ssi' prefix for us to use?

Apache SSI Variable Issue

If we do something like below in .shtml file it is not reading values define in variables.

#set var="REMOTE_HOST" value="localhost"
#set var="Zed" value="${REMOTE_HOST}"

if we pass values like Variable Substitution (like ${REMOTE_HOST}) it is not reading proper values set to variable REMOTE_HOST. can you please resolve this.

Implement #config

directive: config
attr: timefmt, sizefmt, or errmsg
desc: This directive configures the display formats for the date, time, filesize, and error message (returned when an SSI command fails).

such as:

<!--#config timefmt="%Y%m%d%H%M%S" -->

Variable definition scope across inclues

If I define a variable in foo.shtml where foo.shtml is a file that includes bar.shtml then I can only echo that variable in the file foo.shtml the variable is not accessible from within bar.shtml

When running this on apache with SSI then the variable is available from both files.

(Thanks for adding support for echo though)

Better handling No file error

I've got this error output:

Warning: ENOENT, no such file or directory '/home/user/Projects/repo/root.html' Used --force, continuing.

In real case, When Apache does not find the file in #include, it would print the message in output file:
[an error occurred while processing this directive]

Implement #printenv

Outputs all variables both name and value for environment and user-defined variables

<!--#printenv -->

Support #echo

We'd like this functionality in our includes. Would this feature be possible?

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.