Templating
Rubedo uses the Tera template engine. You can refer to its documentation for how to actually use it to create your own theme.
In Rubedo 1.0.0, Tera has been upgraded to version 2.0. This upgrade comes with some small breaking changes in how templating works. If your website fails to render after upgrading, you might want to consult Tera's v1 -> v2 migration guide.
Context
Inside your templates you can use the site and page variables, provided by the context. Here's a rundown of what they contain.
site: Represents the entire website, and is always available in the context.config: Represents theconfig.tomlfile of the website. The description for the various sub-keys can be found in the configuration docspages: List of pages available in your website, each corresponding to a markdown file (indified by the.mdfile extension) inside thecontentdirectory. Each page contains the same data detailed in thepagedefinition below.
page: Represents the current page being rendered. For obvious reasons, this is only available when rendering a page inside thecontentdirectory.title: Title of the page, as specified in the frontmatter. This defaults to the file name.content: String containing the raw content of the markdown file.html: Rendered HTML generated from the markdown file. When displaying it inside a Tera template, it might be a good idea to use thesafefilter like so:{{ page.html | safe }}. Rubedo uses Comrak for rendering markdown.url: Absolute URL of the page, prefixed withsite.config.base_urlif provided in the config.template: Template file path (relative to the theme directory) to use for the page. Defaults to__page__.html.weight: Weight of the page, for sorting purposes. Lower weight pages come before higher weight ones. Pages without a weight are always sorted after pages with a weight. Pages without a weight are sorted on their own by theirurlvalue.datetime: Publish date of the page, parsed from the frontmatter.relative_path: The path to the page, relative to thecontentdirectory, with the file extension from the template file used.relative_path_no_ext: The path to the markdown file, relative to the content directory, minus the file extension.extension: Generated page file extension, with leading dot.skip: Boolean, if true, rendering of this page will be skipped. It will still be available in the context as an item insidesite.pages.data: Contains the values parsed from the frontmatter.metadata: Contains the values parsed from the frontmatter.- This has been deprecated in 1.0.0 and will be removed in future versions; use the
dataobject instead.
- This has been deprecated in 1.0.0 and will be removed in future versions; use the
Filters, functions and tests
Provided by tera-contrib
You can find out more about tera-contrib on their docs.rs page
b64_decodefilter: Decodes a base64 string.b64_encodefilter: Encodes a string to base64. Takes an optionalurl_safebool parameter (falseby default) if you want to use the URL SAFE b64 characters and apaddedbool parameter on whether you want padding (trueby default).datefilter: Formats the given value using the given format if it can be parsed as a date/datetime. Takes:- optional
formatargument, defaulting to%Y-%m-%d - optional timezone argument, defaulting to not set
- optional
is_aftertest: Tests whether a date is after another date. Errors if one of the values cannot be parsed as a date. Takes an optionalinclusiveargument defaulting to false to make this test be>=instead of>.is_beforetest: Tests whether a date is before another date. Errors if one of the values cannot be parsed as a date. Takes an optionalinclusiveargument defaulting to false to make this test be<=instead of<.nowfunction: Returns the current datetime. You can pass an optionaltimezonename. Defaults to UTC if not provided.formatfilter: Formats a value using Rust's std::fmt format specifiers. Supports width, alignment, precision, sign, and zero-padding. Does NOT support radix specifiers (x, X, b, o) - only Display formatting.json_encodefilter: Encodes a value as JSON. Takes an optionalprettyboolean argument defaulting tofalse.get_randomfunction: Get a random integer between thestart(inclusive) andend(exclusive) parameters. Optionally takes a seed.shufflefilter: Shuffles a list, optionally taking a seed for reproducible shuffling.slugfilter: Slugify the given value.urlencodefilter: Percent-encodes reserved URI characters. Matches Python’s urllib.parse.quote behavior with / not escaped.urlencode_strictfilter: Percent-encodes all non-alphanumeric characters. Stricter than urlencode - also encodes / and other typically safe characters.
Provided by Rubedo
markdownifyfilter: Renders the given string as markdownthumbnailfilter: Creates a thumbnail for the given local image; the value should be a path, relative to your website'sstaticdirectory. Takes:path: Path to where the thumbnails will be saved in thepublicdirectoryformat: The image format for the generated thumbnail. Supports:"preserve": Keep the input image's format"jpg": JPEG format"png": PNG format
paginatefunction: Paginates the given list of pages into indices of a given size. Takes:pages: List of pages to paginatepage_size: Up to how many pages per index should be showntemplate: Which template should be used for renderingdir: The output directory for the generated pagesempty_out: If the first rendered index page should not be returned (defaults tofalse)