diff --git a/src/main.rs b/src/main.rs index 9a3a9fc..06f11b9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -57,7 +57,7 @@ async fn main() { } async fn index_handler(State(state): State) -> impl IntoResponse { - match render_template("index.html", &state, Some(50)).await { + match render_template("index.html", &state).await { Ok(html) => Html(html).into_response(), Err(e) => (StatusCode::INTERNAL_SERVER_ERROR, e).into_response(), } @@ -67,7 +67,7 @@ async fn all_handler(State(state): State, Path(page): Path) -> if page.contains("..") { return (StatusCode::NOT_FOUND, "Invalid path").into_response(); } - match render_template(&format!("page_{}.html", page), &state, None).await { + match render_template(&format!("page_{}.html", page), &state).await { Ok(html) => Html(html).into_response(), Err(e) => (StatusCode::INTERNAL_SERVER_ERROR, e).into_response(), } @@ -97,14 +97,13 @@ async fn post_handler( async fn render_template( template_name: &str, state: &AppState, - limit: Option, ) -> Result { let template_path = format!("templates/{}", template_name); let template_content = std::fs::read_to_string(&template_path) .map_err(|e| format!("Failed to read template: {}", e))?; let manager = state.post_manager.read().await; - template_engine::render_template(&template_content, &*manager, None, limit) + template_engine::render_template(&template_content, &*manager, None) } async fn render_post_template(state: &AppState, post_name: String) -> Result { @@ -112,5 +111,5 @@ async fn render_post_template(state: &AppState, post_name: String) -> Result Result<(), String> { self.posts.clear(); + // Get timestamps from git history + let git_timestamps = self.get_post_timestamps()?; + let entries = fs::read_dir(&self.posts_dir) .map_err(|e| format!("Failed to read posts directory: {}", e))?; @@ -162,14 +165,19 @@ impl PostManager { let html_content = markdown_to_html(&markdown_content); - // Mock creation date for now - let metadata = fs::metadata(&path) - .map_err(|e| format!("Failed to read file metadata: {}", e))?; - let created_at = metadata - .created() - .or_else(|_| metadata.modified()) - .map(|t| DateTime::::from(t)) - .unwrap_or_else(|_| Utc::now()); + // Use git timestamp if available, otherwise fall back to file metadata + let created_at = git_timestamps + .get(&name) + .copied() + .or_else(|| { + let metadata = fs::metadata(&path).ok()?; + metadata + .created() + .or_else(|_| metadata.modified()) + .ok() + .map(|t| DateTime::::from(t)) + }) + .unwrap_or_else(|| Utc::now()); let post = Post { name: name.clone(), diff --git a/src/template_engine.rs b/src/template_engine.rs index a3efb02..5ca3f3b 100644 --- a/src/template_engine.rs +++ b/src/template_engine.rs @@ -6,7 +6,6 @@ pub fn render_template( template: &str, post_manager: &PostManager, current_post: Option<&str>, - limit_override: Option, ) -> Result { let mut result = template.to_string(); @@ -19,7 +18,7 @@ pub fn render_template( } // Process post-list tag - result = process_post_list(&result, post_manager, limit_override)?; + result = process_post_list(&result, post_manager)?; Ok(result) } @@ -75,7 +74,6 @@ fn process_post_html( fn process_post_list( template: &str, post_manager: &PostManager, - limit_override: Option, ) -> Result { let post_list_regex = Regex::new(r#"\$"#).unwrap(); @@ -85,7 +83,7 @@ fn process_post_list( let full_match = cap.get(0).unwrap().as_str(); let limit_attr = cap.get(1).and_then(|m| m.as_str().parse::().ok()); - let limit = limit_override.or(limit_attr); + let limit = limit_attr; let posts = if let Some(l) = limit { post_manager.get_posts_limited(l) diff --git a/templates/header.html b/templates/header.html index f43f7a9..0d7121a 100644 --- a/templates/header.html +++ b/templates/header.html @@ -18,6 +18,11 @@ padding-bottom: 10px; margin-bottom: 30px; } + nav span { + font-size: 1.2em; + font-weight: bold; + margin-right: 20px; + } nav a { margin-right: 20px; text-decoration: none; @@ -73,6 +78,7 @@ diff --git a/templates/index.html b/templates/index.html index 45a58fd..d2c6a36 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1,4 +1,4 @@ $

Recent Posts

- $ + $ $ diff --git a/templates/all.html b/templates/page_all.html similarity index 100% rename from templates/all.html rename to templates/page_all.html