# posthtml-jsonld

> PostHTML plugin to import JSON-LD from the external JSON file

Latest version **0.1.0-2** (published 2019-09-29) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install posthtml-jsonld
pnpm add posthtml-jsonld
yarn add posthtml-jsonld
bun add posthtml-jsonld
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.1.0-2 |
| Published | 2019-09-29 |
| First published | 2019-08-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 20.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Kairi |
| Maintainers | seamile |
| Keywords | posthtml, posthtml-plugin, html, json-ld |

## Links

- npm: https://www.npmjs.com/package/posthtml-jsonld
- Repository: https://github.com/seamile4kairi/posthtml-jsonld
- Homepage: https://github.com/seamile4kairi/posthtml-jsonld#readme
- Issues: https://github.com/seamile4kairi/posthtml-jsonld/issues
- npm.io page: https://npm.io/package/posthtml-jsonld

## Dependencies (1)

- [posthtml](https://npm.io/package/posthtml.md) ^0.11.4

## Alternatives

- [@tsparticles/shape-image](https://npm.io/package/@tsparticles/shape-image.md) — 303.7K weekly downloads
- [@tsparticles/shape-line](https://npm.io/package/@tsparticles/shape-line.md) — 233.7K weekly downloads
- [stringify-attributes](https://npm.io/package/stringify-attributes.md) — 58.6K weekly downloads
- [mobile-drag-drop](https://npm.io/package/mobile-drag-drop.md) — 46.3K weekly downloads
- [@comunica/actor-rdf-parse-html](https://npm.io/package/@comunica/actor-rdf-parse-html.md) — 29.2K weekly downloads

## Recent versions

- 0.1.0-2 (latest) — 2019-09-29
- 0.1.0-1 — 2019-09-21
- 0.1.0-0 — 2019-08-27

## README

# PostHTML JSON-LD <img align="right" width="220" height="200" title="PostHTML logo" src="http://posthtml.github.io/posthtml/logo.svg">

[![NPM][npm]][npm-url]
[![Deps][deps]][deps-url]
[![Build][build]][build-badge]
[![Coverage][cover]][cover-badge]
[![Standard Code Style][style]][style-url]
[![Chat][chat]][chat-badge]

Import an external file written in JSON-LD format, and insert it with ``<meta>`` tags.

### Before:

#### ``~/index.html``
``` html
<!DOCTYPE html>
<html>
<head>
<jsonld src="./index.json"></jsonld>
</head>
<body>
</body>
</html>
```

#### ``~/index.json``
```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:

``` html
<!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

```bash
$ npm i -D posthtml posthtml-jsonld
```


## Usage

``` js
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](https://github.com/posthtml/posthtml/tree/master/docs) and [contribution guide](CONTRIBUTING.md).


## License [MIT](LICENSE)


<!-- Links -->

[npm]: https://img.shields.io/npm/v/posthtml-jsonld.svg
[npm-url]: https://npmjs.com/package/posthtml-jsonld

[deps]: https://david-dm.org/seamile4kairi/posthtml-jsonld.svg
[deps-url]: https://david-dm.org/seamile4kairi/posthtml-jsonld

[style]: https://img.shields.io/badge/code%20style-standard-yellow.svg
[style-url]: http://standardjs.com/

[build]: https://travis-ci.org/seamile4kairi/posthtml-jsonld.svg?branch=master
[build-badge]: https://travis-ci.org/seamile4kairi/posthtml-jsonld?branch=master

[cover]: https://coveralls.io/repos/seamile4kairi/posthtml-jsonld/badge.svg?branch=master
[cover-badge]: https://coveralls.io/r/seamile4kairi/posthtml-jsonld?branch=master


[chat]: https://badges.gitter.im/seamile4kairi/posthtml-jsonld.svg
[chat-badge]: https://gitter.im/seamile4kairi/posthtml-jsonld?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge"

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