gulp-ssg
A gulp plugin to help generate a static website from a bunch of files.
Installation
$ npm install gulp-ssg
Usage
var ssg = ; gulp;
This will add properties to each file's data
property:
file.data.url
- A URL, which is thefile.relative
with a slash prepended and any trailingindex.*
removedfile.data.dirtyUrl
- As above, but without trailingindex.*
removedfile.data.root
- A pointer to the root filefile.data.parent
- A pointer to the parent filefile.data.children
- An array of pointers to child filesfile.data.siblings
- An array of pointers to sibling files
To explain these a bit more:
- The
root
file is the rootindex.html
file. If there isn't one thenroot
will benull
. - The
parent
file is the parentindex.html
file. If there isn't one thenparent
will benull
. - The
children
are all the files that have a URL that starts with the current files path plus at least one more token in there path. Becauseindex.html
is truncated from URLs this means/foo/bar/
and/foo/fred.html
are both children of/foo/index.html
. - The
siblings
are all the files that have a common parent URL.
This plug-in follows the gulp-data convention of using file.data
, so anything returned from a gulp-data
pipe will be merged with the properties above.
Example
So how can this be used? It gets more interesting when combined with other pipes. For example:
var gulp = ;var ssg = ;var rename = ;var data = ;var matter = ;var markdown = ;var wrap = ;var del = ; gulp;
There are complete examples with templates in the git repo.
Options
string
baseUrl The base URL of the site, defaults to '/'. This should be the path to where your site will eventually be deployed.
string
sort A property to sort pages by, defaults to url
. For example, this could be a property like order
extracted from the YAML front-matter.