Skip to content

Commit

Permalink
feat(meta): add twitter card, site and creator properties (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
manniL authored and pi0 committed Mar 8, 2018
1 parent 3990ddf commit fe11c76
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
13 changes: 13 additions & 0 deletions docs/modules/meta.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,19 @@ These types are accepted:
- Default: ogHost (if defined)
- Meta: `og:url`


**twitterCard**
- Default: `undefined`
- Meta: `twitter:card

**twitterSite**
- Default: `undefined`
- Meta: `twitter:site

**twitterCreator**
- Default: `undefined`
- Meta: `twitter:creator`

**nativeUI**
- Default: `false`

Expand Down
20 changes: 19 additions & 1 deletion packages/meta/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ function generateMeta (_options) {
ogDescription: true,
ogImage: true,
ogHost: undefined,
ogUrl: true
ogUrl: true,
twitterCard: undefined,
twitterSite: undefined,
twitterCreator: undefined
}

// Combine sources
Expand Down Expand Up @@ -204,6 +207,21 @@ function generateMeta (_options) {
debug('No host specified, skipping og:image')
}
}

// twitter:card
if (options.twitterCard && !find(this.options.head.meta, 'property', 'twitter:card') && !find(this.options.head.meta, 'name', 'twitter:card')) {
this.options.head.meta.push({ hid: 'twitter:card', name: 'twitter:card', property: 'twitter:card', content: options.twitterCard })
}

// twitter:site
if (options.twitterSite && !find(this.options.head.meta, 'property', 'twitter:site') && !find(this.options.head.meta, 'name', 'twitter:site')) {
this.options.head.meta.push({ hid: 'twitter:site', name: 'twitter:site', property: 'twitter:site', content: options.twitterSite })
}

// twitter:creator
if (options.twitterCreator && !find(this.options.head.meta, 'property', 'twitter:creator') && !find(this.options.head.meta, 'name', 'twitter:creator')) {
this.options.head.meta.push({ hid: 'twitter:creator', name: 'twitter:creator', property: 'twitter:creator', content: options.twitterCreator })
}
}

module.exports.meta = require('./package.json')

0 comments on commit fe11c76

Please sign in to comment.