diff --git a/CHANGES.md b/CHANGES.md index 378c231..0c82dbf 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,23 @@ CHANGELOG ====================================================== +Branch 3.X.X +------------------------------------------------------ + +### 3.0.0 ### + +* Refactored the whole codebase +* Added: template support for `pagetitle` (automatically set if not defined) +* Added: option to set the pagetitle directly via `payload.pagetitle` (koa+expressjs) +* Added: filter function to dynamically manipulate the errordata object (koa+expressjs) +* Added: support for additional variables/payloads +* Added: support for placeholders to static page generator +* Added: iso-639-1 `language` attribute (derived from page lang) +* Added: error/exception object available via `error` (koa+expressjs) +* Added: `onError` callback as debug error handler (not to be used in production) +* Changed: moved `footer` content into `payload` object +* Changed: all variables within the `ejs` template are only accessible via `vars` object + Branch 2.X.X ------------------------------------------------------ diff --git a/README.md b/README.md index 8be225f..14be2b6 100644 --- a/README.md +++ b/README.md @@ -153,7 +153,10 @@ async function bootstrap(){ // because of the asynchronous file-loaders, wait until it has been executed await _httpErrorPages.express(_webapp, { lang: 'en_US', - footer: 'Hello World' + payload: { + footer: 'Hello World', + myvar: 'hello world' + } }); // start service @@ -174,10 +177,13 @@ bootstrap() Syntax: `Promise _httpErrorPages.express(expressWebapp [, options:Object])` -* `template` - the path to a custom **EJS** template used to generate the pages. default [assets/template.ejs](assets/template.ejs) -* `css` - the path to a precompiled **CSS** file injected into the page. default [assets/layout.css](assets/layout.css) -* `footer` - optional page footer content (html allowed). default **null** -* `lang` - language definition which should be used (available in the `i18n/` directory). default **en_US** +* `template` (type:string) - the path to a custom **EJS** template used to generate the pages. default [assets/template.ejs](assets/template.ejs) +* `css` (type:string) - the path to a precompiled **CSS** file injected into the page. default [assets/layout.css](assets/layout.css) +* `lang` (type:string) - language definition which should be used (available in the `i18n/` directory). default **en_US** +* `payload` (type:object) - additional variables available within the template +* `payload.footer` (type:string) - optional page footer content (html allowed). default **null** +* `filter` (type:function) - filter callback to manipulate the variables before populated within the template +* `onError` (type:function) - simple debug handler to print errors to the console (not to be used in production!) ## koajs Integration ## @@ -203,7 +209,11 @@ const _httpErrorPages = require('http-error-pages'); // because of the asynchronous file-loaders, wait until it has been executed - it returns an async handler _webapp.use(await _httpErrorPages.koa({ lang: 'en_US', - footer: 'Hello World' + payload: { + footer: 'Hello World', + myvar: 'hello world' + } + })); // add other middleware handlers @@ -224,10 +234,13 @@ _webapp.listen(8888); Syntax: `Promise _httpErrorPages.koa([options:Object])` -* `template` - the path to a custom **EJS** template used to generate the pages. default [assets/template.ejs](assets/template.ejs) -* `css` - the path to a precompiled **CSS** file injected into the page. default [assets/layout.css](assets/layout.css) -* `footer` - optional page footer content (html allowed). default **null** -* `lang` - language definition which should be used (available in the `i18n/` directory). default **en_US** +* `template` (type:string) - the path to a custom **EJS** template used to generate the pages. default [assets/template.ejs](assets/template.ejs) +* `css` (type:string) - the path to a precompiled **CSS** file injected into the page. default [assets/layout.css](assets/layout.css) +* `lang` (type:string) - language definition which should be used (available in the `i18n/` directory). default **en_US** +* `payload` (type:object) - additional variables available within the template +* `payload.footer` (type:string) - optional page footer content (html allowed). default **null** +* `filter` (type:function) - filter callback to manipulate the variables before populated within the template +* `onError` (type:function) - simple debug handler to print errors to the console (not to be used in production!) ## Caddy Integration ## @@ -390,7 +403,7 @@ The footer message can easily be changed/removed by editing [config.json](config ```js { // Output Filename Scheme - eg. HTTP500.html - "scheme": "HTTP%d.html", + "scheme": "HTTP%code%.html", // Footer content (HTML Allowed) "footer": "Contact info@example.org" @@ -402,23 +415,49 @@ The footer message can easily be changed/removed by editing [config.json](config ```js { // Output Filename Scheme - eg. HTTP500.html - "scheme": "HTTP%d.html" + "scheme": "HTTP%code%.html" } ``` +### Placeholders/Variables ### + +The following set of variables is exposed to the ejs template (404 page example): + +```js +{ + title: 'Resource not found', + message: 'The requested resource could not be found but may be available again in the future.', + code: '404', + language: 'en', + scheme: 'HTTP%code%.html', + pagetitle: "We've got some trouble | %code% - %title%", + footer: 'Tech Contact info@example.org', + myvar: 'Hello World' +} +``` + +To generate dynamic titles/content based on the current variable set, each variable is exposed as `placeholder` (surrounded by `%`). + +You can also define custom variable within the page definitions, everything is merged togehter. + ### Modify the HTML template ### The HTML template is based on [ejs](https://github.com/mde/ejs) and located in [assets/template.ejs](assets/template.ejs) - you can apply any kind of changes. ```html - +
-<%= message %>
<%= vars.message %>