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

kazooie

v0.2.8

Published

a minimal static site generator in node

Downloads

1

Readme

kazooie

A minimal static site generator in node.

kazooie is more than your avegerage static site generator. It let's you implement any logic you need, in a framework of your choice - or none - and compiles into static HTML. You build tasks - JS functions, really - that return whatever should be placed inside your templates. Inside your tasks (functions), you can utilize any npm module or framework, as long as the return value can be put into your templates directly. This modularity allows you to reuse tasks easily and keeps the actual build step simple and reliable. It also allows you to exchange frameworks or logic without touching anything but your taskfiles.

As the project grows, it is planned to collect tasks that can easily be plugged into your project, such as:

  • Blogroll from filesystem
  • Getting data from APIs or CMS
  • Using components from frameworks such as react/vue

(see example folder for those)

Installation

$ npm i -g kazooie

Usage

  • $ kazooie init will set up your basic folder structure with src, public and tasks folders
  • $ kazooie build will compile your templates and tasks into static html files inside public

Let's say you're looking to replace {{ timestamp }} with an actual Date.now(), inside your src/index.html:

  1. You'd make a task called tasks/timestamp.js. The file has to expose a function named just like the placeholder → timestamp() !
  2. That function has to return something, eg. the current date:
function timestamp {
  return Date.now();
}
  1. Run $ kazooie build to create the compiled index.html in your public folder → You're done ✨

Helper functions

You can declare 'helper' functions in your taskfiles that start with an underscore and are exectuted without any palceholder 'calling' it. That means they don't have to return anything and do not replace anything by default. This makes them perfect for handling functionality not directly tied to your templates, such as creating a sitemap.xml, moving files, compiling, etc. For example tasks/helpers.js:

_helper = function() {
  console.log("I'm always executed!");
}

Notes:

  • Filenames can be whatever you like actually, as all taskfiles will be required and every exposed function will be available during the build step
  • One taskfile may expose more than one function
  • The {{placeholder}} will be replaced by the return value of the corresponding function with the same name! (in this case function placeholder() {...})
  • Placeholders and functions can be called with one argument, to give context in your tasks. For example getPosts(lastest) and getPosts(all) → no need for inverted commas, string by default

See the examples for more.

Default folder structure

 <your project>
   ├── public           # Your compiled files go here
   ├── src              # Your uncomiled templates are here
   |  ├── index.html    # This is where {{blogroll}} will be replaced
   └── tasks
       ├── blogroll.js     # Given the file contains a function called blogroll(),
                           # this will return the replacement for {{blogroll}}

You may replace this with your own structure, defined in kazooie-config.js as follows. To use a config file, you have to invoke the process with the -c flag (and specify the path).

module.exports = {
  src: `${__dirname}/src`,
  output: `${__dirname}/public`,
  taskFolder: `${__dirname}/tasks`
}

Under the hood:

  • The build step will simply replace your {{placeholder}} with the return value of your corresponding function, so you may need to add markup in the task already
  • Currently all files in src are being compiled (rewritten to public), even if there is no placeholder to be replaced.
  • Your tasks may return a promise, which will be resolved during the build step
  • Taskfiles are nothing but regular JavaScript. You might even require and use node modules or different frameworks inside the different files.

License

Licensed under the MIT License