//! TAG ICONS AS DATA — the starter catalogue (`icons.json`): each icon id of//! Notes' own drawn set with the common words, in several languages, that//! pick it for a tag. A tag is matched by its last word (`home/garden` →//! `garden`), without case or accents; a tag that matches none wears the//! fallback (`hash`). A person's own choice wins over all of it (the core//! keeps that).use serde::Deserialize;usesuper::find::fold_char;#[derive(Debug, Clone, Deserialize)]pubstructIcon {pub id: String,pub words: Vec<String>,}#[derive(Debug, Clone, Deserialize)]pubstructCatalogue {pub fallback: String,pub icons: Vec<Icon>,}/// The catalogue this build ships.pubfn catalogue() -> &'staticCatalogue {static SHIPPED: std::sync::OnceLock<Catalogue> = std::sync::OnceLock::new(); SHIPPED.get_or_init(|| serde_json::from_str(include_str!("icons.json")).expect("the tag icon catalogue reads"))}fn folded(word: &str) -> String { word.trim().chars().map(fold_char).collect()}/// Is `id` an icon a tag may wear (one of the catalogue's, or the fallback)?pubfn known(id: &str) -> bool {let shipped = catalogue(); id == shipped.fallback || shipped.icons.iter().any(|icon| icon.id == id)}/// The icon the catalogue picks for a tag: by its last word, then the/// fallback.pubfn for_tag(tag: &str) -> &'static str {let shipped = catalogue();let last = folded(tag.rsplit('/').next().unwrap_or(tag)); shipped .icons .iter() .find(|icon| icon.words.iter().any(|word| folded(word) == last)) .map_or(shipped.fallback.as_str(), |icon| icon.id.as_str())}