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

@page-libs/static-generator

v1.1.3

Published

Static generator for Page framework.

Downloads

14

Readme

page-static-generator

NPM Version Build Status codecov

Static generator for Page framework (based on 'cuties' libs and Async Tree Pattern).

Install

npm install @page-libs/static-generator

Run test

npm test

Run build

npm run build

Usage

const {
  // Needed async objects here from the table below  
} = require('@page-libs/static-generator');

| Async Object | Description | Parameters(default value/description) | Representation result | | ------------- | ----------------| ---------- | --------------------- | | Base | Creates base tag | href, attrs(string like 'attr="value"') | <base href=${href} ${attrs}> | | Body | Creates body tag | attrs(string like 'attr="value"'), ...elms(elements inside of body tag) | <body ${attrs}>${elms.join('')}</body> | | Head | Creates head tag | ...elms(elements inside of head tag) | <head>${elms.join('')}</head> | | Link | Creates link tag | attrs(string like 'attr="value"') | <link ${attrs}> | | Meta | Creates meta tag | attrs(string like 'attr="value"') | <meta ${attrs}> | | NoScript | Creates noscript tag | text | <noscript>${text}</noscript> | | Page | Creates html tag | attrs(string like 'attr="value"'), head, body | <!DOCTYPE html>\n<html ${attrs}>${head}${body}</html>\n | | PrettyPage | Makes page pretty | page | Pretty html document(page) | | SavedPage | Saves page to the specified file(as path) | path, page | file(as path) | | Script | Creates script tag(for head tag) | src, attrs(string like 'attr="value"') | <script src="${src}" ${attrs}></script> | | Style | Creates link tag with rel="stylesheet | href, attrs(string like 'attr="value"') | <link rel="stylesheet" href="${href}" ${attrs}> | | Template | Read html as string from the specified file(as path) | path | html string | | TemplateWithParams | Replace all placeholders in a template with the specified ...params | template, ...params | html string | | Title | Creates title tag | text | <title>${text}</title> |

Example

Let's say we have templates: outer.html, inner.html:

<!-- outer.html -->
<div class="outer">
   {{ text }}
  <div class="place-for-inner-template">
    {{ innerTemplate }}
  </div>
</div>
<!-- inner.html -->
<div class="inner">
   {{ text }}
</div>

Then we can create a page that contains these templates:

'use strict'

const {
  SavedPage,
  PrettyPage,
  Page,
  Head,
  Body,
  Script,
  Style,
  TemplateWithParams,
  Template
} = require('@page-libs/static-generator');

new SavedPage(
  'page.html', 
  new PrettyPage(
    new Page(
      'xmlns="http://www.w3.org/1999/xhtml" lang="en"',
      new Head(
        new Script('script1.js', 'type="text/javascript"'),
        new Script('script2.js', 'type="text/javascript"'),
        new Style('main.css', 'type="text/css"'),
        new Style('mobile.css', 'type="text/css"')
      ),
      new Body(
        'class="main"',
        new TemplateWithParams(
          new Template('outer.html'),
          'text in outer template',
          new TemplateWithParams(
            new Template('inner.html'),
            'text in inner template'
          )
        )
      )
    )
  )
).call();

The result is

<!-- page.html -->
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">

  <head>
    <script src="script1.js" type="text/javascript"></script>
    <script src="script2.js" type="text/javascript"></script>
    <link rel="stylesheet" href="main.css" type="text/css">
    <link rel="stylesheet" href="mobile.css" type="text/css">
  </head>

  <body class="main">
    <div class="outer">
      text in outer template
      <div class="place-for-inner-template">
        <div class="inner">
          text in inner template
        </div>

      </div>
    </div>
  </body>

</html>

Full example is here.