aip-dev / site-generator

Static site generator for aip.dev and forks.
Apache License 2.0
29 stars 31 forks source link

aip.dev static site generator

This is the site generator for aip.dev and its forks. It takes AIP files in a git repository and outputs a static website.

Why?

We are not fans of rolling our own tools when off-the-shelf alternatives exist. However, the AIP project has grown sufficiently mature to warrant it.

GitHub Pages normally automatically builds documentation with Jekyll, but as the AIP system has grown, we are beginning to reach the limits of what Jekyll can handle, and other off-the-shelf generators had similar issues:

There are some additional advantages that we unlock with a custom generator:

How does it work?

This is essentially split into three parts:

Of the models, there are three models in particular that matter:

Templates are jinja2 files in the templates/ directory.

Note: We run Jinja in with "strict undefined", so referencing an undefined variable in a template is a hard error rather than an empty string.

Entry points

There are two entry points for the app. The publisher (aip_site/publisher.py) is the program that iterates over the relevant directories, renders HTML files, and writes them out to disk. The app (aip_site/server.py) is a lightweight Flask app that provides a development server.

These entry points are routed through the CLI file (aip_site/cli.py); when this application is installed using pip, it makes the aip-site-gen (publisher) and aip-site-serve (server) commands available.

Extensions

This site generator includes a basic extension system for AIPs. When processing AIPs as plain Markdown files, it will make any Markdown (level 2 or 3) header into a block. Therefore...

## Foo bar baz

Lorem ipsum dolor set amet

Becomes...

{% block foo_bar_baz %}
## Foo bar baz

Lorem ipsum dolor set amet
{% endblock %}

That allows an overriding template to extend the original one and override sections:

{% extends aip.templates.generic %}

{% block foo_bar_baz %}

## My mo-betta foo bar baz

Lorem ipsum dolor set something-not-amet
{% endblock %}

Developer Setup

If you want to contribute to this project you will want to have a setup where you can make changes to the code and see the result of your changes as soon as possible. Here is a quick way to set up a local development environment that will enable you to work on the code without having to reinstall the command line scripts.

Dependencies

You'll need venv. On Linux, install with,

sudo apt-get install python3-venv

Running dev env

  1. Check out the source
$ mkdir src
$ cd src
$ git clone https://github.com/aip-dev/site-generator.git
  1. Setup python virtual environment
$ python3 -m venv .venv
$ source .venv/bin/activate
  1. PIP Install with the editable option
$ pip install --editable .
  1. Serve the aip.dev site
$ aip-site-serve /path/to/aip/data/on/your/system