A simple static site generation library
Project description
Ryland
A simple static site generation library
Current Features
- use of Jinja2 templates
- render page-level markdown including frontmatter support
- render markdown within data using filter
- pull data directly from JSON or YAML files within templates
- copy static files and directory trees (for stylesheets, scripts, fonts, images)
- generate hash for cache-busting
History
I've generally found the framework-approach of most static site generators to either be far too complex for my needs or too restricted to just blogs or similar. Over the years, I've generated many static sites with lightweight, bespoke Python code and hosted them on GitHub pages. 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
Now see CHANGELOG.md
Example Usage
pip install ryland (or equivalent).
Then 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()
## copy and hash static files
ryland.copy_to_output(PANTRY_DIR / "style.css")
ryland.add_hash("style.css")
## render templates
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
})
## and/or generate from Markdown files
PAGES_DIR = Path(__file__).parent / "pages"
for page_file in PAGES_DIR.glob("*.md"):
ryland.render_markdown(page_file, "page.html")
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.
Render Markdown Method
ryland.render_markdown takes a Path to a Markdown file and a template name.
The Markdown is rendered to HTML and passed to the template as content. The YAML frontmatter (if it exists) is passed to the template as frontmatter.
Markdown Filter
To render a markdown context variable:
{{ content | markdown }}
Data Function
You can put together your template context in your Python build script or you can pull data directly from a JSON or YAML file within a template.
Here's an example of the latter:
<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
- https://projectamaze.com
- https://digitaltolkien.com
- https://jktauber.com
- https://cite.digitaltolkien.com
Roadmap
In no particular order:
- helpers for pagination
- ability to pass in a function to dynamically generate output filename
- move over other sites to use Ryland
- incorporate more common elements that emerge
- 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
Because Ryland is a library, a lot of missing features can just be implemented by the site developer. However, if three or more sites duplicate effort in their build script, I'll consider at least adding helper code to Ryland.
Once five independent people are running sites built with Ryland, I will declare 1.0.0.
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.9.0.tar.gz.
File metadata
- Download URL: ryland-0.9.0.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.17
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
01acf67c35e6c5dfbcf9a844bc0c7d7adfd9659b637e09be274209708b6f94fb
|
|
| MD5 |
38f438660218ffd2343c63ce231bbdd9
|
|
| BLAKE2b-256 |
4b2fc206452956d841f851c640a8750b16e9c035508ca654925ce10c15f88592
|
File details
Details for the file ryland-0.9.0-py3-none-any.whl.
File metadata
- Download URL: ryland-0.9.0-py3-none-any.whl
- Upload date:
- Size: 4.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.17
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e74b4208393347db1d63b2e3dd810a299581df64266afdf8929ecf334bb4fb2f
|
|
| MD5 |
8981ef4d1c118faa86fe66a7112481de
|
|
| BLAKE2b-256 |
45ae1d27ca036e15b791cf1f0ae7a7c8ebca2f6ce06d809983fa3c4022ebad63
|