cleaned up routes
This commit is contained in:
19
src/main.rs
19
src/main.rs
@@ -143,7 +143,7 @@ async fn main() -> anyhow::Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_summary_data(docs_dir: &PathBuf) -> Vec<Page> {
|
async fn get_summary_data(docs_dir: &PathBuf, is_static: bool) -> Vec<Page> {
|
||||||
let mut pages = Vec::new();
|
let mut pages = Vec::new();
|
||||||
if let Ok(mut entries) = tokio::fs::read_dir(docs_dir).await {
|
if let Ok(mut entries) = tokio::fs::read_dir(docs_dir).await {
|
||||||
while let Ok(Some(entry)) = entries.next_entry().await {
|
while let Ok(Some(entry)) = entries.next_entry().await {
|
||||||
@@ -152,21 +152,26 @@ async fn get_summary_data(docs_dir: &PathBuf) -> Vec<Page> {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
let filename = entry.file_name();
|
let filename_str = if is_static {
|
||||||
let filename_str = filename.to_str().unwrap_or("");
|
entry.file_name().to_string_lossy().into_owned()
|
||||||
|
} else {
|
||||||
|
path.file_stem()
|
||||||
|
.map(|s| s.to_string_lossy().into_owned())
|
||||||
|
.unwrap_or_else(|| entry.file_name().to_string_lossy().into_owned())
|
||||||
|
};
|
||||||
|
|
||||||
let title = if let Ok(content) = tokio::fs::read_to_string(&path).await {
|
let title = if let Ok(content) = tokio::fs::read_to_string(&path).await {
|
||||||
if let Ok(config) = toml::from_str::<WikiConfig>(&content) {
|
if let Ok(config) = toml::from_str::<WikiConfig>(&content) {
|
||||||
config.title
|
config.title
|
||||||
} else {
|
} else {
|
||||||
filename_str.to_string()
|
filename_str.clone()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
filename_str.to_string()
|
filename_str.clone()
|
||||||
};
|
};
|
||||||
|
|
||||||
pages.push(Page {
|
pages.push(Page {
|
||||||
filename: filename_str.to_string(),
|
filename: filename_str,
|
||||||
title,
|
title,
|
||||||
datetime: "".to_string(),
|
datetime: "".to_string(),
|
||||||
});
|
});
|
||||||
@@ -180,7 +185,7 @@ async fn run_build(docs_dir: PathBuf, out_dir: PathBuf, no_navigation: bool) ->
|
|||||||
tracing::info!("Building static site to: {:?}", out_dir);
|
tracing::info!("Building static site to: {:?}", out_dir);
|
||||||
|
|
||||||
if !no_navigation {
|
if !no_navigation {
|
||||||
let pages = get_summary_data(&docs_dir).await;
|
let pages = get_summary_data(&docs_dir, true).await;
|
||||||
let static_pages: Vec<Page> = pages
|
let static_pages: Vec<Page> = pages
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|mut p| {
|
.map(|mut p| {
|
||||||
|
|||||||
@@ -202,7 +202,7 @@ pub async fn render_summary_handler(State(state): State<Arc<AppState>>) -> impl
|
|||||||
if state.no_navigation {
|
if state.no_navigation {
|
||||||
return (StatusCode::NOT_FOUND, "Disabled").into_response();
|
return (StatusCode::NOT_FOUND, "Disabled").into_response();
|
||||||
}
|
}
|
||||||
let pages = get_summary_data(&state.docs_dir).await;
|
let pages = get_summary_data(&state.docs_dir, false).await;
|
||||||
let mut context = Context::new();
|
let mut context = Context::new();
|
||||||
context.insert("title", "Wiki Index");
|
context.insert("title", "Wiki Index");
|
||||||
context.insert("files", &pages);
|
context.insert("files", &pages);
|
||||||
|
|||||||
Reference in New Issue
Block a user