Fix post indexing
This commit is contained in:
@@ -20,7 +20,9 @@ struct Entry {
|
||||
#[allow(dead_code)]
|
||||
short_name: String,
|
||||
file_path: String,
|
||||
timestamp: DateTime<Utc>,
|
||||
created_timestamp: DateTime<Utc>,
|
||||
#[allow(dead_code)]
|
||||
modified_timestamp: DateTime<Utc>,
|
||||
status: i32,
|
||||
}
|
||||
|
||||
@@ -47,7 +49,9 @@ impl PostManager {
|
||||
|
||||
fn query_posts(&self) -> Result<HashMap<String, Entry>, String> {
|
||||
let output = Command::new("git")
|
||||
.arg("whatchanged")
|
||||
.arg("log")
|
||||
.arg("--raw")
|
||||
.arg("--no-merges")
|
||||
.arg("--pretty=%h - %ad - %s")
|
||||
.arg("--date=unix")
|
||||
.arg("--")
|
||||
@@ -99,16 +103,20 @@ impl PostManager {
|
||||
let status = parts[4]; // A (add), D (delete), M (modify)
|
||||
let file_path = parts[5];
|
||||
|
||||
if let Some(file_name) = file_path.strip_prefix("posts/") {
|
||||
if let Some(name) = file_name.strip_suffix(".md") {
|
||||
// Only update if we don't have a timestamp yet (latest commit wins)
|
||||
result.entry(name.to_string()).or_insert(Entry {
|
||||
short_name: name.to_string(),
|
||||
file_path: file_path.to_string(),
|
||||
timestamp,
|
||||
status: if status == "D" { -1 } else { 1 },
|
||||
});
|
||||
}
|
||||
let fn_ = file_path
|
||||
.strip_prefix("posts/")
|
||||
.and_then(|s| s.strip_suffix(".md"));
|
||||
if let Some(name) = fn_ {
|
||||
let entry = result.entry(name.to_string()).or_insert(Entry {
|
||||
short_name: name.to_string(),
|
||||
file_path: file_path.to_string(),
|
||||
created_timestamp: timestamp,
|
||||
modified_timestamp: timestamp,
|
||||
status: if status == "D" { -1 } else { 1 },
|
||||
});
|
||||
|
||||
// Always use the oldest timestamp for posts creation dates
|
||||
entry.created_timestamp = timestamp;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -137,9 +145,9 @@ impl PostManager {
|
||||
filename: entry.file_path,
|
||||
markdown_content,
|
||||
html_content,
|
||||
created_at: entry.timestamp,
|
||||
created_at: entry.created_timestamp,
|
||||
};
|
||||
eprintln!("Loaded post: {} ({})", name, entry.timestamp);
|
||||
eprintln!("Loaded post: {} ({})", name, entry.created_timestamp);
|
||||
self.posts.insert(name, post);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user