Name: koa-meta
Owner: Lad
Description: SEO
Created: 2017-09-09 19:28:28.0
Updated: 2018-05-23 03:39:20.0
Pushed: 2017-12-15 11:39:21.0
Homepage: https://lad.js.org
Size: 158
Language: JavaScript
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
Meta
<title>
and<meta name="description">
middleware for Koa and Lad
npm:
install koa-meta
yarn:
add koa-meta
Use middleware:
t Meta = require('koa-meta');
...
t meta = new Meta({
': [ 'Home', 'Our home page description' ],
contact', [ 'Contact', 'Contact us with questions' ]
use(meta.middleware);
use((ctx, next) => {
since the previous middleware was defined before this
the `ctx.state` object has been populated with metadata
nsole.log('ctx.state.meta', ctx.state.meta);
for a request with `ctx.path` of `/` it will output:
{ title: 'Home', description: 'Our home page description' }
Therefore in your views you can render the meta data easily:
ype html
ad
title= meta.title
meta(name="description", content=meta.description)
Get a meta translation:
t Meta = require('koa-meta');
t meta = new Meta({
': [ 'Home', 'Our home page description' ],
posts': [ 'Posts', 'Posts by our team' ]
ole.log(meta.getByPath('/posts/123456'));
{ title: 'Posts', description: 'Posts by our team' }`
This package supports translation out of the box.
It checks for a function set on ctx.req.t
and utilizes that function to translate based off the request's locale.
This package supports parent meta data lookup for children of paths.
This means if you define in your configuration a path of /posts
and a request is made to /posts/123456
(with this path not being defined in your configuration), then it will use /posts
definition for /posts/123456
.
By default this package will throw an error if a child path was found that does not have a parent defined.
This is extremely useful for retaining quality control with your configuration.
| Name | Website | | ————– | ————————– | | Nick Baugh | http://niftylettuce.com/ |