by Before Semicolon

Build By Data

If you reuse a template to change is content based on the data you pass for different routes, you will need to change those into static pages on build as well. This is if you decide not to go with a live server.

It may look something like this:

const {engine} = require('@beforesemicolon/html-plus');

const app = express();

engine(app, path.resolve(__dirname, './pages'));

app.get('/documentation/:doc?', (req, res) => {
	res.render('documentation', {doc: req.params.doc})

Here we are reusing the documentation template for different url parameter for doc. This is so we can change how the documentation page looks accordingly and since it is not based on a file structure, the builder will not know about it since it only look for files in your pages directory.

Templates option

The templates options allow you to specify as many dynamic templates you want with their respective data list and place to be to be compiled.

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

	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(() => {

Above we are doing the same thing we did in the dynamic routes. The difference here is that we are specifying all the doc params and the path where the file would be if it was not dynamic

The building will use the template specified in path and for each data item will create a file with the first value of the list tuple and passe the second value as context data.