hoastig v1.2.1
hoastig
hoastig
is a static page generator made with hoast
. It is build to be simple, understandable, and functional out of the box, in order to show the power of hoast
as well as serve a basis to by changed by others to create a workflow that fits their needs.
The system builds by layering source directories in order to modularize site content and site layouts. It supports all the basic which you might expect from a static page generator. First gray-matter
is used to extract front matter from markdown files. markdown-it
is used to convert the content. handlebars
enters the content into specified layouts. Finally all CSS, HTML, and JavaScript are minified using clean-css
, html-minifier
, and terser
respectively.
Table of contents
Installation & usage
Command line interface
To use the command line interface you need to have globally install the tool using npm a package manager prepackaged with Node.js. After you have installed node run the following command to install the package npm i -g hoastig
. From now on you should be able to run the hoastig [options]
command from anywhere on your device. Try running hoastig --help
to see what commands you can use or see the overview below.
Options
-V, --version output the version number
-h, --help output usage information
-c, --config <path> path to configuration file (default: hoastig.json)
-d, --development process files in development mode
-r, --remove remove destination directory beforehand
-d, --development
disables minification of any files as wel as overwrite thebase_url
variable in themetadata
to a specified address and port in the configuration file.
To learn more about how to structure the project see the structure section for more information.
Script
If for any reason you want to use the static page generator as part of node application install it locally using npm i --save hoastig
. After which you should be able to require it and call the asynchronous hoastig(directory[, config, options])
function. See the table below for an explanation of each parameter as well as an example.
directory
: Path to directory to work from, most likely__dirname
.- Type:
String
- Required:
yes
- Type:
config
: Process configuration, see configuration for more details.- Type:
Object
- Required:
no
, see configuration section for default values.
- Type:
options
: Process options.- Type:
Object
- Required:
{ development: false, remove: false }
.
- Type:
options.development
: Whether to disable minification of any files as wel as overwrite thebase_url
variable in themetadata
to a specified address and port in the configuration file.- Type:
Boolean
- Default:
false
- Type:
options.remove
: whether to remove the destination directory before starting to process files.- Type:
Boolean
- Default:
false
- Type:
Example
import hoastig from "hoastig";
const config = {},
options = {};
hoastig(__dirname config, options);
The function is asynchronous and can therefore be used in combination with the
await
keyword.
Configuration
destination
: The directory to write the processed files to.- Type:
String
- Default:
dst
- Type:
source
: The directory to process files from.- Type:
String
- Default:
src
- Type:
sources
: The subdirectories to process files from, whereby the directories later in the list overwrite files in the directories before it.- Type:
Array of strings
- Default:
['']
- Type:
metadata
: Metadata given to the layouts.- Type:
Object
- Default:
{}
- Type:
concurrency
: Maximum number of files to process at once.- Type:
Number
- Default:
Infinity
- Type:
minify
css
: Options for clean-css.- Type:
Object
- Default:
{}
- Type:
html
: Options for html-minifier.- Type:
Object
- Default:
{ "collapseWhitespace": true, "removeComments": true }
- Type:
js
: Options for tenrser.- Type:
Object
- Default:
{}
- Type:
development
host
: Address to use in a development build.- Type:
String
- Default:
localhost
- Type:
port
: Process to use in a development build.- Type:
Number
- Default:
8080
- Type:
minify.css.returnPromise
is always set tofalse
and cannot be overwritten.
minify.html.minifyCSS
andminify.html.minifyJS
are both overwritten with a custom function to useclean-css
andterser
respectively the options for these are retrieved fromminify.css
andminify.js
.
Defaults
{
"destination": "dst",
"source": "src",
"sources": [
""
],
"metadata": {},
"concurrency": Infinity,
"minify": {
"css": {},
"html": {
"collapseWhitespace": true,
"removeComments": true
},
"js": {}
},
"development": {
"host": "localhost",
"port": 8080
}
}
Structure
Configuration file
When using the command line interface the configuration can be specified in a .json
file. By default this will retrieve a hoastig.json
in the directory the command is executed from, this can be overwritten using the -c
or --config
option. For more detail see the configuration section.
Destination directory
The destination directory is the directory relative to where the command is executed from and can be defined in the configuration file, by default this is set to dst
.
Source directory
The source directory is the directory relative to where the command is executed from and can be defined in the configuration file, by default this is set to src
. A separate list of sources can be specified which are contained within the source directory. This list can be used to split parts of a site out in for instance a theme and content, by default this list is set to [ "" ]
. The directories overwrite the previous one in the order they are provided in. The defaults result into taking the src
directory as the root and only directory to build. Each source directory follows the following pattern of directories.
content
: Content files, each file will be transformed into a page. Files should have the.hbs
,.html
, or.md
extension. Extension are eventually converted to.html
if they are not already. Extension can also be chained so that a markdown file can include handlebar partials for instance. For examplepage.hbs.md
will first be transformed from markdown to html, then it will be read as handlebars and transformed to html again, this time giving it the.html
extension. Finally the resulting or pre-existing.html
files will be minified.decorators
: Handlebar decorators. Files should have the.js
extension. The file should export a single handlebars decorator compatible function.helpers
: Handlebar helpers. Files should have the.js
extension. The file should export a single handlebars helper compatible function.layouts
: Handlebar layouts. Files should have the.hbs
extension.partials
: Handlebar partials. Files should either have the.hbs
or.html
extension.static
: Files in this directory will be transferred over to the root of the destinations directory..ccs
,.html
, and.js
will be automatically minified.
Any files put in the root of a source directory or directories not specified in the list above will be ignored by the program. This is useful for storing any
README.md
or other miscellaneous files and directories.
Default example
├── dst/
├── src/
│ ├── content/
│ ├── decorators/
│ ├── helpers/
│ ├── layouts/
│ ├── partials/
│ └── static/
└── hoastig.json
Custom example
hoastig.json:
{
"destination": "destination",
"source": "source",
"sources": [
"theme",
"site"
]
}
Directory structure:
├── destination/
├── source/
│ ├── site/
│ │ ├── content/
│ │ └── static/
│ └── theme/
│ ├── helpers/
│ ├── layouts/
│ ├── partials/
│ └── static/
└── hoastig.json
Don note in this example any files in the
theme
directory also present in thesite
directory are overwritten because of the order specified under sources in thehoastig.json
.
License
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago