Lightweight

Static website generator without magic.

Code over configuration

Most frameworks for static site generation are declarative. They require a lot of time to get started and then they may not be flexible enough.

Lightweight is different in this manner. 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 Lightweight.

pip install lightweight

Step #2: Initialize a new project.

lw init example --url https://example.com --title Example
cd example

(Optional) Step #2.1: Create a virtual environment for the new project.

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

Step #3: Serve the newly created site at localhost:8080.

lw serve site:dev

Beyond that you are free to deal with the site as you wish.

Start at the site.py module of the project (it will be similar to code example above) and check out Lightweight docs.