# head-meta-tags

> Simplified management of a document's meta data

Latest version **0.1.1** (published 2018-03-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install head-meta-tags
pnpm add head-meta-tags
yarn add head-meta-tags
bun add head-meta-tags
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2018-03-08 |
| First published | 2018-02-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 14.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Jason Snider |
| Maintainers | jasonsnider |

## Links

- npm: https://www.npmjs.com/package/head-meta-tags
- Repository: https://github.com/jasonsnider/head-meta-tags
- Homepage: https://github.com/jasonsnider/head-meta-tags#readme
- Issues: https://github.com/jasonsnider/head-meta-tags/issues
- npm.io page: https://npm.io/package/head-meta-tags

## Recent versions

- 0.1.1 (latest) — 2018-03-08
- 0.1.0 — 2018-03-08
- 0.0.2 — 2018-03-01
- 0.0.1 — 2018-02-26

## README

# head-meta-tags

[![Build Status](https://travis-ci.org/jasonsnider/head-meta-tags.svg?branch=master)](https://travis-ci.org/jasonsnider/head-meta-tags)

Provides a default configuration of social and traditional html meta tags that can be selectively overridden on a per route basis. Works by replacing ```res.render()``` with a JSON object within the route.

## Configuration

*Full example*

configured to show all possible tags.

```js
var config = {

    // Traditional
    title: 'Hello World',
    description: 'A simple greeting to the world.',
    keywords: 'key, words, keywords',
    canonical: 'https://example.com/some-fancy-slug',

    // Common
    img: { src: '/path/to/image' },
    siteName: 'Example',
    url: 'https://example.com/articles/11',
    
    // schema.org
    schema: true,

    // Twitter
    twitter: {
        //Requires title, description, image to be set
        type: 'summary',
        authorHandle: '@authorHandle',
        pubHandle: '@pubHandle'
    },

    // OpenGraph/Facebook
    og: {
        //Requires title, description, image to be set
        type: 'article'
    }
};
```

*Full example* outputs the following.

```html
<title>Hello World</title>
<meta name="description" content="A simple greeting to the world.">
<meta name="keywords" content="key, words, keywords">
<link rel="canonical" href="https://example.com/some-fancy-slug">
<!-- schema.org -->
<meta itemprop="name" content="Hello World">
<meta itemprop="description" content="A simple greeting to the world.">
<meta itemprop="image" content="/path/to/image">
<!-- Twitter -->
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Hello World">
<meta name="twitter:description" content="A simple greeting to the world.">
<meta name="twitter:creator" content="@authorHandle">
<meta name="twitter:image" content="/path/to/image">
<meta name="twitter:site" content="@pubHandle">
<!-- OpenGraph/Facebook -->
<meta property="og:title" content="Hello World">
<meta property="og:type" content="article">
<meta property="og:url" content="https://example.com/articles/11">
<meta property="og:image" content="/path/to/image">
<meta property="og:description" content="A simple greeting to the world.">
<meta property="og:site_name" content="Example">
```

*Just a title*

Omit a tag to remove it, this is the simplest configuration.

```js
var config = {
    // Traditional
    title: 'Hello World'
};
```

*Just a title* outputs the following.
```html
<title>Hello World</title>
<meta name="description" content="A simple greeting to the world.">
```


## Usage

Provide a configuration object.
```js
var config = {
    title: 'Hello World',
    description: 'A simple greeting to the world.',
}
```

Require head-meta-tags.
```js
var headMetaTags = require('head-meta-tags');
```

Override a selected tag by adding a tags attribute to the reponse object. This should only include the tags you want to override.
```js
app.get('/', function(req, res, next){
    res.data = {
        // Accessible in the view by vars.SOME_VARIABLE_NAME
        vars: {},
        // Override selected tags
        tags: {
            title:'New World',
            description: 'An overriden greeting to the world.'
        },
        // Equates to res.render('index');
        view: 'index'
    };
    next();
});
```

Call headMetaTags with the with the configuration object.
```js
app.use(headMetaTags(config));
```

---
_Source: https://npm.io/package/head-meta-tags · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
