11use std:: { fs, path:: Path , time} ;
22
33use serde_json:: json;
4- use wax:: { Glob , Pattern } ;
54
65use crate :: {
76 types:: { CountryData , ToCollection } ,
8- utils:: { diff_countries, get_country, read_config} ,
7+ utils:: {
8+ diff_countries, get_country, is_match, read_config, rewrite_if_some, rewrite_if_some_option,
9+ } ,
910} ;
11+ use wax:: Glob ;
1012
1113pub fn build ( ) {
1214 let config = read_config ( ) ;
@@ -28,50 +30,55 @@ pub fn build() {
2830 {
2931 let dissolved_time = time:: Instant :: now ( ) ;
3032
31- if tags. len ( ) == 0 {
32- for country_id in & config. main . layers {
33- countries. push ( get_country ( country_id. to_owned ( ) ) ) ;
34- }
35- } else {
36- for country_id in & config. main . layers {
37- let country = get_country ( country_id. to_owned ( ) ) ;
38-
39- match & country. config . tags {
40- Some ( tags) => {
41- let mut matches = false ;
42- for glob in & globs {
43- for tag in tags {
44- if glob. is_match ( tag. as_str ( ) ) {
45- matches = true ;
46- }
47- }
48- }
49-
50- if !matches {
51- continue ;
52- }
53-
54- countries. push ( country) ;
55- }
56- None => {
57- continue ;
58- }
59- }
33+ for country_id in & config. main . layers {
34+ let country = get_country ( country_id. to_owned ( ) ) ;
35+
36+ if is_match ( & country. config . tags , & globs) {
37+ countries. push ( country) ;
6038 }
6139 }
6240
6341 println ! ( "Dissolved in {:?}" , dissolved_time. elapsed( ) ) ;
6442 }
6543
66- // TODO: Add country_rewrite support
67-
68- let countries = {
44+ let countries: Vec < CountryData > = {
6945 let diff_time = time:: Instant :: now ( ) ;
7046
71- let countries = diff_countries ( countries) ;
47+ let mut countries = diff_countries ( countries) ;
7248
7349 println ! ( "Diffed in {:?}" , diff_time. elapsed( ) ) ;
7450
51+ countries. iter_mut ( ) . for_each ( |c| {
52+ if !processing_item. show_markers . unwrap_or ( true ) {
53+ c. markers = vec ! [ ] ;
54+ }
55+
56+ for country_rewrite in processing_item. countries_rewrite . clone ( ) . unwrap_or ( vec ! [ ] ) {
57+ let tags = country_rewrite. tags . unwrap_or ( vec ! [ ] ) ;
58+ let globs: Vec < Glob > = tags. iter ( ) . map ( |tag| Glob :: new ( tag) . unwrap ( ) ) . collect ( ) ;
59+
60+ if is_match ( & c. config . tags , & globs) {
61+ rewrite_if_some ( country_rewrite. properties . name , & mut c. config . name ) ;
62+ rewrite_if_some (
63+ country_rewrite. properties . description ,
64+ & mut c. config . description ,
65+ ) ;
66+ rewrite_if_some (
67+ country_rewrite. properties . foundation_date ,
68+ & mut c. config . foundation_date ,
69+ ) ;
70+ rewrite_if_some ( country_rewrite. properties . flag , & mut c. config . flag ) ;
71+ rewrite_if_some_option (
72+ country_rewrite. properties . about ,
73+ & mut c. config . about ,
74+ ) ;
75+ rewrite_if_some ( country_rewrite. properties . fill , & mut c. config . fill ) ;
76+ rewrite_if_some ( country_rewrite. properties . stroke , & mut c. config . stroke ) ;
77+ rewrite_if_some_option ( country_rewrite. properties . tags , & mut c. config . tags ) ;
78+ }
79+ }
80+ } ) ;
81+
7582 countries
7683 } ;
7784
0 commit comments