posthtml-jsonld v0.1.0-2
PostHTML JSON-LD
Import an external file written in JSON-LD format, and insert it with <meta> tags.
Before:
~/index.html
<!DOCTYPE html>
<html>
<head>
<jsonld src="./index.json"></jsonld>
</head>
<body>
</body>
</html>~/index.json
{
"@context": "http://schema.org",
"@type": "Website",
"url": "@/",
"name": "PostHTML JSON-LD",
"description": "PostHTML plugin to import JSON-LD from the external JSON file",
"image": {
"@type": "ImageObject",
"url": "~/assets/images/ogimage.png",
"width": 1200,
"height": 630
}
}After:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>PostHTML JSON-LD</title>
<meta name="description" content="PostHTML plugin to import JSON-LD from the external JSON file">
<meta property="og:type" content="website">
<meta property="og:title" content="PostHTML JSON-LD">
<meta property="og:description" content="PostHTML plugin to import JSON-LD from the external JSON file">
<meta property="og:url" content="https://github.com/seamile4kairi/posthtml-jsonld">
<meta property="og:image" content="https://github.com/seamile4kairi/posthtml-jsonld/assets/images/ogimage.png">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="PostHTML JSON-LD">
<meta name="twitter:description" content="PostHTML plugin to import JSON-LD from the external JSON file">
<meta name="twitter:url" content="https://github.com/seamile4kairi/posthtml-jsonld">
<meta name="twitter:image" content="https://github.com/seamile4kairi/posthtml-jsonld/assets/images/ogimage.png">
<link rel="canonical" href="https://github.com/seamile4kairi/posthtml-jsonld">
<link rel="alternate" media="only screen and (max-width: 560px)" href="https://github.com/seamile4kairi/posthtml-jsonld/sp/">
<link rel="alternate" hreflang="en" href="https://github.com/seamile4kairi/posthtml-jsonld/en/">
<script type="application/ld+json">{"@context":"http://schema.org","@type":"Website","url":"https://github.com/seamile4kairi/posthtml-jsonld","name":"PostHTML JSON-LD","description":"PostHTML plugin to import JSON-LD from the external JSON file","image":[{"@type":"ImageObject","url":"/seamile4kairi/posthtml-jsonld/assets/images/ogimage.png","width":1200,"height":630}]}</script>
</head>
<body></body>
</html>Install
$ npm i -D posthtml posthtml-jsonldUsage
const fs = require('fs');
const posthtml = require('posthtml');
const posthtmlPlugin = require('posthtml-jsonld');
posthtml()
.use(posthtmlPlugin({ /* options */ }))
.process(html/*, options */)
.then(result => fs.writeFileSync('./after.html', result.html));Options
root
String (Default: ./)
The path to the root directory of JSON files.
host
String (Default: http://localhost)
Protocol & hostname of the site.
base
String (Default: /)
Base path of the site.
title
Boolean || Object (Default: false)
WIP. Page tile.
description
Boolean || Object (Default: false)
Page description.
opengraph
Boolean || Object (Default: false)
WIP. Configrations for Open Graph.
twittercards
Boolean || Object (Default: false)
WIP. Configrations for Twitter Card.
canonical
Boolean (Default: false)
Require link[rel="canonical"]?
alternate
Array<Object> (Default: [])
Alternative URLs (link[rel="alternate"]) for the page.
alternate[].href
Function
Required. A function to mutate cannonical URL into alternative URL.
e.g.) url => url.replace(/\/\/www\./, '//ja.')
alternate[].hreflang
alternate[].media
String
Condition to apply alternative URLs.
Contributing
See PostHTML Guidelines and contribution guide.