npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

posthtml-jsonld

v0.1.0-2

Published

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

Downloads

3

Readme

PostHTML JSON-LD

NPM Deps Build Coverage Standard Code Style Chat

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-jsonld

Usage

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.

License MIT