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

render-json-as-html

v1.4.0

Published

Renders JSON data files using handlebarjs templates into html

Downloads

3

Readme

renderJsonAsHtml

A simple script to render a lot of JSON data files through some handlebars templates to produce a set of static HTML pages. It attempts to only render files that haven't changed based upon the JSON file, Template and HTML's last modified timestamps.

Installation

To install renderJsonAsHtml locally simply use:

npm install render-json-as-html

To install it globally then use the following with an account with permissions to install globally:

npm install -g render-json-as-html

Usage

The following command line options are available:

verbose : Turns on verbose logging (default off)

recursive : Recurse into directories in the JSON data directory rather than just doing the files at the top level of the JSON directory (default off)

srcDir : Specifies the JSON data files source directory (default jsonData)

outputDir : Specifies the directory to put the rendered HTML pages into (default public)

templateDir : Specifies the directory storing the handlebar templates you wish to use (default templates)

assetDir : Specifies the directory storing any assets (css, images, etc) required by the templates (default assets)

global : You can use this to specify additional key value pairs that be available for use in the templates under the _global object (multiple occurances allowed)

JSON Data format

The JSON data in the source directory can be any structure you like, but there are two optional properties that you can set in the JSON data to influence how renderJsonAsHtml will operate:

_template : this can be used to specify the template that you wish to use to render data

_render : if this is set to false then the data won't be rendered (that's the boolean value false, not the string "false").

Additional handlebars helpers

The handlebars engine has the following additional helpers added

renderMarkdown : This will process the field as markdown and insert the resulting HTML into the template

slugify : This will convert the field to a slug format (lowercase alphanumnerics separated by hyphens).

The handlebars engine also has the following additional logic helpers, use them in a subexpression in an if. E.g. {{#if (eq name "fred")}} Welcome Fred {{/if}}

(eq parameter1 parameter2) : checks if parameter1 equals parameter2

(ne parameter1 parameter2) : checks if parameter1 is not equal to parameter2

(lt parameter1 parameter2) : checks if parameter1 is less than parameter2

(gt parameter1 parameter2) : checks if parameter1 is greater than parameter2

(lte parameter1 parameter2) : checks if parameter1 is less than or equal to parameter2

(gte parameter1 parameter2) : checks if parameter1 is greater than or equal to parameter2

(and parameter1 parameter2) : checks if both of its parameters are true

(or parameter1 parameter2) : checks if either of its parameters are true

(not parameter1) : negates parameter1