by Before Semicolon

build()

build details
Details
name build
type function
arguments options
description A function that will compile all pages and their connected resource for production.

Options

Options can be provided directly to the build function or you can simply create a hp.config.js file at the root directory and export(using module.exports = {...}) an object with the following properties.

If you provide options both, by providing the hp.config.js file and build options, these are deeply merged and the options provided to the build function directly will override the hp.config.js file ones where they match in properties.

srcDir
type: string : An absolute path to the directory containing all pages, assets and connected resources.
destDir
type: string : An absolute path to the directory where the site build result files should go.
staticData
type: object : An object with whatever data you want to be available on all templates.
customTags
type: array : An array of function or class based custom tags.
customAttributes
type: array : An array of Attributes based custom attributes.
contextDataProvider
type: function : A callback function that will be called for every file with the page absolute path and corresponding routing path and must return an object to be passed to the page as context data.
templates
type: array : An array of templates which is a object containing a path key with the absolute path to the template file to use and a dataList array key containing tuples where the first value is the routing path and the second the context data.

Usage Examples

The build function shares a lot of options with the engine function. Use the hp.config.js to share common options between them.

const {build} = require("@beforesemicolon/html-plus");
const CodeSnippet = require("./tags/code-snippet.js");
const Wrapper = require("./attributes/wrapper.js");

build({
	srcDir: path.resolve(__dirname, './pages'),
	destDir: path.resolve(__dirname, '../public'),
	staticData: {
		title: 'Before Semicolon'
	},
	customTags: [CodeSnippet],
	customAttributes: [Wrapper]
})
	.then(() => {
		console.log('done');
	})

The contextDataProvider is the equivalent of the onPageRequest option for engine and to replace dynamic route context data.

const {build} = require("@beforesemicolon/html-plus");
const path = require("path");

build({
	srcDir: path.resolve(__dirname, './pages'),
	destDir: path.resolve(__dirname, '../public'),
	contextDataProvider: page => {
		return {path: page.path, fileName: path.basename(page.file)};
	}
}).then(() => {
	console.log('done');
})

The templates option is for cases where you have created dynamic pages which the builder can't see but you can replicate here.

const {build} = require("@beforesemicolon/html-plus");
const path = require("path");

build({
	srcDir: path.resolve(__dirname, './pages'),
	destDir: path.resolve(__dirname, '../public'),
	templates: [
		{
			path: path.resolve(__dirname, './pages/documentation.html'),
			dataList: [
				['/documentation/getting-started', {doc: 'getting-started'}],
				['/documentation/faq', {doc: 'faq'}],
				['/documentation/api-reference', {doc: 'api-reference'}],
			]
		}
	]
}).then(() => {
	console.log('done');
})