koa-head
A document head manager middleware for koa.
Installation
npm i koa-head
TL;DR example
note: this package can be used as native ES6 module but has fallback to CommonJS require
.
;; const app = ; app ; app;
will make documentHead
variable to contain:
Title for my webpage
so you can use it in a place in your layout.
Available methods
.setTitle( string | object )
Set document title.
.addMetaTag( object )
Add <meta />
tag.
.addLink( object )
Add <link />
tag.
.addStyle( string | object )
Add <style />
tag.
.addScript( string | object )
Add <script />
tag.
.toHtml()
Render all set content to coresponding HTML tags.
Middleware factory function config
Option | Description | Default value |
---|---|---|
ctxNamespace |
Name under which middleware is exposed in cxt object and is used by other middlewares i.e. ctx.documentHead.setTitle('Hello') . |
'documentHead' |
stateNamespace |
Name under which middleware stores values in ctx.state |
'documentHead' |
documentTitleFormatter |
If set, all values passed to .setTitle() function will pe parsed by this formatter. |
title => title |
toHtml |
Config for toHtml function. | { [default_values] } |
toHtml.tagSeparator |
Separator between tags inside one group. | \n |
toHtml.groupSeparator |
Separator between group of tags. | \n\n |