Skip to content

Commit

Permalink
Add option to have a prefix for a taxonomy
Browse files Browse the repository at this point in the history
As seen in getzola#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>.
  • Loading branch information
Mandragorian committed Nov 15, 2024
1 parent ab0ad33 commit df6575f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions components/config/src/config/taxonomies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
/// 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
Expand All @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions components/site/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
1 change: 1 addition & 0 deletions components/site/tests/site.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit df6575f

Please sign in to comment.