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

antedate

v1.0.0

Published

pre-render static websites with ease

Downloads

24

Readme

Antedate

Pre-render static websites with ease.

Antedate is a simple API and CLI that uses Chrome pupeteer to pre-render client-side websites. It automatically spins up a local server and renders each route provided.

Install

$ npm install antedate

Usage

You can either use the API or CLI.

$ antedate render -r /home -r /about
import antedate from 'antedate'

const routes = ['/', '/about', '/contact'];
const site = './site';

await antedate(site, routes);
// => [
//      { html: '....', route: '/', path: '/index.html' },
//      { html: '....', route: '/about', path: '/about.html' }
//      ...
// ]

await antedate(site, routes, { headless: false, dirs: true });
// => [
//      { html: '....', route: '/', path: '/index.html' },
//      { html: '....', route: '/about', path: '/about/index.html' }
//      ...
// ]

CLI

The module also comes with an CLI

  Description
    Pre-render the routes given

  Usage
    $ antedate render [options]

  Options
    -s, --selector    Wait for the following selector before rendering
    -w, --wait        MS to wait before saving page. Happens after selector wait
    -r, --route       Prerender the route specified
    -d, --dir         Directory containing the static site  (default .)
    -o, --output      Output directory  (default ./static)
    -h, --help        Displays this message

  Examples
    $ antedate render -r /home -r /about

API

antedate(root, routes, opts?)

Returns: Array

Returns a rendering function that will optionally accept a date value as its only argument.

root

Type: String Required: true

Path to the directory containing the static site to pre-render. Antedate automatically starts a local server.

routes

Type: Array Required: true

Array of routes to be rendered. The root / is always rendered last. E.g. ['/about', '/contact', '/'].

opts

Type: Object Required: false

headless

Type: Boolean Default: false

Wether to run puppeteer in headless mode.

selector

Type: String Default: ``

Wait for selector to appear before rendering the site. E.g. body.prerender.

wait

Type: Number Default: ``

Milliseconds to before rendering the site.

OBS: This happens after the selector option if both are provided.

script

Type: Function Default: ``

A callback function to execute on the page before the rendering happens.

decorator

Type: Function Default: ``

A decorator function that allows you to manupulate the rendered HTML string.

await antedate(site, routes, { decorator: html => html.toUpperCase()});

Credit

The idea and logic is based on code from PWA by Luke Edwards. See original implementation in build.js in @pwa/cli.

License

MIT License @ Terkel Gjervig