This commit is contained in:
31
src/lib.rs
31
src/lib.rs
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user