mirror of
https://github.com/getzola/zola
synced 2024-11-10 06:14:19 +00:00
Simplify taxonomy term struct
This commit is contained in:
parent
5fb0867b3a
commit
ee961056c8
5 changed files with 19 additions and 36 deletions
|
@ -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
|
||||
|
|
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -4009,7 +4009,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "zola"
|
||||
version = "0.16.1"
|
||||
version = "0.17.0"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"clap_complete",
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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) {
|
||||
|
@ -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,
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
|
|
@ -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.
|
||||
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue