@@ -12,6 +12,7 @@ use config::Config;
12
12
use image:: GenericImageView ;
13
13
use library:: { Library , Taxonomy } ;
14
14
use utils:: site:: resolve_internal_link;
15
+ use utils:: slugs:: { slugify_paths, SlugifyStrategy } ;
15
16
16
17
#[ macro_use]
17
18
mod macros;
@@ -317,18 +318,20 @@ fn image_dimensions(path: &PathBuf) -> Result<(u32, u32)> {
317
318
pub struct GetTaxonomyUrl {
318
319
taxonomies : HashMap < String , HashMap < String , String > > ,
319
320
default_lang : String ,
321
+ slugify : SlugifyStrategy ,
320
322
}
323
+
321
324
impl GetTaxonomyUrl {
322
- pub fn new ( default_lang : & str , all_taxonomies : & [ Taxonomy ] ) -> Self {
325
+ pub fn new ( default_lang : & str , all_taxonomies : & [ Taxonomy ] , slugify : SlugifyStrategy ) -> Self {
323
326
let mut taxonomies = HashMap :: new ( ) ;
324
327
for taxo in all_taxonomies {
325
328
let mut items = HashMap :: new ( ) ;
326
329
for item in & taxo. items {
327
- items. insert ( item. name . clone ( ) , item. permalink . clone ( ) ) ;
330
+ items. insert ( slugify_paths ( & item. name . clone ( ) , slugify ) , item. permalink . clone ( ) ) ;
328
331
}
329
332
taxonomies. insert ( format ! ( "{}-{}" , taxo. kind. name, taxo. kind. lang) , items) ;
330
333
}
331
- Self { taxonomies, default_lang : default_lang. to_string ( ) }
334
+ Self { taxonomies, default_lang : default_lang. to_string ( ) , slugify : slugify }
332
335
}
333
336
}
334
337
impl TeraFn for GetTaxonomyUrl {
@@ -358,7 +361,7 @@ impl TeraFn for GetTaxonomyUrl {
358
361
}
359
362
} ;
360
363
361
- if let Some ( permalink) = container. get ( & name) {
364
+ if let Some ( permalink) = container. get ( & slugify_paths ( & name, self . slugify ) ) {
362
365
return Ok ( to_value ( permalink) . unwrap ( ) ) ;
363
366
}
364
367
@@ -650,7 +653,9 @@ mod tests {
650
653
let tags_fr = Taxonomy { kind : taxo_config_fr, items : vec ! [ tag_fr] } ;
651
654
652
655
let taxonomies = vec ! [ tags. clone( ) , tags_fr. clone( ) ] ;
653
- let static_fn = GetTaxonomyUrl :: new ( & config. default_language , & taxonomies) ;
656
+ let static_fn =
657
+ GetTaxonomyUrl :: new ( & config. default_language , & taxonomies, config. slugify . taxonomies ) ;
658
+
654
659
// can find it correctly
655
660
let mut args = HashMap :: new ( ) ;
656
661
args. insert ( "kind" . to_string ( ) , to_value ( "tags" ) . unwrap ( ) ) ;
@@ -659,6 +664,16 @@ mod tests {
659
664
static_fn. call( & args) . unwrap( ) ,
660
665
to_value( "http://a-website.com/tags/programming/" ) . unwrap( )
661
666
) ;
667
+
668
+ // can find it correctly with inconsistent capitalisation
669
+ let mut args = HashMap :: new ( ) ;
670
+ args. insert ( "kind" . to_string ( ) , to_value ( "tags" ) . unwrap ( ) ) ;
671
+ args. insert ( "name" . to_string ( ) , to_value ( "programming" ) . unwrap ( ) ) ;
672
+ assert_eq ! (
673
+ static_fn. call( & args) . unwrap( ) ,
674
+ to_value( "http://a-website.com/tags/programming/" ) . unwrap( )
675
+ ) ;
676
+
662
677
// works with other languages
663
678
let mut args = HashMap :: new ( ) ;
664
679
args. insert ( "kind" . to_string ( ) , to_value ( "tags" ) . unwrap ( ) ) ;
0 commit comments