Skip to content

Commit df6575f

Browse files
committed
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 /<prefix>/<taxonomy_name> instead of /<taxonomy>.
1 parent ab0ad33 commit df6575f

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

Diff for: components/config/src/config/taxonomies.rs

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ use serde::{Deserialize, Serialize};
55
pub struct TaxonomyConfig {
66
/// The name used in the URL, usually the plural
77
pub name: String,
8+
/// The prefix used in the URL.
9+
pub prefix: Option<String>,
810
/// The slug according to the config slugification strategy
911
pub slug: String,
1012
/// If this is set, the list of individual taxonomy term page will be paginated
@@ -21,6 +23,7 @@ impl Default for TaxonomyConfig {
2123
fn default() -> Self {
2224
Self {
2325
name: String::new(),
26+
prefix: None,
2427
slug: String::new(),
2528
paginate_by: None,
2629
paginate_path: None,

Diff for: components/site/src/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -930,6 +930,10 @@ impl Site {
930930
components.push(taxonomy.lang.as_ref());
931931
}
932932

933+
if let Some(prefix) = &taxonomy.kind.prefix {
934+
components.push(prefix.as_ref());
935+
}
936+
933937
components.push(taxonomy.slug.as_ref());
934938

935939
let list_output =

Diff for: components/site/tests/site.rs

+1
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,7 @@ fn can_build_site_with_pagination_for_taxonomy() {
577577
let (_, _tmp_dir, public) = build_site_with_setup("test_site", |mut site| {
578578
site.config.languages.get_mut("en").unwrap().taxonomies.push(TaxonomyConfig {
579579
name: "tags".to_string(),
580+
prefix: None,
580581
slug: "tags".to_string(),
581582
paginate_by: Some(2),
582583
paginate_path: None,

0 commit comments

Comments
 (0)