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

boxedjs

v0.5.2

Published

A simple static HTML templating engine.

Downloads

12

Readme

A simple static HTML templating engine.

npm Package Travis downloads per month

Why?

While working on my personal website, which is just static HTML and CSS, I realised I would need some very basic templating system. I didn't want to clutter the project with too powerful or overly-complicated engines, just to repeat my footer and header in all the pages of the website.

So I wrote this.

NOTE: This is intended as an experiment and nothing more.

Install

npm install -g boxedjs

Create a new project

You can create a project manually or with the project starter option:

boxed create [project-template] [project-name]

in the folder where you want to start a new project.

The available templates are simple-website and simple-blog.

Project structure

The script needs to be run in the root folder of the project and it expects the following project structure:

/
├── src/
    ├── assets/
    ├── pages/
    ├── templates/
├── .boxedrc

where the content of the folders is the following:

  • src/assets: contains all the styling files, images and other files but html.
  • src/pages: contains the pages of your website
  • src/templates: contains the templates used inside the pages

.boxedrc

This file contains the configuration for the project. By default it has the following content:

{
  "name": "Untitled project",
  "folders": {
    "pages": "src/pages",
    "templates": "src/templates",
    "assets": "src/assets",
    "dist": "dist"
  }
}

Feel free to customise it to suit your project structure better.

How to use the templates in a page

Whenever you want to use one of the templates in one of the pages you can require them like the following:

<!-- src/pages/index.html -->
<!DOCTYPE html>
<html>
  <head>
    <title>My templated website</title>
  </head>
  <body>
    [[header]] <!-- Template src/templates/header.html -->
    <div>
      <p>Occaecat eu occaecat cupidatat et in dolore ullamco do dolore laboris magna deserunt in fugiat aute irure occaecat veniam tempor fugiat qui cillum ad aliquip dolore labore pariatur ut dolore est sit minim amet irure.
      </p>
    </div>
    [[footer]] <!-- Template src/templates/footer.html -->
  </body>
</html>

The code above, will result in a page called index.html which will contain the injected content of the templates.

How to create pages and apply templates to them

While the approach above can be enough if you want to build simple, and unique pages, what about more complex cases like a blog post?

Boxedjs allows you to specify pages in different formats (json or yaml) which contains information about a page, which will be then applied to a specific template. To follow the blog example, you could try to create a page like the following:

src/pages/blog-post-1.json

{
  "path": "post-1",
  "template": "post",
  "content": {
    "title": "Blog post 1",
    "author": "Emanuele Libralato",
    "date": "22 September 2017",
    "content": "In do mollit eu magna eairure dolor excepteur et deserunt tempor duis commodo sed eiusmod in ullamco nisi sit eu est occaecat culpa excepteur."
  }
}

and then the template which will be applied to this page:

src/templates/post.html

<!DOCTYPE html>
<html lang="">
  <body>
    <h1 class="text-center">Hello Human! This is a blog post</h1>
    <h1>[[[ title ]]]</h1>
    <h2>[[[ author ]]] - [[[ date ]]]</h2>
    <p>[[[ content ]]]</p>
  </body>
</html>

Boxedjs will generate a page called dist/post-1/index.html. You can find more specific examples in the example folder.

Export

Once you finished writing your HTML, you can just run:

cd root_of_project
boxed

The website will be exported in the dist/ folder.

Watch

You can run boxedjs specifying the option -w or --watch. This will watch the full folder and will build a new version whenever there is a new change.

Examples

The folder examples of this repository contains the output of the two project templates simple-website and simple-blog.