项目作者: rafaelrinaldi

项目描述 :
Generate HTML meta tags from JSON data.
高级语言: JavaScript
项目地址: git://github.com/rafaelrinaldi/html-meta-tags.git
创建时间: 2017-09-09T21:31:07Z
项目社区:https://github.com/rafaelrinaldi/html-meta-tags

开源协议:MIT License

下载


html-meta-tags Build Status

Generate HTML meta tags from JSON data.

Install

  1. npm install html-meta-tags -g

Usage

CLI

You can either pipe data from the standard input or specify a file path for the program.

  1. $ html-meta-tags
  2. Usage: html-meta-tags <file> [options]
  3. Example:
  4. cat data.json | html-meta-tags
  5. Options:
  6. -v --version Display current program version
  7. -h --help Display help and usage details
  8. --no-charset Do not specify UTF-8 as document charset
  9. --no-og Do not generate Open Graph meta tags
  10. --no-twitter Do not generate Twitter meta tags
  11. $ echo '
  12. {
  13. "title": "My Website",
  14. "url": "https://mywebsite.com",
  15. "keywords": ["blockchain", "infosec", "crypto"],
  16. "description": "This is my personal website"
  17. }' | html-meta-tags
  18. <meta charset="utf-8">
  19. <meta name="title" content="My Website">
  20. <meta name="url" content="https://mywebsite.com">
  21. <meta name="keywords" content="blockchain, infosec, crypto">
  22. <meta name="description" content="This is my personal website">
  23. <meta name="twitter:description" content="This is my personal website">
  24. <meta name="twitter:title" content="My Website">
  25. <meta property="og:description" content="This is my personal website">
  26. <meta property="og:title" content="My Website">

Node.js

  1. var htmlMetaTags = require('html-meta-tags')
  2. var data = require('./data.json')
  3. console.log(htmlMetaTags(data))

API

htmlMetaTags(data, [options])

Returns an HTML string containing a representation of all meta tags from data.

data

Type: Object

Meta tags in object notation format.

  • You can use arrays for comma-separated such as keywords or viewport.
  • If a specific value for a prefixed key is specified it will take precedence over the default.
  • Prefixed keys should have their own entry, og:title for example, should be represented as:
    1. {
    2. og: {
    3. title: 'value'
    4. }
    5. }

options

Type: Object

shouldIgnoreCharset

Type: boolean
Default: false

Whether or not it should render UTF-8 charset meta tag.

shouldIgnoreTwitter

Type: boolean
Default: false

Whether or not it should render Twitter specific meta tags.

shouldIgnoreOpenGraph

Type: boolean
Default: false

Whether or not it should render Open Graph specific meta tags.

License

MIT © Rafael Rinaldi



Buy me a ☕