From 5ff3e9e94f6bfd7dbc83f390d76aed8631a84a54 Mon Sep 17 00:00:00 2001 From: JMARyA Date: Tue, 30 Jan 2024 08:14:17 +0100 Subject: [PATCH] fix: duplicate tag entries --- src/lib.rs | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index d8480ab..87e0ab6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,4 @@ -use std::collections::HashMap; +use std::collections::{HashMap, HashSet}; use txd::DataType; @@ -82,18 +82,25 @@ impl Index { serde_yaml::from_str(&frontmatter).unwrap(); if !ignore_inline_tags { - let tags = get_inline_tags(&content); + let mut tags = frontmatter + .as_mapping() + .unwrap() + .get("tags") + .map(|x| x.as_sequence().unwrap().clone()) + .unwrap_or_default(); + let inline_tags = get_inline_tags(&content); + + tags.extend(inline_tags.iter().map(|x| x.clone().into())); + + let mut unique_tags = HashSet::new(); + for tag in tags { + unique_tags.insert(tag); + } frontmatter .as_mapping_mut() .unwrap() - .entry("tags".into()) - .or_insert(tags.clone().into()) - .as_sequence_mut() - .unwrap() - .extend::>( - tags.iter().map(|x| x.clone().into()).collect(), - ); + .insert("tags".into(), unique_tags.into_iter().collect()); } let doc = Document { path, frontmatter };