added categories
This commit is contained in:
73
src/main.rs
73
src/main.rs
@@ -15,10 +15,12 @@ mod analysis;
|
||||
mod changelog;
|
||||
mod cli;
|
||||
mod entry;
|
||||
mod fs;
|
||||
mod rendering;
|
||||
|
||||
use crate::{
|
||||
cli::{Cli, Commands},
|
||||
fs::get_summary_data,
|
||||
rendering::{
|
||||
render_changelog_handler, render_page_handler, render_summary_handler, render_wiki_page,
|
||||
},
|
||||
@@ -64,11 +66,13 @@ pub struct Page {
|
||||
pub filename: String,
|
||||
pub title: String,
|
||||
pub datetime: String,
|
||||
pub category: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize, Clone, Debug)]
|
||||
pub struct WikiConfig {
|
||||
pub title: String,
|
||||
pub category: Option<String>,
|
||||
pub image: Option<String>,
|
||||
pub infobox: Option<IndexMap<String, String>>,
|
||||
pub content_file: Option<String>,
|
||||
@@ -154,46 +158,6 @@ async fn main() -> anyhow::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn get_summary_data(docs_dir: &PathBuf, is_static: bool) -> Vec<Page> {
|
||||
let mut pages = Vec::new();
|
||||
if let Ok(mut entries) = tokio::fs::read_dir(docs_dir).await {
|
||||
while let Ok(Some(entry)) = entries.next_entry().await {
|
||||
let path = entry.path();
|
||||
if path.extension().and_then(|s| s.to_str()) != Some("toml")
|
||||
|| path.file_name().and_then(|s| s.to_str()) == Some("_changelog.toml")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
let filename_str = if is_static {
|
||||
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 {
|
||||
if let Ok(config) = toml::from_str::<WikiConfig>(&content) {
|
||||
config.title
|
||||
} else {
|
||||
filename_str.clone()
|
||||
}
|
||||
} else {
|
||||
filename_str.clone()
|
||||
};
|
||||
|
||||
pages.push(Page {
|
||||
filename: filename_str,
|
||||
title,
|
||||
datetime: "".to_string(),
|
||||
});
|
||||
}
|
||||
}
|
||||
pages.sort_by(|a, b| a.title.cmp(&b.title));
|
||||
pages
|
||||
}
|
||||
|
||||
async fn run_build(docs_dir: PathBuf, out_dir: PathBuf, no_navigation: bool) -> anyhow::Result<()> {
|
||||
tracing::info!("Building static site to: {}", out_dir.display());
|
||||
|
||||
@@ -287,32 +251,3 @@ async fn serve_css() -> impl IntoResponse {
|
||||
Err(_) => (StatusCode::NOT_FOUND, "CSS not found").into_response(),
|
||||
}
|
||||
}
|
||||
|
||||
fn get_nav_links(dir: &PathBuf, current_file: &str) -> (Option<String>, Option<String>) {
|
||||
let mut files: Vec<String> = std::fs::read_dir(dir)
|
||||
.unwrap()
|
||||
.filter_map(|entry| {
|
||||
let path = entry.ok()?.path();
|
||||
if path.extension()? == "toml" {
|
||||
Some(path.file_name()?.to_str()?.to_string())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
|
||||
files.sort();
|
||||
let pos = files.iter().position(|f| f == current_file);
|
||||
match pos {
|
||||
Some(i) => {
|
||||
let prev = if i == 0 {
|
||||
Some(".".to_string())
|
||||
} else {
|
||||
files.get(i - 1).cloned()
|
||||
};
|
||||
let next = files.get(i + 1).cloned();
|
||||
(prev, next)
|
||||
}
|
||||
None => (None, None),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user