Add path to TaxonomyTerm

Closes #1336
This commit is contained in:
Vincent Prouillet 2021-02-22 21:27:50 +01:00
parent 7fc7ef4720
commit 2a46e07e74
4 changed files with 14 additions and 4 deletions

View file

@ -15,6 +15,7 @@
- Image processing now supports WebP
- Fix `zola serve` failing for some static files
- Fix `zola serve` not picking up directory renaming
- Add `path` to the taxonomy terms to be on par with pages and sections
## 0.13.0 (2021-01-09)

View file

@ -413,6 +413,7 @@ mod tests {
let taxonomy_item = TaxonomyItem {
name: "Something".to_string(),
slug: "something".to_string(),
path: "/tags/something".to_string(),
permalink: "https://vincent.is/tags/something/".to_string(),
pages: library.pages().keys().collect(),
};
@ -446,6 +447,7 @@ mod tests {
let taxonomy_item = TaxonomyItem {
name: "Something".to_string(),
slug: "something".to_string(),
path: "/some-tags/something/".to_string(),
permalink: "https://vincent.is/some-tags/something/".to_string(),
pages: library.pages().keys().collect(),
};

View file

@ -18,6 +18,7 @@ use utils::slugs::slugify_paths;
pub struct SerializedTaxonomyItem<'a> {
name: &'a str,
slug: &'a str,
path: &'a str,
permalink: &'a str,
pages: Vec<SerializingPage<'a>>,
}
@ -34,6 +35,7 @@ impl<'a> SerializedTaxonomyItem<'a> {
SerializedTaxonomyItem {
name: &item.name,
slug: &item.slug,
path: &item.path,
permalink: &item.permalink,
pages,
}
@ -45,6 +47,7 @@ impl<'a> SerializedTaxonomyItem<'a> {
pub struct TaxonomyItem {
pub name: String,
pub slug: String,
pub path: String,
pub permalink: String,
pub pages: Vec<DefaultKey>,
}
@ -73,16 +76,17 @@ impl TaxonomyItem {
.collect();
let (mut pages, ignored_pages) = sort_pages_by_date(data);
let item_slug = slugify_paths(name, config.slugify.taxonomies);
let permalink = if taxonomy.lang != config.default_language {
config.make_permalink(&format!("/{}/{}/{}", taxonomy.lang, taxo_slug, item_slug))
let path = if taxonomy.lang != config.default_language {
format!("/{}/{}/{}/", taxonomy.lang, taxo_slug, item_slug)
} else {
config.make_permalink(&format!("/{}/{}", taxo_slug, item_slug))
format!("/{}/{}/", taxo_slug, item_slug)
};
let permalink = config.make_permalink(&path);
// We still append pages without dates at the end
pages.extend(ignored_pages);
TaxonomyItem { name: name.to_string(), permalink, slug: item_slug, pages }
TaxonomyItem { name: name.to_string(), permalink, path, slug: item_slug, pages }
}
pub fn serialize<'a>(&'a self, library: &'a Library) -> SerializedTaxonomyItem<'a> {
@ -338,6 +342,7 @@ mod tests {
assert_eq!(tags.items[0].name, "db");
assert_eq!(tags.items[0].slug, "db");
assert_eq!(tags.items[0].permalink, "http://a-website.com/tags/db/");
assert_eq!(tags.items[0].path, "/tags/db/");
assert_eq!(tags.items[0].pages.len(), 1);
assert_eq!(tags.items[1].name, "js");
@ -438,6 +443,7 @@ mod tests {
assert_eq!(tags.items[1].name, "js");
assert_eq!(tags.items[1].slug, "js");
assert_eq!(tags.items[1].permalink, "http://a-website.com/tags/js/");
assert_eq!(tags.items[1].path, "/tags/js/");
assert_eq!(tags.items[1].pages.len(), 2);
assert_eq!(tags.items[2].name, "rust");

View file

@ -13,6 +13,7 @@ First, `TaxonomyTerm` has the following fields:
```ts
name: String;
slug: String;
path: String;
permalink: String;
pages: Array<Page>;
```