refactor: express custom directives with standard markdown constructs

This commit is contained in:
randogoth 2026-10-04 19:40:59 +03:00
parent e5583bbd89
commit 46f12b10da
7 changed files with 558 additions and 454 deletions

View file

@ -10,6 +10,9 @@ use std::path::Path;
/// Returned when the extension is absent or unrecognised.
pub const DEFAULT: &str = "application/octet-stream";
/// Plain text, which is also what marks a file as inlinable ASCII art.
pub const PLAIN_TEXT: &str = "text/plain; charset=utf-8";
/// The media type to serve `path` as, by extension, compared case-insensitively.
pub fn media_type(path: &Path) -> &'static str {
let Some(extension) = path.extension().and_then(|e| e.to_str()) else { return DEFAULT };
@ -34,7 +37,7 @@ const TABLE: &[(&str, &str)] = &[
("ico", "image/vnd.microsoft.icon"),
("avif", "image/avif"),
// Documents and data
("txt", "text/plain; charset=utf-8"),
("txt", PLAIN_TEXT),
("gmi", "text/gemini; charset=utf-8"),
("css", "text/css; charset=utf-8"),
("html", "text/html; charset=utf-8"),
@ -42,7 +45,7 @@ const TABLE: &[(&str, &str)] = &[
("json", "application/json"),
("toml", "application/toml"),
("pdf", "application/pdf"),
("asc", "text/plain; charset=utf-8"),
("asc", PLAIN_TEXT),
// Audio and video
("mp3", "audio/mpeg"),
("ogg", "audio/ogg"),