kazooie
v0.2.8
Published
a minimal static site generator in node
Downloads
1
Maintainers
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 withsrc
,public
andtasks
folders$ kazooie build
will compile your templates and tasks into static html files insidepublic
Let's say you're looking to replace {{ timestamp }}
with an actual Date.now()
, inside your src/index.html
:
- You'd make a task called
tasks/timestamp.js
. The file has to expose a function named just like the placeholder → timestamp() ! - That function has to return something, eg. the current date:
function timestamp {
return Date.now();
}
- Run
$ kazooie build
to create the compiledindex.html
in yourpublic
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 casefunction placeholder() {...}
) - Placeholders and functions can be called with one argument, to give context in your tasks. For example
getPosts(lastest)
andgetPosts(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 topublic
), 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