From df6575fef4b99760d61aee29f033a8d4dcdc48cf Mon Sep 17 00:00:00 2001 From: Konstantin Andrikopoulos Date: Fri, 15 Nov 2024 15:01:57 +0100 Subject: [PATCH] Add option to have a prefix for a taxonomy As seen in #2449, it might be nice to not serve the taxonomies in the top level directory, but in a subfolder. This commit adds an option "prefix" to the taxonomy definition. The taxonomy then would be served in // instead of /. --- components/config/src/config/taxonomies.rs | 3 +++ components/site/src/lib.rs | 4 ++++ components/site/tests/site.rs | 1 + 3 files changed, 8 insertions(+) diff --git a/components/config/src/config/taxonomies.rs b/components/config/src/config/taxonomies.rs index 46842b5d6b..b19cd0f12d 100644 --- a/components/config/src/config/taxonomies.rs +++ b/components/config/src/config/taxonomies.rs @@ -5,6 +5,8 @@ use serde::{Deserialize, Serialize}; pub struct TaxonomyConfig { /// The name used in the URL, usually the plural pub name: String, + /// The prefix used in the URL. + pub prefix: Option, /// The slug according to the config slugification strategy pub slug: String, /// If this is set, the list of individual taxonomy term page will be paginated @@ -21,6 +23,7 @@ impl Default for TaxonomyConfig { fn default() -> Self { Self { name: String::new(), + prefix: None, slug: String::new(), paginate_by: None, paginate_path: None, diff --git a/components/site/src/lib.rs b/components/site/src/lib.rs index cd48c219e4..e36b7ce774 100644 --- a/components/site/src/lib.rs +++ b/components/site/src/lib.rs @@ -930,6 +930,10 @@ impl Site { components.push(taxonomy.lang.as_ref()); } + if let Some(prefix) = &taxonomy.kind.prefix { + components.push(prefix.as_ref()); + } + components.push(taxonomy.slug.as_ref()); let list_output = diff --git a/components/site/tests/site.rs b/components/site/tests/site.rs index bf0811e15a..bee04162cd 100644 --- a/components/site/tests/site.rs +++ b/components/site/tests/site.rs @@ -577,6 +577,7 @@ fn can_build_site_with_pagination_for_taxonomy() { let (_, _tmp_dir, public) = build_site_with_setup("test_site", |mut site| { site.config.languages.get_mut("en").unwrap().taxonomies.push(TaxonomyConfig { name: "tags".to_string(), + prefix: None, slug: "tags".to_string(), paginate_by: Some(2), paginate_path: None,