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

rest2static

v0.10.0

Published

Pull data from REST API and generate static HTML content.

Downloads

1

Readme

REST -> Static

A simple way to add static pages to your website by generating them from a REST API call(or many). If your website is done as a Web App for qualified users, you might still want to expose some of the content within as public web pages.

So as part of your build process, you pull data from REST API and generate static HTML content using Handlebars templates.

Put a configuration in your package.json.

{
  "scripts": {
    "generate": "rest2static"
  },
  "rest2static": {
    "root": "./dist",
    "partials": "./src",
    "https://...": {
      "method": "GET",
      "scan": [
        {
          "key": "key",
          "title": "title"
        }
      ],
      "template": "./src/template.hbs",
      "url": "/lib/{{ key }}/"
    }
  }
}

You can now run npm run generate to pull down and generate from the URL you've defined in the configuration.

Configuration

The configuration can be embedded in package.json or put in a separate file. By default rest2static will look up the entry in package.json. It expects a string or an object. Specify a string with the config file name relative to the project directory if you want to keep a separate config file.

[TODO: You can use multiple configurations by passing the path to the config file as a parameter to the command.] [TODO: In addition to .json format, you write the config file as a .config.js file. In this case it must be a valid node module that exports the config object.]

root The document root where sitemap and pages are written to. index sitemap changefreq. partials helpers assets

method scan template url

REST Data -> Page

When rendering a page the template is combined with a flat set of data. All string values in the scan object graph are treated as the name under which they are found in the data passed to the template. If you want a field to exist under more than one name, provide both names separated by space. If you want a default value append = followed by the default value. The location of the page can also be found in the data as filepath and url.

If an assets file is declared, the contents are provided as data to the page as well.

assets integration

If you use webpack to generate the main site files, the bundles will probably gain a unique name in production builds. So the URLs for CSS and JS resources keep changing. You can use npm assets-webpack-plugin module to export the bundle names to a JSON file. The URLs can then be included in the rest2static generation by declaring assets in the config file.

Debugging

As a not VS Code has pretty decent debugging support. As an example here is the launch.json for debugging the tests.

    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Launch Specs",
            "program": "${workspaceRoot}/node_modules/jasmine/bin/jasmine.js",
            "args": [
                "${workspaceFolder}/flatten.spec.js"
            ],
            "env": {
                "NODE_PATH": "."
            }
        }
    ]