Larablog Rust

Larablog Rust is a Markdown blog for Laravel Rust sites that speak more than one language. A post is a folder, each translation is a file inside it, and every translation has its own slug and its own address: the English one at /blog/chat-moderation-games, the Spanish one at /es/blog/moderacion-chat-videojuegos. It finds, caches and paginates the posts; your own views draw them.
Written against version 0.1, which targets Laravel Rust 0.1 (in beta). Its API follows the framework's changes until 1.0.
This is the port of Larablog, the PHP package, and it reads the same content, with no change: a site that runs the PHP package can point this crate at its content folder. Neoguias runs on the PHP package. The test suite of the crate runs fifteen of its real posts with their _categories.yml and _authors.yml as fixtures, and the README records that the HTML matches the PHP package's on all 152 of them. The crate is on crates.io and its API reference is on docs.rs. For a step-by-step tutorial in Spanish, see Cómo crear un blog con Markdown en Laravel Rust on Neoguias.
Installation
Requires Laravel Rust 0.1 and Laralocale, which holds the current locale that Laravel Rust does not.
cargo add larablog laralocale
Laracards comes with the default cards feature. Without the social cards, which keeps resvg out of the build:
cargo add larablog --no-default-features
Register the providers in src/app.rs, and name the collections that have pages:
use larablog::LarablogServiceProvider; use laralocale::{LaralocaleServiceProvider, LocaleConfig}; Application::configure() .with_providers(|providers| { providers.add(LaralocaleServiceProvider::new()); providers.add(LarablogServiceProvider::new().routes("blog")); }) .with_config(|config, _| { config.section_mut::<LocaleConfig>().supported = vec!["en".into(), "es".into()]; })
The provider adds the configuration, the collections, their routes, the commands and the packaged views. There is no config file to publish: the configuration is LarablogConfig, set with with_config.
Writing a post
content/blog/
_authors.yml
_categories.yml
chat-moderation/
en.md
es.md
The folder name groups the translations and never appears in a URL. A language missing for a post is allowed; larablog:check points it out. A post is a Markdown file with YAML frontmatter:
--- title: "Chat moderation for games" slug: chat-moderation-games description: "Catching toxicity without killing the banter." date: 2026-09-01 category: engineering tags: [gaming, moderation] author: edu featured: true draft: false --- The body, in Markdown.
slug defaults to the title, slugified. A post dated in the future is scheduled: it is not listed, not in the feed or the sitemap, and answers 404 until its day. A post with draft: true is never published. Any other field stays available as post.meta("field"), with dots for depth. Dates are read in UTC, as 2026-09-01, 2026-09-01 10:30, 2026-09-01T10:30:00 or with an offset. Categories and authors live in the two YAML files, with names per language.
Linking one post from another
Link another post by its folder, not by its slug:
Read [how glossaries are applied](post:glossaries) first.
On an English page that becomes /blog/glossaries-that-are-obeyed, on a Spanish one /es/blog/glosarios-que-se-cumplen, and if the post has no translation it points at the language it exists in. A renamed slug breaks nothing. A link to a post that is not out yet is printed as plain words and becomes a link by itself the day that post goes live. A link to a folder that does not exist points at # and fails larablog:check.
Content that appears when another post is published
Wrap any Markdown fragment in if-published and name the other post by its folder ID:
::: if-published post="chat-moderation"
Read [our complete guide to chat moderation](/blog/chat-moderation-games).
:::
The markers go on their own lines, and everything inside is ordinary Markdown. The fragment is omitted until that post is published, and the condition is evaluated after the cache, on every visit, so a scheduled post reveals its dependent fragments on time with no command and no rebuild. A list item can carry its own condition, indented under the list marker, and a list with no items left disappears. Hidden headings are excluded from post.headings. Examples inside fenced code stay literal.
Putting it on the site
LarablogServiceProvider::new().routes("blog") gives each language its listing, posts, categories, tags and RSS feed, named .blog.index|show|category|tag|feed. The default language of the application sits at the root and the others under their code. A link opened in the wrong language redirects to the right post with a 301.
The views are MiniJinja templates, and each receives blog, locale and alternates, the address of the same page in every language, which is what the hreflang tags need. A post view reads fields where PHP's views call methods: post.url, post.author.name, post.date_formatted, post.reading_time, post.headings, post.html. The crate ships a plain pair of views, used when the application has none of its own:
laravel larablog:publish
writes index.html and show.html into resources/views/vendor/larablog, where they override the packaged ones. From Rust, larablog::collection("blog")? gives the collection: posts, find, categories, tags and sitemap, with None for the current locale.
Social cards
With the cards feature, Larablog registers itself as a Laracards source, so laravel cards:generate --source=larablog draws one card per post and language at public/img/blog/{locale}/{slug}.png, scheduled posts included. post.image_url returns the frontmatter's image, or the card when it exists.
Index cache
Larablog caches each collection's metadata and a lookup keyed by language and slug, so finding one post does not parse the whole collection. A request builds a missing index by itself. In production, changes in the files are checked at most once every 60 seconds, and outside production immediately. Draft visibility and scheduled publication times are evaluated on every lookup, so a scheduled post goes public on time. laravel larablog:cache prepares the index during a deploy, and it is optional.
The cache lives in the memory of the process, which in Laravel Rust outlives the request.
Before publishing
laravel larablog:check
laravel larablog:check --pending
The first fails on what would reach a reader broken: a post with no title, a slug used twice in one language, broken YAML, a post: link to a folder that does not exist (in scheduled posts too). It warns about missing translations and exits 1 on errors, for CI. The second also lists every link waiting for its post, with the day it becomes a link.
Configuration
LarablogConfig is the configuration section, with the keys and defaults of config/larablog.php:
| Key | Default | |
|---|---|---|
collections |
blog |
The collections, by name |
collections.*.path |
content/blog |
The folder, relative to the base path or absolute |
collections.*.locales |
None |
Its languages, the default first. None is the supported ones of Laralocale |
collections.*.paths |
en and es are blog |
The first segment of its URLs, per language. Empty puts it at the root |
collections.*.segments |
category, categoria, tag, etiqueta |
The words in category and tag URLs, per language |
collections.*.per_page |
12 |
Posts per page of a listing |
show_scheduled |
false |
Read from LARABLOG_SHOW_SCHEDULED |
show_drafts |
false |
Read from LARABLOG_SHOW_DRAFTS |
cache.check_interval |
None |
60 seconds in production and 0 elsewhere. Read from LARABLOG_CACHE_CHECK_INTERVAL |
Several collections (a blog, guides, case studies) each get their own entry and their own call to routes.
Testing
cargo test
The suite runs on the application of for_testing against fixtures: the PHP package's own and fifteen real posts of Neoguias, which exercise conditional blocks in paragraphs and list items, posts that go out on different days, tags and dates with an offset. Time is controlled with app.travel_to.
Differences from the PHP package
- The provider registers the routes, with
LarablogServiceProvider::new().routes("blog"), instead ofLarablog::routes('blog')inroutes/web.php.routes_withtakes aMiddlewareGroup. - There are no named routes in Laravel Rust 0.1, so Larablog has a registry of its own. The names are PHP's but the addresses come from the configuration. There is no Laralang integration: the default language sits at the root and the others under their code.
- Facades are functions.
Larablog::collection('blog')islarablog::collection("blog")?. - Default arguments are
Optionor a second method.$locale = nullisOption<&str>, andurl($absolute = true)isurl()andurl_with(absolute). - Views get data, not objects, because MiniJinja cannot call a Rust method.
- The views are shipped and overridable, and
larablog:publishis thevendor:publishthat Laravel Rust 0.1 lacks. - The cache is in the memory of the process, not in a Laravel cache store.
- Dates are UTC, and
Carbon::parseis not here. Only the formats listed above are read. - The reading time counts words like PHP does (
str_word_count), but not like PHP'sstrip_tags. On code-heavy posts the minutes differ: of the 152 posts of Neoguias, 66 get the same minutes, 23 differ by one and 63 by more. Setreading_timein the frontmatter to fix one. - YAML is YAML 1.2, so
yesandnoare strings. - CommonMark is
comrak. Its output matchesleague/commonmarkfor a list of eighteen constructs and for the 152 posts of Neoguias, apart from whitespace between tags. The conditions are rewritten by a line scanner before parsing, becausecomrakhas no block extension point.
built and maintained by Edu Lazaro · MIT license