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

oxirane

v0.0.1

Published

A zero-configuration static site generator

Downloads

5

Readme

A bare-bones, zero-configuration static site generator forked from tinyjam and modified for my own use case. Essentially a tiny, elegant glue between EJS templates and Markdown with freeform structure (enabling incremental adoption) and convenient defaults, written in under 120 lines of JavaScript.

Example

# source directory
├── posts
│   ├── 01.md
│   ├── 02.md
│   └── item.ejs
├── _header.ejs
└── index.ejs

# output
├── posts
│   ├── 01.html
│   └── 02.html
└── index.html

An example template:

<%- include('_header.ejs') %>

<% for (const [name, {date, title}] of Object.entries(posts)) { %>
    <h3><%= date.toDateString() %>: <a href="posts/<%= name %>.html"><%= title %></a></h3>
<% } %>

Browse the full example.

Documentation

Getting started

npx oxirane source_dir output_dir

Oxirane doesn't impose any folder structure, processing any data files (*.md and *.yml) and templates (*.ejs) it encounters and copying over anything else.

Data files

All *.md and *.yml files inside the working directory are interpreted as data, available for any templates all at once as JavaScript objects. For example, given the following folder structure:

├── posts
│   ├── 01.md
│   ├── 02.md
├── data.yml
└── about.md

A template in this folder will have the contents available as:

posts: {
  "01": {title: "First post", date: new Date("2020-02-20"), body: "Hello world"},
  "02": {title: "Second post", date: new Date("2020-02-21"), body: "Hello there"}
},
data: {author: "Vladimir Agafonkin"},
about: {body: "This is an awesome blog about me."}

Markdown is rendered according to the GitHub Flavored Markdown specification.

Templates

Oxirane uses EJS (through yeahjs, a fast EJS subset), a templating system where you can use plain JavaScript, so it's both powerful and easy to learn. All *.ejs files it encounters are rendered with the collected data in the following way:

  • <filename>.ejs files are rendered as <filename>.html.
  • item.ejs has a special meaning: all data files in the same folder (e.g. <filename>.md) are rendered with this template as <filename>.html with the corresponding file's data.
  • Templates starting with _ (e.g. _header.ejs) are skipped (to be used as EJS includes).
  • Templates are rendered as html by default, but you can use other extensions, e.g. main.css.ejs will be rendered as main.css.

In addition to the collected data, templates have access to the following properties:

  • rootPath is a relative path to the root of the project — useful as a prefix for links in includes as they may be used on different nesting levels (e.g. <%= rootPath %>/index.css).
  • root references all of the project's data, which is useful for accessing data in includes or outside of the current template's folder.

Command line

Install with NPM to use oxirane as a CLI: npm install -g oxirane. Usage:

oxirane source_dir [output_dir] [--breaks] [--smartypants] [--silent]
  • --breaks: Add single line breaks as <br> in Markdown.
  • --smartypants: Convert quotes, dashes and ellipses in Markdown to typographic equivalents.
  • --silent: Run silently (unless there's an error).

If output_dir is not provided, it's assumed equal to source_dir. This is useful for incrementally converting static sites without changing deployment folders.

Node.js API

import oxirane from "oxirane";

oxirane(sourceDir, outputDir, {
  log: false, // log the progress (like in the CLI)
  breaks: false, // Markdown: add single line breaks (like in GitHub comments)
  smartypants: false, // Markdown: convert quotes, dashes and ellipses to typographic equivalents
  highlight: null, // a code highlighting function: (code, lang) => html
});

Note that the project only supports Node v12.17+.

FAQ

Why build yet another static site generator?

I wanted to add some templating to my personal static websites to make them easier to maintain (e.g. my band's album page, which is pure HTML/CSS/JS), but never found a static site generator that would be simple and unobtrusive enough for my liking.

A tool I envisioned would not involve meticulous configuration, special folder structure, reading through hundreds of documentation pages, bringing in a ton of dependencies, or making you learn a new language. At the same time, it would be flexible enough to make multilingual websites without plugins and convoluted setup.

Ideally, I would just rename some html files to ejs, move some content to Markdown files, add light templating and be done with it. So I decided to build my own minimal tool for this, but will be happy if anyone else finds it useful.

Can you add <feature X>?

Sorry — probably not, unless it fits the concept of a minimal, zero-configuration tool.

How fast is Oxirane?

Pretty fast. I didn't see a point in benchmarking because most of the time is spent parsing Markdown/YAML and rendering EJS anyway, but corresponding dependencies (marked, js-yaml, yeahjs) are very well optimized.

Why EJS for templating, and can I use another templating system?

EJS is also an extremely simple, minimal system, and it allows you to use plain JavaScript for templates, making it pretty powerful with almost no learning curve. To make it even faster, I crafted my own implementation (yeahjs). No plans to support other template engines.

How do I make a reactive single-page app with dynamic routing, hydration, bundle splitting and service worker caching?

There's no need for all that in a static website. If you do have a case for it, you'll need a different tool.

How do I make a multilingual website?

Oxirane gives you freedom to approach this in many different ways, but here's an example:

en.ejs: <%- include('_content.ejs', {lang: 'en'}) %>
fr.ejs: <%- include('_content.ejs', {lang: 'fr'}) %>
_content.ejs: <%= content[lang].body %> (use either content/en.md or content/fr.md)

How do I add pagination?

At the moment, you can't. It's not a great UI pattern anyway — make an archive page with links to all content instead.

How do I do asset optimization, CSS preprocessing, TypeScript transpilation, etc.?

Do all the preprocessing in the source directory prior to running oxirane.

How do I add code syntax highlighting?

Here's an example using the oxirane API with highlight.js:

import oxirane from "oxirane";
import { highlight } from "highlight.js";

oxirane(sourceDir, outputDir, {
  highlight: (code, lang) => highlight(lang, code).value,
});