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

portatheme

v0.3.0

Published

Small, opinionated theme bundler

Downloads

5

Readme

portatheme

Small, opinionated theme bundler

Travis npm

Installation

npm install portatheme

Setup

A theme has these features:

  • A set of layouts, which are Pug templates. Every theme must have at least one layout called default.pug.
  • Sass compilation using node-sass and Eyeglass.
  • JavaScript compilation and bundling using Webpack with Babel support.
  • Static asset copying.

A minimal theme is structured like this:

- theme/
  - assets/
  - js/
    - index.js
  - sass/
    - index.scss
  - templates/
    - default.pug

Let's break it down.

  • assets includes static assets like images and fonts.
  • js includes JavaScript required by your theme.
  • sass includes Sass required by your theme.
  • templates includes Pug templates that will render pages.

Static assets placed at the root of the theme, such as a robots.txt, will also be copied.

Only the templates folder is required, and the only required file in that folder is default.pug. All other features‐static files, Sass, and JavaScript—are optional.

Usage

import Theme from 'portatheme';

// Initialize the theme with a file path
// The theme can be in node_modules or a local folder
const catTheme = new Theme('./cat-theme');

// Set an output folder for pages and theme assets
catTheme.outputTo('./dist');

// Create a page by passing a file name and data object
catTheme.compilePage('index.html', { title: 'Home' }).then(() => console.log('Page built.'));

// Compile theme assets (static files, Sass, and JavaScript)
catTheme.build().then(() => console.log('Assets compiled.'))

Inheritance

A theme can inherit the layouts, assets, Sass, and JavaScript of another theme. Here's how it works:

  • Any layout in a theme or its parents can be used. If a child theme has a layout with the same name as a parent theme, the child layout will be used.
  • All static assets are combined together and copied to the final build folder.
  • The child Sass files can import the parent theme's Sass using @import '<parent theme>';, where <parent theme> is the folder name of the parent theme.
  • The child JavaScript files can import the parent theme's JavaScript using require('<parent theme>'); or import '<parent theme>';.

Note that if a parent theme has Sass or JavaScript features, the child theme must import the parent theme's files for them to be compiled.

Here's what theme inheritance looks like:

import Theme from 'portatheme';

const catTheme = new Theme('cat-theme');
const kittenTheme = new Theme('./lib/kitten-theme', catTheme);

// Any layout in cat-theme/ or kitten-theme/ can be referenced
kittenTheme.compilePage('index.html', {}, 'catLayout');

If cat-theme/ has a Sass codebase, kitten-theme/ can import those files:

@import 'cat-theme';

It works the same with JavaScript:

import 'cat-theme';

API

new Theme(location[, parent])

Create a new theme.

  • location (String): path to theme folder. Should be an absolute path, or relative to the current working directory.
  • parent (Theme): Optional. Theme to inherit assets from.

Theme.outputTo(location)

Define the output folder when building theme assets and pages. Call this before using other theme methods.

  • location (String): path to output to.

Theme.compilePage(dest[, data, layout])

Create a page using one of the theme's layouts, paired with a data object.

  • dest (String): name of file to output, e.g. index.html. The path is relative to the root folder set with Theme.outputTo().
  • data (Object): object to pass to Pug template.
  • layout (String): theme template to use. Defaults to default.

Returns a Promise which resolves when the page has been written to disk, or rejects if there's an error.

Theme.compileString([data, layout])

Create an HTML string using one of the theme's layouts, paired with a data object.

  • data (Object): object to pass to Pug template.
  • layout (String): theme template to use. Defaults to default.

Returns an HTML string.

Theme.build()

Build the assets of a theme: static files, CSS, and JavaScript.

Returns a Promise which resolves when the build process is done, or rejects if there's an error.

Theme.buildAndWatch()

Build the assets of a theme, then watch for changes to theme files and rebuild when necessary.

Returns a Promise which rejects if there's an error. The Promise will never resolve, because file watching goes on indefinitely.

Local Development

git clone https://github.com/spacedoc/portatheme
cd portatheme
npm install
npm test

License

MIT © Geoff Kimball