From 2f309bd3897c629af7c29b0042749c4166afa04e Mon Sep 17 00:00:00 2001 From: Artemy Date: Thu, 23 May 2024 13:09:49 +0300 Subject: [PATCH] feat: tags --- src/build.rs | 22 +++++++++++++++++++--- src/templates/config.toml | 4 +--- src/types.rs | 8 +------- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/build.rs b/src/build.rs index 04e2072..efbed33 100644 --- a/src/build.rs +++ b/src/build.rs @@ -2,7 +2,7 @@ use std::{fs, path::Path}; use geojson::{Feature, FeatureCollection}; use serde_json::json; -use wax::Glob; +use wax::{Glob, Pattern}; use crate::{ types::CountryData, @@ -19,15 +19,31 @@ pub fn build() { let mut countries: Vec = vec![]; + let tags = processing_item.tags.unwrap_or(vec!["*".to_string()]); + let globs: Vec = tags.iter().map(|tag| Glob::new(tag).unwrap()).collect(); + for country_id in &config.main.layers { let mut country = get_country(country_id.to_owned()); - // TODO: Add tags support + let mut matches = false; + for glob in &globs { + for tag in &country.config.tags.clone().unwrap_or(vec![]) { + if glob.is_match(tag.as_str()) { + matches = true; + } + } + } + + if !matches { + continue; + } features.append(&mut country.geo.features); countries.push(country); } + // TODO: Country diff + // TODO: Add country_rewrite support // TODO: let countries = vec![rewrite_info]; @@ -40,7 +56,7 @@ pub fn build() { } .to_string(); - let countries = serde_json::to_string(&serde_json::Map::from_iter( + let countries = serde_json::to_string_pretty(&serde_json::Map::from_iter( countries .iter() .map(|country| (country.id.clone(), json!(country.config))), diff --git a/src/templates/config.toml b/src/templates/config.toml index a12faa3..ce3a1e3 100644 --- a/src/templates/config.toml +++ b/src/templates/config.toml @@ -16,9 +16,7 @@ output_folder = "./out/map" # Include or exclude countries based on tags # Glob syntax is supported -# [processing.tags] -# include = [] # [] = not filtered -# exclude = ["test", "test2"] +# tags = ["test-[!2]"] # Rewrite properties of all countries. All fields are optional. # [processing.countries_rewrite] diff --git a/src/types.rs b/src/types.rs index 0888c85..0728a3e 100644 --- a/src/types.rs +++ b/src/types.rs @@ -74,17 +74,11 @@ pub struct ProcessingConfig { pub show_markers: Option, pub output_folder: String, - pub tags: Option, + pub tags: Option>, pub countries_rewrite: Option, pub public: Option, } -#[derive(Debug, Serialize, Deserialize, Clone)] -pub struct ProcessingTagsConfig { - pub include: Option>, - pub exclude: Option>, -} - #[derive(Debug, Serialize, Deserialize, Clone)] pub struct CountryRewriteConfig { pub name: Option,