Lightweight

Static website generator without magic.

Code over configuration

Most frameworks for static site generation are declarative. They have little flexibility in terms of how they work, and can require lots of time to setup. Lightweight is meant to be easy to grasp for people who already know Python. It’s core API is handful, but from there you’re free to go in any direction you want.

Features

Installation

Get it from PyPI:

pip install lightweight

Code Example

from lightweight import Site, markdown, paths, render, template, feeds, sass


def blog_posts():
    post_template = template('blog-post.html')
    # Use globs to select files.
    return (markdown(path, post_template) for path in paths('posts/**.md'))


site = Site(url='https://example.com')

# Render a Jinja2 template.
site.include('index.html', jinja('index.html'))

# Render list of Markdown files.
[site.include(f'posts/{post.source_path.stem}.html', post) for post in blog_posts()]

# Render SCSS.
site.include('static/css/style.css', sass('static/scss/lightweight.scss'))

# Include a copy of a directory.
site.include('static/js')
site.include('static/img')

# Execute all included content.
site.render()

Getting started

Step #1: Install

pip install lightweight

Step #2: Initialize project

lw init example --title Example
cd example

(Optional) Step #2.1: Create venv

python -m venv .venv
source ./.venv/bin/activate
pip install -r requirements.txt

Step #3: Serve at localhost:8080

./website.py serve

Next steps

Start by looking at website.py module located at project root (it will be similar to code example above) and check out Lightweight docs.