mirror of
https://github.com/getzola/zola
synced 2024-11-10 06:14:19 +00:00
Add permalink to Taxonomy (#1516)
* Add permalink to Taxonomy * Document permalink addition to TaxonomyConfig
This commit is contained in:
parent
98b110ba14
commit
57705aa82e
4 changed files with 23 additions and 2 deletions
|
@ -422,6 +422,7 @@ mod tests {
|
|||
kind: taxonomy_def,
|
||||
lang: "en".to_owned(),
|
||||
slug: "tags".to_string(),
|
||||
permalink: "/tags/".to_string(),
|
||||
items: vec![taxonomy_item.clone()],
|
||||
};
|
||||
let paginator = Paginator::from_taxonomy(&taxonomy, &taxonomy_item, &library);
|
||||
|
@ -457,6 +458,7 @@ mod tests {
|
|||
kind: taxonomy_def,
|
||||
lang: "en".to_owned(),
|
||||
slug: "some-tags".to_string(),
|
||||
permalink: "/some-tags/".to_string(),
|
||||
items: vec![taxonomy_item.clone()],
|
||||
};
|
||||
let paginator = Paginator::from_taxonomy(&taxonomy, &taxonomy_item, &library);
|
||||
|
|
|
@ -108,6 +108,7 @@ impl PartialEq for TaxonomyItem {
|
|||
pub struct SerializedTaxonomy<'a> {
|
||||
kind: &'a TaxonomyConfig,
|
||||
lang: &'a str,
|
||||
permalink: &'a str,
|
||||
items: Vec<SerializedTaxonomyItem<'a>>,
|
||||
}
|
||||
|
||||
|
@ -115,7 +116,12 @@ impl<'a> SerializedTaxonomy<'a> {
|
|||
pub fn from_taxonomy(taxonomy: &'a Taxonomy, library: &'a Library) -> Self {
|
||||
let items: Vec<SerializedTaxonomyItem> =
|
||||
taxonomy.items.iter().map(|i| SerializedTaxonomyItem::from_item(i, library)).collect();
|
||||
SerializedTaxonomy { kind: &taxonomy.kind, lang: &taxonomy.lang, items }
|
||||
SerializedTaxonomy {
|
||||
kind: &taxonomy.kind,
|
||||
lang: &taxonomy.lang,
|
||||
permalink: &taxonomy.permalink,
|
||||
items,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -125,6 +131,7 @@ pub struct Taxonomy {
|
|||
pub kind: TaxonomyConfig,
|
||||
pub lang: String,
|
||||
pub slug: String,
|
||||
pub permalink: String,
|
||||
// this vec is sorted by the count of item
|
||||
pub items: Vec<TaxonomyItem>,
|
||||
}
|
||||
|
@ -159,7 +166,14 @@ impl Taxonomy {
|
|||
false
|
||||
}
|
||||
});
|
||||
Taxonomy { kind, slug, lang: lang.to_owned(), items: sorted_items }
|
||||
let path = if lang != config.default_language {
|
||||
format!("/{}/{}/", lang, slug)
|
||||
} else {
|
||||
format!("/{}/", slug)
|
||||
};
|
||||
let permalink = config.make_permalink(&path);
|
||||
|
||||
Taxonomy { kind, slug, lang: lang.to_owned(), permalink, items: sorted_items }
|
||||
}
|
||||
|
||||
pub fn len(&self) -> usize {
|
||||
|
|
|
@ -202,12 +202,14 @@ mod tests {
|
|||
kind: taxo_config,
|
||||
lang: config.default_language.clone(),
|
||||
slug: "tags".to_string(),
|
||||
permalink: "/tags/".to_string(),
|
||||
items: vec![tag],
|
||||
};
|
||||
let tags_fr = Taxonomy {
|
||||
kind: taxo_config_fr,
|
||||
lang: "fr".to_owned(),
|
||||
slug: "tags".to_string(),
|
||||
permalink: "/fr/tags/".to_string(),
|
||||
items: vec![tag_fr],
|
||||
};
|
||||
|
||||
|
@ -278,12 +280,14 @@ mod tests {
|
|||
kind: taxo_config,
|
||||
lang: config.default_language.clone(),
|
||||
slug: "tags".to_string(),
|
||||
permalink: "/tags/".to_string(),
|
||||
items: vec![tag],
|
||||
};
|
||||
let tags_fr = Taxonomy {
|
||||
kind: taxo_config_fr,
|
||||
lang: "fr".to_owned(),
|
||||
slug: "tags".to_string(),
|
||||
permalink: "/fr/tags/".to_string(),
|
||||
items: vec![tag_fr],
|
||||
};
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ paginate_by: Number?;
|
|||
paginate_path: String?;
|
||||
feed: Bool;
|
||||
lang: String;
|
||||
permalink: String;
|
||||
```
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue