mirror of
https://github.com/Lumither/nocturne.git
synced 2026-10-17 10:26:21 +00:00
feat(blog::components::check_update, README.md) add tracking filter
This commit is contained in:
4 files changed
+21
-8
No files matched your search
@@ -20,6 +20,7 @@ tracing-appender = "0.2.3"
|
|||||||
dirs = "6.0.0"
|
dirs = "6.0.0"
|
||||||
thiserror = "2.0.11"
|
thiserror = "2.0.11"
|
||||||
tokio = { version = "1.42.0", features = ["rt", "rt-multi-thread", "macros", "sync"] }
|
tokio = { version = "1.42.0", features = ["rt", "rt-multi-thread", "macros", "sync"] }
|
||||||
|
regex = "1.11.1"
|
||||||
dotenv = "0.15.0"
|
dotenv = "0.15.0"
|
||||||
uuid = { version = "1.13.2", features = ["v4"] }
|
uuid = { version = "1.13.2", features = ["v4"] }
|
||||||
futures = "0.3.31"
|
futures = "0.3.31"
|
||||||
|
|||||||
File renamed without changes.
@@ -1,3 +1,4 @@
|
|||||||
|
use std::sync::LazyLock;
|
||||||
use std::{collections::HashMap, fs::remove_dir_all, path::PathBuf};
|
use std::{collections::HashMap, fs::remove_dir_all, path::PathBuf};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@@ -10,6 +11,7 @@ use crate::{
|
|||||||
use markdown::MdFile;
|
use markdown::MdFile;
|
||||||
|
|
||||||
use git2::{Delta, Repository};
|
use git2::{Delta, Repository};
|
||||||
|
use regex::Regex;
|
||||||
use tracing::{error, warn};
|
use tracing::{error, warn};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
@@ -64,14 +66,17 @@ pub async fn fetch_deltas(
|
|||||||
|
|
||||||
// process deleted deltas before merging commit to prevent "file not found" os error
|
// process deleted deltas before merging commit to prevent "file not found" os error
|
||||||
for delta in commit_deltas.into_iter() {
|
for delta in commit_deltas.into_iter() {
|
||||||
// todo: limit scanning scope to post only OR extract merging logic to external component
|
let relative_file_path = delta
|
||||||
|
.new_path
|
||||||
|
.clone()
|
||||||
|
.expect("cannot parse modified post `new_path`");
|
||||||
|
|
||||||
|
if !should_delta_tracked(&relative_file_path) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if delta.status == Delta::Deleted {
|
if delta.status == Delta::Deleted {
|
||||||
let file_path = &git_work_dir.join(
|
let file_path = &git_work_dir.join(relative_file_path);
|
||||||
delta
|
|
||||||
.new_path
|
|
||||||
.expect("cannot parse modified post `new_path`"),
|
|
||||||
);
|
|
||||||
if let Some(id) = extract_post_id(&MdFile::from_file(file_path)?) {
|
if let Some(id) = extract_post_id(&MdFile::from_file(file_path)?) {
|
||||||
changes.push(Change::Delete(Delete {
|
changes.push(Change::Delete(Delete {
|
||||||
uuid: id,
|
uuid: id,
|
||||||
@@ -169,3 +174,10 @@ fn merge_changes(changes: Vec<Change>) -> Vec<Change> {
|
|||||||
|
|
||||||
merged
|
merged
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static TRACKED_DELTA_RULE: LazyLock<Regex> =
|
||||||
|
LazyLock::new(|| Regex::new(r"posts/\d{4}/[a-zA-Z0-9-]+/index\.md").unwrap());
|
||||||
|
|
||||||
|
fn should_delta_tracked(path: &PathBuf) -> bool {
|
||||||
|
TRACKED_DELTA_RULE.is_match(path.to_str().unwrap())
|
||||||
|
}
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
pub mod check_update;
|
pub mod check_update;
|
||||||
mod consistency_guard;
|
pub mod consistency_guard;
|
||||||
mod rag;
|
pub mod rag;
|
||||||
Reference in new issue
Block a user