feat: build.rs — génération automatique des pages HTML depuis CHANGELOG.md et ROADMAP.md
- build.rs convertit CHANGELOG.md → changelog.html et ROADMAP.md → help.html
- Injection automatique de la version Cargo.toml dans toutes les pages
- Correction du routage : /changelog et /help sans .html fonctionnent
- Templates changelog.tmpl.html et help.tmpl.html avec placeholders {{VERSION}}
- Plus jamais de désynchronisation entre .md et pages web !
- v0.2.0 affichée partout (index, changelog, help, API)
This commit is contained in:
+32
-23
@@ -63,33 +63,42 @@ async fn serve_static(
|
||||
let path = path.trim_start_matches('/');
|
||||
|
||||
// Par défaut, servir index.html
|
||||
let asset_path = if path.is_empty() { "index.html" } else { path };
|
||||
let asset_path = if path.is_empty() { "index.html".to_string() } else { path.to_string() };
|
||||
|
||||
match FrontendAssets::get(asset_path) {
|
||||
Some(content) => {
|
||||
let mime = mime_guess(asset_path);
|
||||
axum::http::Response::builder()
|
||||
.header("Content-Type", mime)
|
||||
.header("Cache-Control", "public, max-age=3600")
|
||||
// Essayer avec le chemin exact
|
||||
if let Some(content) = FrontendAssets::get(&asset_path) {
|
||||
let mime = mime_guess(&asset_path);
|
||||
return axum::http::Response::builder()
|
||||
.header("Content-Type", mime)
|
||||
.header("Cache-Control", "public, max-age=3600")
|
||||
.body(axum::body::Body::from(content.data.to_vec()))
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
// Essayer avec .html si pas d'extension
|
||||
if !asset_path.contains('.') {
|
||||
let html_path = format!("{}.html", asset_path);
|
||||
if let Some(content) = FrontendAssets::get(&html_path) {
|
||||
return axum::http::Response::builder()
|
||||
.header("Content-Type", "text/html; charset=utf-8")
|
||||
.body(axum::body::Body::from(content.data.to_vec()))
|
||||
.unwrap()
|
||||
}
|
||||
None => {
|
||||
// Fallback SPA: toutes les routes inconnues renvoient index.html
|
||||
if let Some(index) = FrontendAssets::get("index.html") {
|
||||
axum::http::Response::builder()
|
||||
.header("Content-Type", "text/html; charset=utf-8")
|
||||
.body(axum::body::Body::from(index.data.to_vec()))
|
||||
.unwrap()
|
||||
} else {
|
||||
axum::http::Response::builder()
|
||||
.status(axum::http::StatusCode::NOT_FOUND)
|
||||
.header("Content-Type", "text/plain")
|
||||
.body(axum::body::Body::from("404 — Page non trouvée"))
|
||||
.unwrap()
|
||||
}
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback SPA: toutes les routes inconnues renvoient index.html
|
||||
if let Some(index) = FrontendAssets::get("index.html") {
|
||||
axum::http::Response::builder()
|
||||
.header("Content-Type", "text/html; charset=utf-8")
|
||||
.body(axum::body::Body::from(index.data.to_vec()))
|
||||
.unwrap()
|
||||
} else {
|
||||
axum::http::Response::builder()
|
||||
.status(axum::http::StatusCode::NOT_FOUND)
|
||||
.header("Content-Type", "text/plain")
|
||||
.body(axum::body::Body::from("404 — Page non trouvée"))
|
||||
.unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
/// Devine le type MIME à partir de l'extension
|
||||
|
||||
Reference in New Issue
Block a user