mirror of
https://github.com/zensical/zensical.git
synced 2026-08-26 09:06:49 +00:00
refactor: allow custom metadata in navigation templates (#291)
Signed-off-by: squidfunk <martin.donath@squidfunk.com>
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
|
||||
//! Navigation.
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
use std::hash::{DefaultHasher, Hash, Hasher};
|
||||
|
||||
use ahash::HashMap;
|
||||
@@ -40,7 +41,6 @@ use super::page::Page;
|
||||
|
||||
mod item;
|
||||
mod iter;
|
||||
mod meta;
|
||||
|
||||
pub use item::NavigationItem;
|
||||
use iter::Iter;
|
||||
@@ -124,7 +124,7 @@ impl Navigation {
|
||||
}
|
||||
|
||||
// Extract page metadata for selected keys
|
||||
item.meta = Some(page.meta.clone().into());
|
||||
item.meta = page.meta.clone();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,7 +144,7 @@ impl Navigation {
|
||||
title: Some(page.title.clone()),
|
||||
url: Some(page.url.clone()),
|
||||
canonical_url: page.canonical_url.clone(),
|
||||
meta: Some(page.meta.clone().into()),
|
||||
meta: page.meta.clone(),
|
||||
children: Vec::new(),
|
||||
is_index: true,
|
||||
active: false,
|
||||
@@ -334,7 +334,7 @@ impl From<Chunk<Id, Page>> for Navigation {
|
||||
title: Some(title),
|
||||
url: None,
|
||||
canonical_url: None,
|
||||
meta: None,
|
||||
meta: BTreeMap::default(),
|
||||
children: Vec::new(),
|
||||
is_index: false,
|
||||
active: false,
|
||||
@@ -351,7 +351,7 @@ impl From<Chunk<Id, Page>> for Navigation {
|
||||
title: Some(page.data.title),
|
||||
url: Some(page.data.url),
|
||||
canonical_url: page.data.canonical_url,
|
||||
meta: Some(page.data.meta.into()),
|
||||
meta: page.data.meta.clone(),
|
||||
children: Vec::new(),
|
||||
is_index: is_index(&file),
|
||||
active: false,
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
use pyo3::FromPyObject;
|
||||
use serde::Serialize;
|
||||
|
||||
use super::meta::NavigationMeta;
|
||||
use crate::structure::page::PageMeta;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Structs
|
||||
@@ -45,7 +45,7 @@ pub struct NavigationItem {
|
||||
/// Item canonical URL.
|
||||
pub canonical_url: Option<String>,
|
||||
/// Item metadata.
|
||||
pub meta: Option<NavigationMeta>,
|
||||
pub meta: PageMeta,
|
||||
/// Item children.
|
||||
pub children: Vec<NavigationItem>,
|
||||
/// Whether this item is an index page.
|
||||
|
||||
@@ -1,61 +0,0 @@
|
||||
// Copyright (c) 2025-2026 Zensical and contributors
|
||||
|
||||
// SPDX-License-Identifier: MIT
|
||||
// All contributions are certified under the DCO
|
||||
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
//! Navigation item.
|
||||
|
||||
use pyo3::FromPyObject;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::structure::page::PageMeta;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Structs
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
/// Navigation item metadata.
|
||||
#[derive(Clone, Debug, PartialEq, Hash, Eq, FromPyObject, Serialize)]
|
||||
#[pyo3(from_item_all)]
|
||||
pub struct NavigationMeta {
|
||||
/// Page icon.
|
||||
pub icon: Option<String>,
|
||||
/// Page status.
|
||||
pub status: Option<String>,
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Trait implementations
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
impl From<PageMeta> for NavigationMeta {
|
||||
/// Extract navigation metadata from a page.
|
||||
fn from(meta: PageMeta) -> Self {
|
||||
let icon = meta.get("icon").cloned();
|
||||
let status = meta.get("status").cloned();
|
||||
NavigationMeta {
|
||||
icon: icon.map(|meta| meta.to_string()),
|
||||
status: status.map(|meta| meta.to_string()),
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user