
# Larablog for Laravel Rust
<p align="center">
<a href="https://github.com/edulazaro/larablog-rust/actions/workflows/tests.yml"><img src="https://github.com/edulazaro/larablog-rust/actions/workflows/tests.yml/badge.svg" alt="Tests"></a>
<a href="https://crates.io/crates/larablog"><img src="https://img.shields.io/crates/v/larablog" alt="Crates.io"></a>
<a href="https://crates.io/crates/larablog"><img src="https://img.shields.io/crates/d/larablog" alt="Downloads"></a>
<a href="https://docs.rs/larablog"><img src="https://img.shields.io/docsrs/larablog" alt="Docs.rs"></a>
<a href="https://github.com/edulazaro/larablog-rust/blob/main/LICENSE.md"><img src="https://img.shields.io/crates/l/larablog" alt="License"></a>
</p>
Markdown blogs for Laravel Rust in several languages, where **every language has its own URL**.
One folder per post, one file per language. Each file declares its own slug, so the English
post lives at `/blog/chat-moderation-games` and the Spanish one at
`/es/blog/moderacion-chat-videojuegos`, and each page knows the other: hreflang, a language
switcher, the sitemap and a link shared in the wrong language all just work.
- Posts are Markdown files with YAML frontmatter, read once and cached until a file changes
- A URL per language, with translated words (`/blog/category/x`, `/es/blog/categoria/x`)
- A slug from another language redirects to the right post in this one (301)
- Categories and authors in two YAML files, named per language
- Drafts and scheduled posts, an RSS feed per language, sitemap entries with alternates
- Anchors on every heading for an "On this page" index, safe external links
- Links between posts by folder (`post:chat-moderation`), resolved in the reader's language
- Fragments that appear when another post is published (`::: if-published post="..."`)
- A social card per post and language, drawn by [Laracards](https://github.com/edulazaro/laracards-rust)
- `larablog:check` before a visitor finds the broken post
- Your views: Larablog finds and paginates the posts, your site draws them
It is the port of the PHP package [Larablog](https://github.com/edulazaro/larablog) to
[Laravel Rust](https://laravel.com/rust). **It targets Laravel Rust 0.1, which is in beta, and its
API follows the framework's changes until 1.0.** It reads **the same content, with no change**: a
site that runs the PHP package can point this crate at its `content` folder. The names, the config keys,
the commands and this document follow the PHP package. Where Laravel Rust has no equivalent, the
section says so, and the [differences](#differences-from-the-php-package) are collected at the end.
## Requirements
Laravel Rust 0.1 and [Laralocale](https://github.com/edulazaro/laralocale-rust), which holds the
current locale that Laravel Rust does not. [Laracards](https://github.com/edulazaro/laracards-rust)
comes with the default `cards` feature.
## Install
```bash
cargo add larablog laralocale
```
Without the social cards, which keeps `resvg` out of the build:
```bash
cargo add larablog --no-default-features
```
Register the providers in `src/app.rs`, and name the collections that have pages:
```rust
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`](#configuration),
set with `with_config`.
## Content
```
content/blog/
_authors.yml
_categories.yml
chat-moderation/
en.md
es.md
glossaries/
en.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.
```markdown
---
title: "Chat moderation for games"
slug: chat-moderation-games
description: "Catching toxicity without killing the banter."
date: 2026-09-01
updated: 2026-09-20
category: engineering
tags: [gaming, moderation]
author: edu
image: /img/covers/chat.jpg # optional: otherwise the Laracards card is used
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. Any other field stays available as
`post.meta("field")`, with dots for depth (`post.meta("seo.title")`), which is how a site keeps its own
`noindex: true`.
Dates are read in UTC, as `2026-09-01`, `2026-09-01 10:30`, `2026-09-01T10:30:00` or with an offset
(`2026-09-01T00:00:00+01:00`). A post with no date takes the modification time of its file.
```yaml
# _categories.yml
engineering:
name: { en: Engineering, es: Ingeniería }
description: { en: How it is built, es: Cómo está hecho }
color: "#009e4d"
```
```yaml
# _authors.yml
edu:
name: Eduardo Lázaro
role: { en: Founder, es: Fundador }
avatar: /img/authors/edu.webp
links: { github: https://github.com/edulazaro }
```
A category slug is its name, slugified, per language (`ingenieria`), unless you give `slug`.
Any other field of a category stays available as `category.meta("field")`, in the page's language when
it is written per language. `accent` is also what the social card is tinted with, when the `color` your
views use is a class name rather than a colour:
```yaml
engineering:
name: { en: Engineering, es: Ingeniería }
color: teal # your CSS: class="cat-{{ post.category.color }}"
accent: "#2dd4bf" # the card
```
## Linking posts
Link another post by its **folder**, not by its slug:
```markdown
Read [how glossaries are applied](post:glossaries) first, or [the part on
placeholders](post:glossaries#placeholders).
```
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 is not translated it points at the language it does
exist in. Renaming a slug never breaks the links to it. `#anchor` and `?query` are kept.
A link to a post that exists but is not out yet (dated ahead, or a draft) is printed as its words, with
no link, and becomes a link by itself the day that post goes live: a published post can point at one
scheduled for next month with no dead link in between. 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**:
```markdown
::: if-published post="chat-moderation"
Read [our complete guide to chat moderation](/blog/chat-moderation-games).
:::
```
The opening and closing markers must be on their own lines. Everything inside is ordinary Markdown: a
paragraph, heading, image, table, list or several elements together. The whole fragment is omitted until
that post is published. The links and their visible text remain exactly as you wrote them; this condition
does not rewrite ordinary URLs.
A list item can have its own condition. Keep its content and closing marker indented under the list
marker:
```markdown
- ::: if-published post="chat-moderation"
Moderation guide: [How to moderate a game chat](/blog/chat-moderation-games).
:::
- ::: if-published post="future"
Next guide: [The future article](/blog/from-the-future).
:::
```
If only the first post is published, only the first complete `<li>` appears, including its label and
link. Hidden items leave no empty bullets. Lists with no remaining items are removed as well. A condition
inside an item that also has other content hides just that fragment and keeps the rest of the item.
Conditions are evaluated **after the cache**, on every visit. A scheduled post reveals its dependent
fragments when its publication time arrives, without editing the source post, running a command or
rebuilding the cached HTML. Hidden headings are excluded from `post.headings()` and their anchors remain
stable when they become visible.
The target belongs to the same collection. Availability follows the same language fallback as `post:`
links: the requested translation first, then an available translation. The `show_drafts` and
`show_scheduled` settings also apply. Conditions may be nested, inside lists and blockquotes too; all
outer conditions must be satisfied. Examples inside fenced code stay literal.
Create the target files before scheduling the series. `larablog:check` reports missing folder IDs and
missing closing markers; `--pending` lists dependencies waiting for publication. A missing target or an
unclosed condition stays hidden.
## Routes
```rust
LarablogServiceProvider::new().routes("blog")
```
That registers, per language, the listing, a post, a category, a tag and the feed, named
`{locale}.blog.index|show|category|tag|feed`. The default language of the application (`locale` of
`LocaleConfig`) sits at the root and the others under their code.
PHP registers the routes with `Larablog::routes('blog')` in `routes/web.php`. A package registers its
routes from its provider in Laravel Rust, so the collection is named there. Middleware for the pages goes
in `routes_with`, after the `web` group:
```rust
use laravel::http::MiddlewareGroup;
LarablogServiceProvider::new().routes_with("blog", MiddlewareGroup::new().with(throttle))
```
Laravel Rust 0.1 has no named routes, so Larablog keeps its own small registry. The names are PHP's and
`Blog::route_name("blog", "show", "es")` is `es.blog.show`, but the address of each page is a function of
the configuration, so `blog.url(..)` and `post.url()` work in a handler, a command and a test alike.
```rust
// config
blog.locales = Some(vec!["en".into(), "es".into()]);
blog.paths = [("en".into(), "blog".into()), ("es".into(), "blog".into())].into();
blog.segments.category = [("en".into(), "category".into()), ("es".into(), "categoria".into())].into();
blog.segments.tag = [("en".into(), "tag".into()), ("es".into(), "etiqueta".into())].into();
blog.per_page = 12;
})
```
Several collections (a blog, guides, case studies) each get their own entry in `collections` and their own
call to `routes`.
## Views
The views are MiniJinja templates. Every view gets `blog`, `locale` and `alternates` (a list of
`[language, URL]` pairs of this same page). The listing gets `posts` (a page, with `items`, `current_page`,
`last_page`, `total`, `prev_page_url` and `next_page_url`), `categories`, `tags`, and `category` or `tag`
when filtered; a post gets `post` and `related`.
Where PHP's views call a method, a view here reads a field of the same name: `post.url`,
`post.author.name`, `post.category.name`, `post.reading_time`, `post.headings`, `post.html`. The
frontmatter's own `author` and `category` are `post.author_key` and `post.category_key`.
`$post->date->locale($locale)->isoFormat('LL')` is `post.date_formatted`.
```html
{% for code, url in alternates %}
<link rel="alternate" hreflang="{{ code }}" href="{{ url }}">
{% endfor %}
<h1>{{ post.title }}</h1>
<p>{{ post.author.name }} · {{ post.date_formatted }} · {{ post.reading_time }} min</p>
<nav>
{% for heading in post.headings %}
<a href="#{{ heading.id }}">{{ heading.text }}</a>
{% endfor %}
</nav>
The hreflang links are also put in the `<head>` with `Head::alternate` of `laravel::head`, so a layout that
prints `{{ head() }}` has them already, along with the title, the description and `robots` for a post that
has `noindex: true`.
The views of a collection are the ones its `views` setting names, `blog.index` and `blog.show` by default.
When the application has none by that name, the crate's own are used, which draw a plain blog the moment the
provider is added. To start from them:
```bash
laravel larablog:publish
```
writes `index.html` and `show.html` into `resources/views/vendor/larablog`, where they override the packaged
ones (`--force` replaces them). PHP's `vendor:publish --tag=larablog-config` has nothing to write, since the
configuration is code.
## From Rust
```rust
let blog = larablog::collection("blog")?;
blog.posts(Some("es")); // published, newest first
blog.find("moderacion-chat-videojuegos", Some("es"));
post.alternates(); // [("en", "…/blog/chat-moderation-games"), ("es", "…")]
post.translations(false); // the same post in the other languages
post.related(3);
blog.categories(Some("es"));
blog.tags(Some("en"));
blog.sitemap(); // every URL with lastmod and its alternates
```
Where PHP takes `?string $locale = null`, this takes `Option<&str>`, and `None` is the current locale of
`laralocale`. The names are PHP's in snake_case: `Blog::find_in_any_locale`, `link_to`, `resolve_links`,
`broken_links`, `pending_links`, `category_by_slug`, `in_category`, `with_tag`, `index_alternates`,
`category_alternates`, `rebuild_index`. `Post::url()` is absolute and `Post::url_with(false)` is the path;
`Post::reading_time`, `image_alt` and `card_path()` are PHP's `readingTime`, `imageAlt` and `cardPath()`.
## Social cards
Larablog registers itself as a [Laracards](https://github.com/edulazaro/laracards-rust) source from the `boot`
of its provider, with `laracards::source`, so `cards:generate` draws one card per post and language, at
`public/img/blog/{locale}/{slug}.png`. Add the `LaracardsServiceProvider` too.
```bash
laravel cards:generate --source=larablog
```
The template gets `title`, `description`, `category_label`, `accent` (the category's colour), `author_name`,
`date_formatted` (in the post's language), `reading_time`, `brand_label` and `locale`. `post.image_url()`
returns the frontmatter's `image`, or the card when it exists. It is the `cards` cargo feature, on by default;
without it the crate does not depend on Laracards or on `resvg`.
## Index cache
Larablog caches each collection's metadata and a lookup keyed by language and slug. Looking up one post does
not parse every post of the collection. A request automatically builds a missing index, so no deployment
command is required.
In production, filesystem changes are checked at most once every 60 seconds. Outside production they are
checked immediately, preserving the edit-and-refresh workflow. To choose another interval:
```rust
config.section_mut::<LarablogConfig>().cache.check_interval = Some(30); // seconds; Some(0) checks on every use
```
`LARABLOG_CACHE_CHECK_INTERVAL` and `LARABLOG_CACHE` are also read. The index is refreshed on the first use
after that interval, including additions, deletions, renamed slugs, authors and categories. New metadata can
take up to the interval to appear. Draft visibility and scheduled publication times are evaluated on every
lookup, so a scheduled post becomes public on time without rebuilding its index. Rendered bodies are cached
by the path, modification time and size of their file.
To prepare an index during deployment, or make edited metadata visible immediately:
```bash
laravel larablog:cache # all collections
laravel larablog:cache blog # one collection
```
This command is optional. `larablog:check` also refreshes the index before validating files. With
`cache.enabled` set to `false`, nothing is kept and content is read on demand.
The cache lives in the memory of the process, which in Laravel Rust outlives the request. Each request of a
blog page also reads one snapshot of the collection, so the page is consistent while a file changes.
`larablog::scoped` gives a command or a test the same, and `larablog::flush()` forgets it, which is PHP's
`forgetScopedInstances()`.
## Checking
```bash
laravel larablog:check
laravel larablog:check --pending # also list links waiting for their post, with the day
```
Errors (a post without a title, a slug used twice in one language, broken YAML) are posts that are not
published at all, and a `post:` link to a folder that does not exist, in any post, scheduled ones included.
A link to a post not out yet is not an error. Warnings are posts missing a language. It exits 1 on errors,
for CI.
## Configuration
`LarablogConfig` is the configuration section. The keys and the defaults are those of `config/larablog.php`:
| `collections` | `blog` | The collections, by name. Each has the settings below |
| `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 `LocaleConfig`, else its `locale` |
| `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.*.views` | `blog.index`, `blog.show` | The views of its pages |
| `collections.*.per_page` | `12` | Posts per page of a listing |
| `collections.*.cards` | enabled, template `post`, path `img/blog` | Social cards |
| `collections.*.feed` | enabled, 20 posts | The feed of each language, at `/{path}/feed`. `title` and `description` are `Localized` |
| `show_scheduled` | `false` | Read from `LARABLOG_SHOW_SCHEDULED` |
| `show_drafts` | `false` | Read from `LARABLOG_SHOW_DRAFTS` |
| `words_per_minute` | `220` | For the reading time |
| `cache.enabled` | `true` | Read from `LARABLOG_CACHE` |
| `cache.check_interval` | `None` | 60 seconds in production and 0 elsewhere. Read from `LARABLOG_CACHE_CHECK_INTERVAL` |
| `markdown.html_input` | `Allow` | `Allow`, `Strip` or `Escape`. The content is written by the site's owner |
| `markdown.allow_unsafe_links` | `false` | |
| `markdown.external_links` | `true` | Links to other hosts open with `rel="noopener noreferrer"` and `target="_blank"` |
## Testing
```bash
cargo test
```
The suite runs on the application of `for_testing` against fixtures: the PHP package's own (a translated post,
one with no translation, a scheduled one, a draft, a post with no title and a duplicated slug) and fifteen
real posts of [Neoguias](https://neoguias.com) with its `_categories.yml` and `_authors.yml`, which exercise
conditional blocks in paragraphs and in list items, posts that go out on different days, tags and dates with
an offset, and which `larablog:check` must accept. Time is controlled with `app.travel_to`.
## Differences from the PHP package
- **The provider registers the routes**, with `LarablogServiceProvider::new().routes("blog")`, instead of
`Larablog::routes('blog')` in `routes/web.php`. `routes_with` takes a `MiddlewareGroup` for the array of
middleware.
- **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, and `url()` does not fail when the routes were not
registered. There is no Laralang integration: the default language of the application sits at the root and
the others under their code.
- **Facades are functions.** `Larablog::collection('blog')` is `larablog::collection("blog")?` and
`Larablog::collections()` is `larablog::collections()`. They are synchronous and read the manager from the
application's configuration, because Laravel Rust 0.1 can only resolve a service asynchronously.
`Feed::for($blog, $locale)` is `Feed::for_blog(&blog, locale)`, since `for` is a keyword.
- **Default arguments are `Option` or a second method.** `$locale = null` is `Option<&str>`;
`url($absolute = true)` is `url()` and `url_with(absolute)`; `blog.url(kind, locale, params, absolute)` takes
the parameters as pairs. `paginate` returns a `Pagination`, not Laravel's paginator.
- **Views get data, not objects**, because MiniJinja cannot call a Rust method (see [Views](#views)).
`alternates` is a list of pairs, to keep the order of the languages, and the listing gets `tags` too, which
a Blade view reads from `$blog->tags()`.
- **The views are shipped and overridable.** The PHP package ships none. `larablog:publish` is the
`vendor:publish` that Laravel Rust 0.1 lacks.
- **The cache is in the memory of the process**, not in a Laravel cache store, so `cache.store` is gone. The
signature of the files and the check interval work as in PHP, on the clock of the application, which
`app.travel` moves.
- **`larablog::collections()` is ordered by name**, not by the order of the configuration, and `categories()`
and `tags()` return lists, not arrays keyed by slug.
- **Dates are UTC and `Carbon::parse` is not here.** The formats are the ones above. A date with an offset is
kept as the same instant in UTC. `date_formatted` knows English, Spanish, Catalan, Galician, Portuguese,
French, Italian and German, and writes an ISO date for any other language.
- **The reading time counts words like PHP does** (`str_word_count`, which sees `información` as two words),
but not like PHP's `strip_tags`, which swallows everything between a `<` in a code sample and the next `>`.
On code-heavy posts the numbers differ from PHP's: of the 152 posts of Neoguias, 66 get the same minutes,
23 differ by one, and 63 by more, by a lot where PHP lost the code. Set `reading_time` in the frontmatter
to fix one.
- **A `noindex: true` post is hidden from robots** by the handler, with `Head::hidden_from_robots`, because a
view cannot call `head::merge`. In PHP the site's view does it.
- **YAML is `saphyr`, YAML 1.2.** `yes` and `no` are strings, and a date is text until a post reads it.
- **CommonMark is `comrak`**, with the table, strikethrough, autolink and task list extensions and the GFM tag
filter. Its output matches `league/commonmark` for everything on 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, because `comrak` has no block extension point; the rules are the PHP parser's.
## Sponsors
Larablog for Laravel Rust is supported by the following sponsors. Thank you for keeping it growing:
<p>
<a href="https://kenodo.com"><img src="art/logo-kenodo.png" width="24" alt="Kenodo"></a> <a href="https://kenodo.com">Kenodo</a>
<a href="https://andorradev.com"><img src="art/logo-andorradev.png" width="24" alt="AndorraDev"></a> <a href="https://andorradev.com">AndorraDev</a>
</p>
## Author
Created by [Edu Lazaro](https://edulazaro.com)
## License
Larablog for Laravel Rust is open-sourced software licensed under the [MIT license](LICENSE.md).