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 🙏

© 2025 – Pkg Stats / Ryan Hefner

posthtml-head-elements

v0.5.1

Published

Build HTML head elements from a JSON file

Readme

posthtml-head-elements

Build Status devDependency Status npm version Coverage Status

This plugin is intended to work with PostHTML. It will allow you to keep HTML head elements - title, script, link, base and meta - in a separate JSON file:

{
  "meta": [
    {
      "charset": "utf-8"
    },
    {
      "http-equiv": "X-UA-Compatible",
      "content": "IE=edge"
    },
    {
      "name": "description",
      "content": "A front-end template that helps you build fast, modern mobile web apps."
    },
    {
      "name": "viewport",
      "content": "width=device-width, initial-scale=1"
    }
  ],
  "title": "Web Starter Kit",
  "link": [
    {
      "rel": "manifest",
      "href": "manifest.json"
    },
    {
      "rel": "icon",
      "sizes": "192x192",
      "href": "images/touch/chrome-touch-icon-192x192.png"
    }
  ],
  "script": [
    {
      "src": "//cdn.polyfill.io/v1/polyfill.min.js"
    }
  ],
  "base": [
    {
      "href": "/"
    }
  ]
}

A custom tag, which signifies where the HTML head elements should be inserted during the build process, needs to be placed in the document head:


<!doctype html>
<html lang="en">
<head>

  <posthtml-head-elements></posthtml-head-elements>

  <!-- Add to homescreen for Chrome on Android -->
  <meta name="mobile-web-app-capable" content="yes">
  <meta name="application-name" content="Web Starter Kit">

This is then configured like below if you are using gulp-posthtml. Please read the PostHTML GitHub page for plugin configuration guidelines.


var posthtml = require('gulp-posthtml');
var gulp = require('gulp');
var jsonPath = '/data/posthtml-head-elements.json';

gulp.task('posthtml', function() {

  var plugins = [
    require('posthtml-head-elements')({headElements: jsonPath})
  ];

  return gulp.src('/app/index.html')
    .pipe(posthtml(plugins))
    .pipe(gulp.dest('/build/'));

});

Note that the HTML head elements are inserted into the document in the spatial order they are laid out - from top to bottom

It is possible to mix the head elements, but the JSON syntax requires a unique key. Therefore, if you are using more than one head element, place an underscore immediately afterwards.

An example of a JSON file with multiple head elements:

{
  "meta": [
    {
      "charset": "utf-8"
    },
    {
      "http-equiv": "X-UA-Compatible",
      "content": "IE=edge"
    },
    {
      "name": "description",
      "content": "A front-end template that helps you build fast, modern mobile web apps."
    },
    {
      "name": "viewport",
      "content": "width=device-width, initial-scale=1"
    }
  ],
  "title": "Web Starter Kit",
  "link": [
    {
      "rel": "manifest",
      "href": "manifest.json"
    }
  ],
  "meta_1": [
    {
      "name": "mobile-web-app-capable",
      "content": "yes"
    },
    {
      "name": "application-name",
      "content": "Web Starter Kit"
    }
  ],
  "link_1": [
    {
      "rel": "icon",
      "sizes": "192x192",
      "href": "images/touch/chrome-touch-icon-192x192.png"
    }
  ],
  "meta_2": [
    {
      "name": "apple-mobile-web-app-capable",
      "content": "yes"
    },
    {
      "name": "apple-mobile-web-app-status-bar-style",
      "content": "black"
    },
    {
      "name": "apple-mobile-web-app-title",
      "content": "Web Starter Kit"
    }
  ],
  "link_2": [
    {
      "rel": "apple-touch-icon",
      "href": "images/touch/apple-touch-icon.png"
    }
  ],
  "meta_3": [
    {
      "name": "msapplication-TileImage",
      "content": "mages/touch/ms-touch-icon-144x144-precomposed.png"
    },
    {
      "name": "msapplication-TileColor",
      "content": "3372DF"
    },
    {
      "name": "theme-color",
      "content": "#3372DF"
    }
  ],
  "link_3": [
    {
      "rel": "stylesheet",
      "href": "styles/main.css"
    }
  ]
}