Zine is an open source, command line, blog-aware, static website generator.
Distinguishing features include:
- ERB templates
- Sass stylesheets
- fast incremental builds
- a choice of AWS S3, GitHub & SFTP file uploaders
How do I get it?
Zine is a Ruby Gem, so if you have Ruby on your machine (it comes installed standard on a Mac), open Terminal & type
gem install zine
And you're away.
To generate a new scaffold site, cd to a new directory and:
$ zine site
Then update your site's name, your name & so on in zine.yaml. Pay particular care to the Upload section, if you want to use Zine to deploy files you've changed, you'll need to edit this section to include your remote server's details, including the path to a YAML file with your credentials.
Day to day use
To set up a new blog post:
$ zine post 'Your chosen title'
Your new post will have some fields set up in the YAML front matter, feel free to edit them too.
You can also create other Markdown files outside of the posts folder, those will be rendered into HTML in the same relative position in the build folder. That's how the project, about etc pages on my site are made for example.
Type zine build before you start writing to serve up a local copy of your site that you can refresh to see what the build version will look like.
$ zine build
or
$ zine force
Build will only watch for the things that change while it's running, so the first time you build your site you should use force -- force writes all of the files (& so also uploads them all too if you've set up uploads).
Control-C in Terminal when you're done.
Design & development
Typing zine style
will render the Sass file into CSS. The templates are all editable, as are the files' names, which you can change in the options file.
Halp!
To see the options available type zine & hit enter:
$ zine
Commands:
zine build # Build the site
zine force # Build the site, forcing writes & uploads
zine help [COMMAND] # Describe available commands or one specific command
zine notice POST # Build the site, then force the one POST
zine nuke # Delete the build folder
zine post TITLE # Create the file for a new blog post, titled TITLE
zine site # Create the skeleton of a new site (overwriting files)
zine style # Build the site's stylesheet
zine version # Show the version number
Links
MiniJinja: a powerful template engine for Rust with minimal dependencies
MiniJinja is a powerful but minimal dependency template engine for Rust which is based on the syntax and behavior of the Jinja2 template engine for Python.
It's implemented on top of serde
and only has it as a single required
dependency. It supports a range of features from Jinja2
including inheritance, filters and more. The goal is that it should be possible
to use some templates in Rust programs without the fear of pulling in complex
dependencies for a small problem. Additionally it tries not to re-invent
something but stay in line with prior art to leverage an already existing
ecosystem of editor integrations.
$ cargo tree
minimal v0.1.0 (examples/minimal)
└── minijinja v2.4.0 (minijinja)
└── serde v1.0.144
Additionally minijinja is also available as an (optionally pre-compiled) command line executable
called minijinja-cli
:
$ curl -sSfL https://github.com/mitsuhiko/minijinja/releases/latest/download/minijinja-cli-installer.sh | sh
$ echo "Hello {{ name }}" | minijinja-cli - -Dname=World
Hello World
You can play with MiniJinja online in the browser playground powered by a WASM build of MiniJinja.
Goals:
- Well documented, compact API
- Minimal dependencies, reasonable compile times and decent runtime performance
- Stay as close as possible to Jinja2
- Support for expression evaluation which allows the use as a DSL
- Support for all
serde
compatible types - Well tested
- Support for dynamic runtime objects with methods and dynamic attributes
- Descriptive errors
- Compiles to WebAssembly
- Works with Python
- Comes with a handy CLI
- Experimental C-Bindings
Example Template:
{% extends "layout.html" %}
{% block body %}
<p>Hello {{ name }}!</p>
{% endblock %}
Here are some interesting Open Source users and use cases of MiniJinja. The examples link directly to where the engine is used so you can see how it's utilized:
-
HTML Generation:
- Zine uses it to generate static HTML
- Oranda uses it to generate HTML landing pages
-
Structure Generation:
- Astral's Rye is using it to generate project structures
- Maturin uses it to generate project structures
- cargo-dist uses it to generate CI and project configuration
-
AI Chat Templating:
- HuggingFace uses it to render LLM chat templates
- mistral.rs uses it to render LLM chat templates
- BoundaryML's BAML uses it to render LLM chat templates
- LSP-AI uses it to render LLM chat templates
-
Data and Processing:
- Cube uses it for data modelling
- PRQL uses it to handle DBT style pipelines
If you are stuck with MiniJinja
, have suggestions or need help, you can use the
GitHub Discussions.
- minijinja-autoreload: provides auto reloading functionality of environments
- minijinja-embed: provides utilities for embedding templates in a binary
- minijinja-contrib: provides additional utilities too specific for the core
- minijinja-py: makes MiniJinja available to Python
- minijinja-cli: a command line utility.
- minijinja-cabi: a C binding to MiniJinja.
These are related template engines for Rust:
- Askama: Jinja inspired, type-safe, requires template precompilation. Has significant divergence from Jinja syntax in parts.
- Rinja: Jinja inspired, type-safe, requires template precompilation. Has significant divergence from Jinja syntax in parts.
- Tera: Jinja inspired, dynamic, has divergences from Jinja.
- TinyTemplate: minimal footprint template engine with syntax that takes lose inspiration from Jinja and handlebars.
- Liquid: an implementation of Liquid templates for Rust. Liquid was inspired by Django from which Jinja took it's inspiration.
from https://github.com/mitsuhiko/minijinja
(cd ~
git clone https://github.com/mitsuhiko/minijinja
cd minijinja
cargo build --release
在生成的target/release目录里,出现了 minijinja-cli.exe
~/minijinja/target/release/minijinja-cli.exe -h )
No comments:
Post a Comment