Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/eden-js/meta
https://github.com/eden-js/meta
Last synced: 27 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/eden-js/meta
- Owner: eden-js
- Created: 2018-11-01T05:26:11.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2022-04-09T22:51:42.000Z (over 2 years ago)
- Last Synced: 2024-11-18T11:26:10.958Z (about 1 month ago)
- Language: TypeScript
- Size: 347 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# EdenJS - Meta
[![TravisCI](https://travis-ci.com/eden-js/meta.svg?branch=master)](https://travis-ci.com/eden-js/meta)
[![Issues](https://img.shields.io/github/issues/eden-js/meta.svg)](https://github.com/eden-js/meta/issues)
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/eden-js/meta)
[![Awesome](https://img.shields.io/badge/awesome-true-green.svg)](https://github.com/eden-js/meta)
[![Discord](https://img.shields.io/discord/583845970433933312.svg)](https://discord.gg/5u3f3up)Meta base logic component for [EdenJS](https://github.com/edenjs-cli)
`@edenjs/meta` automatically adds middleware functions for metatag generation.
## Setup
### Install
```
npm i --save @edenjs/meta
```### Hooks
#### `sitemap` _[Usage](https://github.com/eden-js/meta/blob/master/bundles/meta/controllers/meta.js#L96)_
The sitemap hook allows you to add things to the global sitemap. _[Usage](https://github.com/eden-js/shop/blob/master/bundles/product/controllers/product.js#L49)_
```js
// pre sitemap
this.eden.pre('sitemap', async (map) => {
// get products
const products = await Product.find({
published : true,
});// get categories
await Promise.all(products.map(async (product) => {
// add to eden
map.urls.push({
url : `/product/${product.get('slug')}`,
img : await Promise.all((await product.get('images') || []).map(async (image) => {
// return image
return {
url : await image.url('md-sq'),
title : product.get('title.en-us'),
caption : image.get('name'),
license : 'https://creativecommons.org/licenses/by/4.0/',
};
})),
lastmod : product.get('updated_at'),
priority : 0.8,
changefreq : 'daily',
});
}));
});
```This can also be done in a build function. _[Usage](https://github.com/eden-js/shop/blob/master/bundles/product/controllers/product.js#L49)_
```js
/**
* order individual item
*/
const build = () => {
// get categories
(await Product.find({
published : true,
})).map(async (product) => {
// add to eden
// this.eden must be in a controller/daemon extended the core daemon/controller
this.eden.sitemap.add({
url : `/product/${product.get('slug')}`,
img : await Promise.all((await product.get('images') || []).map(async (image) => {
// return image
return {
url : await image.url('md-sq'),
title : product.get('title.en-us'),
caption : image.get('name'),
license : 'https://creativecommons.org/licenses/by/4.0/',
};
})),
lastmod : product.get('updated_at'),
priority : 0.8,
changefreq : 'daily',
});
});
}
```### Functions
#### `res.meta` _[Usage](https://github.com/eden-js/meta/blob/master/bundles/meta/controllers/meta.js#L180)_
```js
/**
* test action
*
* @route {GET} /test
*/
testAction(req, res) {
// add meta tag
res.meta('name', 'content'); // translates to
}
```#### `res.og` _[Usage](https://github.com/eden-js/meta/blob/master/bundles/meta/controllers/meta.js#L223)_
```js
/**
* test action
*
* @route {GET} /test
*/
testAction(req, res) {
// add meta tag
res.og('image', 'https://image.com/image.png', 'image'); // translates to
}
```#### `res.article` _[Usage](https://github.com/eden-js/meta/blob/master/bundles/meta/controllers/meta.js#L240)_
```js
/**
* test action
*
* @route {GET} /test
*/
testAction(req, res) {
// add meta tag
res.article('image', 'https://image.com/image.png', 'image'); // translates to
}
```#### `res.twitter` _[Usage](https://github.com/eden-js/meta/blob/master/bundles/meta/controllers/meta.js#L257)_
```js
/**
* test action
*
* @route {GET} /test
*/
testAction(req, res) {
// add meta tag
res.twitter('image', 'https://image.com/image.png', 'image'); // translates to
}
```#### `res.title` _[Usage](https://github.com/eden-js/meta/blob/master/bundles/meta/controllers/meta.js#L274)_
```js
/**
* test action
*
* @route {GET} /test
*/
testAction(req, res) {
// add meta tag
res.title('Page Title'); // translates to Page Title as well as all appropriate meta tags
}
```#### `res.description` _[Usage](https://github.com/eden-js/meta/blob/master/bundles/meta/controllers/meta.js#L299)_
```js
/**
* test action
*
* @route {GET} /test
*/
testAction(req, res) {
// add meta tag
res.description('Page Description'); // translates to as well as all appropriate meta tags
}
```#### `res.image` _[Usage](https://github.com/eden-js/meta/blob/master/bundles/meta/controllers/meta.js#L328)_
```js
/**
* test action
*
* @route {GET} /test
*/
testAction(req, res) {
// add meta tag
res.image('https://image.com/image.png', 100, 100); // translates to
}
```