Skip to content

Commit

Permalink
Simplify taxonomy term struct
Browse files Browse the repository at this point in the history
  • Loading branch information
Keats committed Feb 16, 2023
1 parent 5fb0867 commit ee96105
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 36 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## 0.17.0 (unreleased)

- Add `get_taxonomy_term` function
- Add slugify.paths_keep_dates option
- Add command to generate shell completions

## 0.16.1 (2022-08-14)

- Fix many Windows bugs
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "zola"
version = "0.16.1"
version = "0.17.0"
authors = ["Vincent Prouillet <hello@vincentprouillet.com>"]
edition = "2018"
license = "MIT"
Expand Down
43 changes: 11 additions & 32 deletions components/content/src/taxonomies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ pub struct SerializedTaxonomyTerm<'a> {
}

impl<'a> SerializedTaxonomyTerm<'a> {
pub fn from_item(item: &'a TaxonomyTerm, library: &'a Library) -> Self {
pub fn from_item(item: &'a TaxonomyTerm, library: &'a Library, include_pages: bool) -> Self {
let mut pages = vec![];

for p in &item.pages {
pages.push(SerializingPage::new(&library.pages[p], Some(library), false));
if include_pages {
for p in &item.pages {
pages.push(SerializingPage::new(&library.pages[p], Some(library), false));
}
}

SerializedTaxonomyTerm {
Expand All @@ -45,29 +47,6 @@ impl<'a> SerializedTaxonomyTerm<'a> {
}
}

#[derive(Debug, Clone, PartialEq, Serialize)]
pub struct SerializedTaxonomyTermWithoutPages<'a> {
name: &'a str,
slug: &'a str,
path: &'a str,
permalink: &'a str,
pages: Vec<SerializingPage<'a>>,
page_count: usize,
}

impl<'a> SerializedTaxonomyTermWithoutPages<'a> {
pub fn from_item(item: &'a TaxonomyTerm, _library: &'a Library) -> Self {
SerializedTaxonomyTermWithoutPages {
name: &item.name,
slug: &item.slug,
path: &item.path,
permalink: &item.permalink,
pages: vec!(),
page_count: item.pages.len(),
}
}
}

/// A taxonomy with all its pages
#[derive(Debug, Clone)]
pub struct TaxonomyTerm {
Expand Down Expand Up @@ -104,14 +83,14 @@ impl TaxonomyTerm {
}

pub fn serialize<'a>(&'a self, library: &'a Library) -> SerializedTaxonomyTerm<'a> {
SerializedTaxonomyTerm::from_item(self, library)
SerializedTaxonomyTerm::from_item(self, library, true)
}

pub fn serialize_without_pages<'a>(
&'a self,
library: &'a Library,
) -> SerializedTaxonomyTermWithoutPages<'a> {
SerializedTaxonomyTermWithoutPages::from_item(self, library)
) -> SerializedTaxonomyTerm<'a> {
SerializedTaxonomyTerm::from_item(self, library, false)
}

pub fn merge(&mut self, other: Self) {
Expand All @@ -136,7 +115,7 @@ pub struct SerializedTaxonomy<'a> {
impl<'a> SerializedTaxonomy<'a> {
pub fn from_taxonomy(taxonomy: &'a Taxonomy, library: &'a Library) -> Self {
let items: Vec<SerializedTaxonomyTerm> =
taxonomy.items.iter().map(|i| SerializedTaxonomyTerm::from_item(i, library)).collect();
taxonomy.items.iter().map(|i| SerializedTaxonomyTerm::from_item(i, library, true)).collect();
SerializedTaxonomy {
kind: &taxonomy.kind,
lang: &taxonomy.lang,
Expand Down Expand Up @@ -208,7 +187,7 @@ impl Taxonomy {
let mut context = Context::new();
context.insert("config", &config.serialize(&self.lang));
context.insert("lang", &self.lang);
context.insert("term", &SerializedTaxonomyTerm::from_item(item, library));
context.insert("term", &SerializedTaxonomyTerm::from_item(item, library, true));
context.insert("taxonomy", &self.kind);
context.insert("current_url", &self.permalink);
context.insert("current_path", &self.path);
Expand All @@ -231,7 +210,7 @@ impl Taxonomy {
let mut context = Context::new();
context.insert("config", &config.serialize(&self.lang));
let terms: Vec<SerializedTaxonomyTerm> =
self.items.iter().map(|i| SerializedTaxonomyTerm::from_item(i, library)).collect();
self.items.iter().map(|i| SerializedTaxonomyTerm::from_item(i, library, true)).collect();
context.insert("terms", &terms);
context.insert("lang", &self.lang);
context.insert("taxonomy", &self.kind);
Expand Down
4 changes: 2 additions & 2 deletions snapcraft.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: zola
version: 0.16.1
version: 0.17.0
summary: A fast static site generator in a single binary with everything built-in.
description: |
A fast static site generator in a single binary with everything built-in.
Expand All @@ -21,7 +21,7 @@ parts:
zola:
source-type: git
source: https://github.com/getzola/zola.git
source-tag: v0.16.1
source-tag: v0.17.0
plugin: rust
rust-channel: stable
build-packages:
Expand Down

0 comments on commit ee96105

Please sign in to comment.