3 Using mlem
viridian edited this page 2024-04-21 15:56:52 +02:00

Using mlem

Some prerequisites before you can use mlem are:

  • A Rust Compiler
  • Knowledge of HTML
  • Knowledge of Markdown

Writing a config

Mlem expects a mlem.toml in its execution directory to work. You can generate the config by running mlem create . The default config file it creates looks like this:

output_dir = "output"
src_dir = "md_src"
templates_dir = "templates"

You can change all these values later as well.

Creating a template

Blog template

Before you can even write anything you will have to add some templates into the templates directory (assuming your using the default). These templates are made using Tera reading the documentation should be enough to write a template for a blog post. The values which mlem exposes to the blog template are:

  • blog_content This contains the HTML of the markdown of the post
  • The values defined in the frontmatter

Index template

The index template will be used to generate an index of all posts. It must be named index.html. The values exposed to this template are:

  • blog_posts An array of structs containing the posts.
    • title
    • human_date
    • sort_date
    • content
    • output_file_name
  • truncate filter; works like a call to String.truncate()

Writing an entry

To create a new entry you add a markdown file into the src directory. In that file you now have to add frontmatter (A list of keys and values). This is an example of all the needed values:

---
date: 2024-04-20T20:40:00+02:00
template: blog.html
title: Porting libcurl to browser
---

The date values is an ISO8601 formatted date. The template is one of the templates which were defined by you. The title is the blog title.

After you added the frontmatter you can write normal markdown like you are used to.

Publishing the articles

By running mlem the files will be outputted in the output directory and you can move them to a webserver (Or whatever).