add fix for (#1135) Taxonomies with identical slugs now get merged (#1136)

This commit is contained in:
Sam Vente 2020-08-18 12:59:33 +02:00 committed by GitHub
parent 7666043b16
commit 05646ab573
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 73 additions and 3 deletions

View file

@ -189,7 +189,10 @@ pub fn find_taxonomies(config: &Config, library: &Library) -> Result<Vec<Taxonom
let taxonomies_def = {
let mut m = HashMap::new();
for t in &config.taxonomies {
m.insert(format!("{}-{}", t.name, t.lang), t);
m.insert(
format!("{}-{}", slugify_paths(&t.name, config.slugify.taxonomies), t.lang),
t,
);
}
m
};
@ -197,7 +200,8 @@ pub fn find_taxonomies(config: &Config, library: &Library) -> Result<Vec<Taxonom
let mut all_taxonomies = HashMap::new();
for (key, page) in library.pages() {
for (name, val) in &page.meta.taxonomies {
let taxo_key = format!("{}-{}", name, page.lang);
let taxo_key =
format!("{}-{}", slugify_paths(name, config.slugify.taxonomies), page.lang);
if taxonomies_def.contains_key(&taxo_key) {
all_taxonomies.entry(taxo_key.clone()).or_insert_with(HashMap::new);
@ -710,4 +714,70 @@ mod tests {
);
assert_eq!(categories.items[1].pages.len(), 1);
}
#[test]
fn taxonomies_are_groupted_by_slug() {
let mut config = Config::default();
let mut library = Library::new(2, 0, false);
config.taxonomies = vec![
TaxonomyConfig {
name: "test-taxonomy".to_string(),
lang: config.default_language.clone(),
..TaxonomyConfig::default()
},
TaxonomyConfig {
name: "test taxonomy".to_string(),
lang: config.default_language.clone(),
..TaxonomyConfig::default()
},
TaxonomyConfig {
name: "test-taxonomy ".to_string(),
lang: config.default_language.clone(),
..TaxonomyConfig::default()
},
TaxonomyConfig {
name: "Test-Taxonomy ".to_string(),
lang: config.default_language.clone(),
..TaxonomyConfig::default()
},
];
let mut page1 = Page::default();
let mut taxo_page1 = HashMap::new();
taxo_page1
.insert("test-taxonomy".to_string(), vec!["term1".to_string(), "term2".to_string()]);
page1.meta.taxonomies = taxo_page1;
page1.lang = config.default_language.clone();
library.insert_page(page1);
let mut page2 = Page::default();
let mut taxo_page2 = HashMap::new();
taxo_page2
.insert("test taxonomy".to_string(), vec!["term2".to_string(), "term3".to_string()]);
page2.meta.taxonomies = taxo_page2;
page2.lang = config.default_language.clone();
library.insert_page(page2);
let mut page3 = Page::default();
let mut taxo_page3 = HashMap::new();
taxo_page3.insert("test-taxonomy ".to_string(), vec!["term4".to_string()]);
page3.meta.taxonomies = taxo_page3;
page3.lang = config.default_language.clone();
library.insert_page(page3);
let mut page4 = Page::default();
let mut taxo_page4 = HashMap::new();
taxo_page4.insert("Test-Taxonomy ".to_string(), vec!["term8".to_string()]);
page4.meta.taxonomies = taxo_page4;
page4.lang = config.default_language.clone();
library.insert_page(page4);
// taxonomies get merged correctly
let taxonomies = find_taxonomies(&config, &library).unwrap();
assert_eq!(taxonomies.len(), 1);
// merged taxonomies contains all of the terms
let term = taxonomies.iter().next().unwrap();
assert_eq!(term.items.len(), 5);
}
}

View file

@ -64,4 +64,4 @@ The taxonomy pages are then available at the following paths:
$BASE_URL/$NAME/ (taxonomy)
$BASE_URL/$NAME/$SLUG (taxonomy entry)
```
Note that taxonomies are case insensitive so terms that have the same slug will get merged, e.g. sections and pages containing the tag "example" will be shown in the same taxonomy page as ones containing "Example"