5.1.0 • Published 2 years ago

@ngeojiajun/ejs-site-generator v5.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

EJS Site Generator

A simple tool that generate the HTML files based on the EJS template and the data for the static site.

Usage

$ejs-site-generator -h
Usage: index [options]

Options:
  -V, --version   output the version number
  -views <dir>    The directory for the views (default: "./views")
  -data <dir>     The directory for the data (default: "./data")
  -out <dir>      The directory for the outputs (default: "./out")
  -statics <dir>  The directory for the static files which will copied on the end of the build (default: "./statics")
  -base <dir>     The base directory for the execution (default: "./")
  -h, --help      display help for command

Directory structure of the view folder

NameDescription
default.ejsThe default view that it should the engine load if the _viewParam.view value is missing inside the data files
<name>.ejsThe views for the file
<name>.ejs.jsonThe default value assignments for the file

Alert: If a view inherit another view, all key present in the parent json file must be also present in the view's json file or it will causes some undefined symbol errors. The json inheriting is work in progress

Directory structure of the data folder

The engine accept four type of files: 1. .json files which only contains the data file that the template require 2. .ejs or .html files which contain the html code to be directly included inside the template. This require the template to support it by include the file specified by the _external.ejs_include variable. The metadata required by the template could be provided through the <filename>.json under the same directory. 3. .idtl files which have both html code and its metadata combined together. See IDTL.md on the guideline on using it. 4. .jst files which serve as the template for the JavaScript files. The engine's working directory always at the root directory when it is executed.

API exported by the engine

NameDescription
_external._path.data(name)Return the resolved path for the path provided relative to the data directory
_external._path.base(name)Return the resolved path for the path provided relative to the base directory
_external._path.views(name)Return the resolved path for the path provided relative to the views directory

Special key in the JSON metadata

The _viewParam key allows the developer to specify the behavior of the compiler

{
  "_viewParam":{
    "ignore": true|false,
    "view":"default"
  }
}
NameTypeDescription
ignoreAllThe compiler should ignore this file from being processed
viewData pages onlyThe name of view that compiler will use while building the html for the data

Runtime Variables

This contain a list of the variables which will be defined by the engine if not defined by the page

NameDescription
build_timeThe JavaScript Date Object which represent the timestamp that the build is started
page_unit_nameThe name of the page which usually taken from the filename
page_unit_pathSimilar with the page_unit_name but provided in full path
InteropsHandle to the imported copy of the plugin.js inside the build directory is it is found

Plugin support

The generator supports custom plugin by placing a plugin.js on the base directory. Its exports will be imported as Interops from the template.

Build hooks

Within the same file the developers can specify their build hooks to catch events.

NameDescription
hooks.build_start()The build is begin
hooks.build_done()The build is finished
hooks.new_page(path)A new page has been generated
5.1.0

2 years ago

5.0.0

2 years ago

4.0.0

2 years ago

3.0.0

2 years ago

2.0.0

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago