anodize v2.6.0
Anodize is a static site generator that allows you to create no-frills websites from simple templates. It has several useful website features built-in; the philosophy is to have sane defaults rather than to allow excessive configuration.
Differentiating features:
- Templating within markdown: Anodize will parse templates inside the body of your markdown files, for things like lists of pages or files
- Incremental regeneration (beta): Automatically skip re-rendering files that haven't changed
- Global variables: Declare variables in your configuration file and access them anywhere
Getting started:
$ npm install -g anodize
$ cd your/website/directory
$ anodize init
How it works
Anodize stores all config in the .anodize.yml
file in the project root folder, which is assumed to be the current working directory unless the -i
flag is passed.
There are three subdirectories in the project root:
template
stores Liquid templates for rendering the website.src
stores all of the source files.gen
is the output folder for the rendered HTML. The name of each of these folders is configurable in.anodize.yml
under the keystemplate
,source
,target
respectively.
Source folder
Files in the source folder are either markdown files (everything with a .md
extension) or static files (everything else). Static files are simply copied over to the target directory under the same relative path.
Markdown format
Markdown parsing is done by ShowdownJS. Each file contains:
- a YAML header
- one line with only
---
- a markdown body
title: My first post
sort: 5
some_key: true
this:
- is
- yaml
---
## this is markdown
Anything here can be templated in Liquid. For example: this is {{ keys.some_key }}.
Index files (index.md
) and other markdown files are treated differently.
Non-index files
The header can contain any keys with any values, except for the following special keys:
title
is used in the HTML<title>
tag, through the titleTemplate (see below) if presentdate
if in the formatYYYY-MM-DD
orYYYY-MM
is parsed into a Unix timestampdraft
is a boolean that indicates the current file is a draft and should not be rendered, allowing you to include the file in version control without displaying it in productionhead
represents the HTML head. Currently only supported for internal use, so consider this key reserved.regen
is a boolean that enables site-wide access in the body template. This flag tells Anodize to regenerate this file regardless of changes when doing incremental regeneration.keywords
is an array of keywords to be placed in the<meta keywords>
html tag.layout
identifies the name of the template file, and if not present, Anodize will look for a file with the name of the parent directory and the.liquid
extension./foo/bar.md
will default to<template directory>/foo.liquid
.
Standard markdown files have access to the following keys through templates in their body.
keys
is the header object of the fileglobal
is the object declared under the key of the same name in.anodize.yml
id
is the filename of the current filepath
is the path that the current file will be accessible at after generationdirname
is the name of the parent directory, or_root
if the file is in the website root.site
is accessible ifregen
is enabled in the header. It is an object with keys in the formatpath/to/directory
and values{ filename: file_object }
. Many of thefile_object
properties are internal, but naturally the header is accessible underfile_object.keys
. For example, if I wanted to enumerate the files in a directoryfoo/bar
:
{% assign dir = site['foo/bar'] | sortItems %}
{% for f in dir %}{{ f.id }}{% endfor %}
The Liquid filter sortItems is provided to convert objects into arrays and sort based on the sort key if present, or alphanumerically otherwise.
Index files
Index files have access to the same keys as regular files, with the following differences:
sortBy
tells the sortItems filter which key to sort the folder byno-regen
is used instead ofregen
for conciseness; index files are regenerated by default, andno-regen
disables this behavior. Sosite
is accessible by default in index files.layout
defaults toindex.liquid
rather than the name of the parent directory.
Index files are also discard by the sortItems filter for convenience.
All markdown files are output as the index file of their own directory; this is known as a 'pretty url.' /foo/bar/baz.md
will be output to /foo/bar/baz/index.html
and can be located by a browser at https://example.com/foo/bar/baz/
.
Templates
Anodize uses the Liquid templating language through liquidjs.
Server
Anodize comes with live-server, a development webserver with live reloading. Just run$ anodize serve
and open http://localhost:8000
in a browser.
Configuration
Settings are defined in a file named .anodize.yml
, which is automatically created by running anodize init
.
As previously stated the keys target
, source
, and template
specify the locations of those directories.
The key ignore
is an array of glob patterns to ignore. Default is all dotfiles **/.*
.
The key head
specifies the contents of the <head>
tag. Available sub-keys and corresponding tags:
title
: string,<title>
description
: string,<meta name="description">
keywords
: array,<meta name="keywords">
css
: array of file paths,<link rel="stylesheet" href="path/to/file.css">
raw
: array, inserts specified text into<head>
.
The contents of the key global
are available to the templating engine under the key global
.
The key titleTemplate
is a template for constructing html <title>
tags. It is a string with a $0
where you want the page's title inserted. For example, the string $0 | Sid Mani's blog
. Defaults to $0
(no templating).
About
I wrote this to power my blog. If you do something cool with this, a link back here or to my blog would be nice. Feel free to open pull requests.
License
GNU-AGPLv3
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago