| Crates.io | flatpage |
| lib.rs | flatpage |
| version | 0.2.1 |
| created_at | 2022-07-01 06:37:14.775146+00 |
| updated_at | 2025-07-29 01:33:09.300465+00 |
| description | A simple file system based markdown flat page |
| homepage | |
| repository | https://github.com/imbolc/flatpage |
| max_upload_size | |
| id | 616962 |
| size | 28,835 |
A simple file system based markdown flat page.
Only characters allowed in urls are ASCII, numbers and hyphen with underscore.
Urls map to files by simply substituting / to ^ and adding .md extension.
I believe it should eliminate all kinds of security issues.
| url | file name |
|---|---|
/ |
^.md |
/foo/bar-baz |
^foo^bar-baz.md |
File could provide title and description in a yaml-based frontmatter, if there's
no frontmatter the first line would be considered the title (and cleaned from
possible header marker #).
| File content | title |
description |
body |
html() |
|---|---|---|---|---|
# FooBar |
"Foo" |
None |
"# Foo\nBar" |
"<h1>Foo</h1>\n<p>Bar</p>\n" |
---description: Bar---# Foo |
"Foo" |
Some("Bar") |
"# Foo" |
"<h1>Foo</h1>\n" |
---title: Foodescription: Bar--- |
"Foo" |
Some("Bar") |
"" |
"" |
let root_folder = "./";
if let Some(home) = flatpage::FlatPage::<()>::by_url(root_folder, "/").unwrap() {
println!("title: {}", home.title);
println!("description: {:?}", home.description);
println!("markdown body: {}", home.body);
println!("html body: {}", home.html());
} else {
println!("No home page");
}
You can define extra statically typed frontmatter fields
#[derive(Debug, serde::Deserialize)]
struct Extra {
slug: String,
}
let _page = flatpage::FlatPage::<Extra>::by_url("./", "/").unwrap();
It's a common for a page to have a list of related pages. To avoid reading all
the files each time, you can use [FlatPageStore] to cache pages metadata
(titles and descriptions).
let root_folder = "./";
let store = flatpage::FlatPageStore::read_dir(root_folder).unwrap();
if let Some(meta) = store.meta_by_url("/") {
println!("title: {}", meta.title);
println!("description: {:?}", meta.description);
} else {
println!("No home page");
}
Please run .pre-commit.sh before sending a PR, it will check everything.
This project is licensed under the MIT license.