2.0.3 • Published 4 years ago
ejs2static v2.0.3
ejs2static
An extremely simple static site generator supporting ejs
Description
This module will generate static sites from ejs files. This allows you to deploy your site on a static provider such as GitHub pages.
I created this because I couldn't find a super simple module or CLI app to do it. Harp exists, but apparently Node 12 isn't supported.
Installation
Module
npm install ejs2static --save
Usage
const Generator = require('ejs2static');
const generator = new Generator(options);
gen.generate() // returns a Promise that resolves once all files are generated
options
(optional)
sourceDir
- This directory will be searched recursively for files. EJS files will be rendered to HTML and copied to theoutputDur
retaining the directory structure.outputDir
- Generates to the static site to this directory.This directory will be cleared before generation ifempty
option is true!copyAll
(optional - defaultfalse
) - If true, all non ejs files in thesourceDir
will be copied to thebuildDir
. This is helpful for copying assets.data
- (optional - default{}
) - Object with keys of files relative to thesourceDir
and values of an object that will be passed as data to the ejs render when the file specified in the key is rendered. (Huh? Check the examples).empty
- (optional - defaultfalse
) - If true, the outputDir will be cleared before render.
Example
├── dist
│ ├── components
│ │ └── head.html
│ ├── dir
│ │ └── dirtest.html
│ ├── test-file.txt
│ └── test.html
├── ejs
│ ├── components
│ │ └── head.ejs
│ ├── dir
│ │ └── dirtest.ejs
│ ├── test-file.txt
│ └── test.ejs
└── test.js
// test.js
const Generator = require('../ejs2static');
const gen = new Generator({
sourceDir: './ejs',
outputDir: './dist',
copyAll: true,
data: {
'./dir/dirtest.ejs': {
someData: "testing data"
}
}
});
gen.generate().then(_ => console.log("Done!"));
License
MIT