A simple static site generation library
Project description
Ryland
A simple static site generation library
Current Features
- Jinja2 templates with a basic markdown filter and a function to pull data directly from JSON files
- copying static files and directory trees (for stylesheets, scripts, fonts, images)
- cache-busting with hashes
History
I've generally found most static site generation libraries to either be far too complex for my needs or be too restricted to just blogs so, over the years, I've generated many static sites with lightweight, bespoke Python code and hosted them on GitHub pages. However, I've ended up repeating myself a lot so I'm now cleaning it all up and generalizing my prior work as this library.
Changelog
0.1.0
- initial release
0.2.0
- added the
datafunction with support for JSON
0.3.0
- changed
disttooutput - changed
calc_hashtoadd_hash - support just passing in
__file__and assumingoutput_dirandtemplate_dir - added an example
0.4.0
clear_outputwill create the directory if it doesn't exist- added another example
Example Usage
pip install ryland (or equivalent).
The write a build script of the following form:
from ryland import Ryland
ROOT_DIR = Path(__file__).parent.parent
OUTPUT_DIR = ROOT_DIR / "output"
PANTRY_DIR = ROOT_DIR / "pantry"
TEMPLATE_DIR = ROOT_DIR / "templates"
ryland = Ryland(output_dir=OUTPUT_DIR, template_dir=TEMPLATE_DIR)
ryland.clear_output()
ryland.copy_to_output(PANTRY_DIR / "style.css")
ryland.add_hash("style.css")
ryland.render_template("404.html", "404.html")
ryland.render_template("about_us.html", "about-us/index.html")
# construct context variables
ryland.render_template("homepage.html", "index.html", {
# context variables
})
Also see examples/ in this repo.
Cache-Busting Hashes
The add_hash makes it possible to do
<link rel="stylesheet" href="/style.css?{{ HASHES['style.css'] }}">
in the templates to bust the browser cache when a change is made to a stylesheet, script, etc.
Markdown Filter
To render a markdown context variable:
{{ content | markdown }}
Data Function
To pull data directly from a JSON file in a template:
<div>
<h2>Latest News</h2>
{% for news_item in data("news_list.json")[:3] %}
<div>
<div class="news-dateline">{{ news_item.dateline }}</div>
<p>{{ news_item.content }}</p>
</div>
{% endfor %}
</div>
Sites Currently Using Ryland
Roadmap
In no particular order:
- move over other sites to use Ryland
- incorporate more common elements that emerge
- add support for YAML data loading in templates
- improve error handling
- produce a Ryland-generated website for Ryland
- document how to automatically build with GitHub actions
- write up a cookbook
- add a command-line tool for starting a Ryland-based site
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ryland-0.4.0.tar.gz.
File metadata
- Download URL: ryland-0.4.0.tar.gz
- Upload date:
- Size: 3.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
66207c4d51b2acff791fa8d6345696288c82734c5f42a72613bdd37ece12cea4
|
|
| MD5 |
69600ba2ec3783439e9e58826a24c148
|
|
| BLAKE2b-256 |
28a2bc2c1102d522a90f8e1d3e31d02f736fdbe561c6ce77c5d4436ec93c6212
|
File details
Details for the file ryland-0.4.0-py3-none-any.whl.
File metadata
- Download URL: ryland-0.4.0-py3-none-any.whl
- Upload date:
- Size: 3.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0cb01cfeab65bf218fb94befb2f1f416dc606444714ad879bb19ccad71d03bf7
|
|
| MD5 |
bd19a5f6debec80a20a9ef0c2fd3033d
|
|
| BLAKE2b-256 |
7ab9a8822c6484067179b5f20a44d06790b70e82a590a0c823c62f42b2a8440d
|