Add tag search.
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
2025-08-31 01:52:25 -05:00
parent 4e868abb01
commit 3ec4c11219
2 changed files with 56 additions and 0 deletions

View File

@@ -23,6 +23,7 @@ use std::ffi::OsStr;
use git2::{Repository, Signature, Commit};
use rocket::form::validate::Contains;
use tera::Tera;
use toml::value::Table;
use serde::Serialize;
@@ -756,6 +757,36 @@ impl<'a> Searcher<'a> {
results
}
pub fn tag_search(&self, root: &Page, tag: &str) -> Vec<SearchResult> {
let mut results: Vec<SearchResult> = vec![];
for child in &root.children {
if let Some(child_page) = self.historian.resolve_to_page(&child.full_name) {
for result in self.tag_search(&child_page, tag) {
results.push(result);
}
let mut content = String::new();
if let Ok(mut file) = fs::File::open(&child_page.path) {
file.read_to_string(&mut content).unwrap();
}
let mut metadata = Table::new();
parse_markdown(&content, &mut metadata);
if metadata.contains_key("tags") {
let tags = metadata.get("tags").unwrap();
if tags.is_array() && tags.as_array().contains(toml::Value::String(tag.to_owned())) {
results.push(SearchResult {
page: child_page,
matches: vec![]
});
}
}
}
}
results
}
fn do_search(&self, root: &Page, results: &mut Vec<SearchResult>, searcher: &mut grep::searcher::Searcher, matcher: &grep::regex::RegexMatcher) {
for child in &root.children {
if let Some(child_page) = self.historian.resolve_to_page(&child.full_name) {