Blockstatic HTML content page generator
Blockstatic is a collection of utilities that can be used to generate static HTML content pages from Markdown and JSON data files and using Handlebars.js templates. This module can be used alongside other build tasks that look after assets, scripts or styles.
npm install --save-dev blockstatic
Blockstatic can be used as with a simple command line interface - or as a library in your custom build scripts.
The most important interfaces are the
buildPages() which between them allow you to define a directory containing content pages, and with some config options to build HTML output.
This will scan the contents of the source path for Markdown and JSON files, and convert each into an HTML page, according to the options passed to it, or defined in the loaded JSON.
1. Preparing content
Individual pages can be defined with JSON or as Markdown with YAML front-matter variables
- assets: object with arrays containing assetts for this page.
- indexPages: object with list source and ouput options
- data: object with each property a path to a json file containing data for the page
- docs: object with each property a path to a markdown file for rendering in the page
- routePath: the path to this page
- meta: key/value pairs for title, author, date, published, and any others like keywords, description etc
routePath- the file location (folder) where the output HTML will be written
docs- a hash of ids and markdown files, which are pulled into the template by key
data- a hash of ids and JSON files to be used in the handlebars templates, identified in the template by the key
indexPages- generates a block containing a list of links or pages, as defined by the object
templates- define a
html(outer) template for each page - paths to
e.g. a page definition
Markdown with front-matter
The markdown parser supports standard Markdown with a YAML front-matter:
Note for markdown the
assets are extracted, and what remains is
---author: Adam Davisdate: 2012-01-16description: "Some thoughts on code, beauty and art: my response to a request from a journalist."keywords: code, beauty, art, opinion,title: code, beauty and art.published: trueindexPages:listIndex:inputPath: "./src/content/code-ideas"outputPath: "/code-ideas"limit: 10assets:js:- ./src/scripts/funky.js---
That should get you started.
In the example below I am generating pages for my website.
You can integrate this basic interface into your npm scripts or other build tools:
Options: -V, --version output the version number -c, --config <path> JSON input for default values (site details, templates for html and page required) -s, --src <path> Source content folder (.md and .json) -u, --baseurl <url> Base url for the generated html -o, --output <path> Output dir path -h, --help output usage information
I started writing some - these need completing.
The MIT License (MIT) Copyright (c) 2019 Adam Davis
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.