From c93dcdede1ec06fa191c5c301083b3131ff3dee2 Mon Sep 17 00:00:00 2001 From: Claas Augner Date: Fri, 3 Jan 2025 12:13:59 +0100 Subject: [PATCH] feat(sidebars): add recursive listSubPages[Grouped] option --- crates/rari-doc/src/helpers/subpages.rs | 3 ++- crates/rari-doc/src/html/sidebar.rs | 13 ++++++++++++- crates/rari-tools/src/sidebars.rs | 4 ++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/crates/rari-doc/src/helpers/subpages.rs b/crates/rari-doc/src/helpers/subpages.rs index 37ad3ec1..89641104 100644 --- a/crates/rari-doc/src/helpers/subpages.rs +++ b/crates/rari-doc/src/helpers/subpages.rs @@ -189,6 +189,7 @@ pub fn list_sub_pages_grouped_internal( out: &mut String, url: &str, locale: Locale, + depth: Option, ListSubPagesContext { sorter, page_types, @@ -196,7 +197,7 @@ pub fn list_sub_pages_grouped_internal( include_parent, }: ListSubPagesContext<'_>, ) -> Result<(), DocError> { - let sub_pages = get_sub_pages(url, None, sorter.unwrap_or_default())?; + let sub_pages = get_sub_pages(url, depth, sorter.unwrap_or_default())?; let mut grouped = BTreeMap::new(); for sub_page in sub_pages.iter() { diff --git a/crates/rari-doc/src/html/sidebar.rs b/crates/rari-doc/src/html/sidebar.rs index 9f3d3620..cda410e3 100644 --- a/crates/rari-doc/src/html/sidebar.rs +++ b/crates/rari-doc/src/html/sidebar.rs @@ -297,6 +297,8 @@ pub struct SubPageEntry { pub code: bool, #[serde(default, skip_serializing_if = "is_default")] pub include_parent: bool, + #[serde(default, skip_serializing_if = "is_default")] + pub recursive: bool, } #[derive(Serialize, Deserialize, Default, Debug, PartialEq, Clone)] @@ -328,12 +330,14 @@ pub enum MetaChildren { tags: Vec, code: bool, include_parent: bool, + recursive: bool, }, ListSubPagesGrouped { path: String, tags: Vec, code: bool, include_parent: bool, + recursive: bool, }, WebExtApi, #[default] @@ -440,6 +444,7 @@ impl TryFrom for SidebarMetaEntry { path, code, include_parent, + recursive, }) => SidebarMetaEntry { section: false, details, @@ -450,6 +455,7 @@ impl TryFrom for SidebarMetaEntry { tags, code, include_parent, + recursive, }, }, SidebarEntry::ListSubPagesGrouped(SubPageEntry { @@ -461,6 +467,7 @@ impl TryFrom for SidebarMetaEntry { path, code, include_parent, + recursive, }) => SidebarMetaEntry { section: false, details, @@ -471,6 +478,7 @@ impl TryFrom for SidebarMetaEntry { tags, code, include_parent, + recursive, }, }, SidebarEntry::Default(BasicEntry { @@ -596,6 +604,7 @@ impl SidebarMetaEntry { tags, code, include_parent, + recursive, } => { let url = if path.starts_with(concat!("/", default_locale().as_url_str(), "/")) { Cow::Borrowed(path) @@ -611,7 +620,7 @@ impl SidebarMetaEntry { out, &url, locale, - Some(1), + Some(if *recursive { usize::MAX - 1 } else { 1 }), ListSubPagesContext { sorter: None, page_types: tags, @@ -625,6 +634,7 @@ impl SidebarMetaEntry { tags, code, include_parent, + recursive, } => { let url = if path.starts_with(concat!("/", default_locale().as_url_str(), "/")) { Cow::Borrowed(path) @@ -640,6 +650,7 @@ impl SidebarMetaEntry { out, &url, locale, + Some(if *recursive { usize::MAX - 1 } else { 1 }), ListSubPagesContext { sorter: None, page_types: tags, diff --git a/crates/rari-tools/src/sidebars.rs b/crates/rari-tools/src/sidebars.rs index 20697953..a9aac17d 100644 --- a/crates/rari-tools/src/sidebars.rs +++ b/crates/rari-tools/src/sidebars.rs @@ -263,6 +263,7 @@ fn process_entry(entry: SidebarEntry, pairs: Pairs<'_>) -> SidebarEntry { path, include_parent, code, + recursive, }) => { let new_path: Option = replace_pairs(Some(path), pairs); if new_path.is_none() { @@ -277,6 +278,7 @@ fn process_entry(entry: SidebarEntry, pairs: Pairs<'_>) -> SidebarEntry { path: new_path.unwrap(), include_parent, code, + recursive, }) } SidebarEntry::ListSubPagesGrouped(SubPageEntry { @@ -288,6 +290,7 @@ fn process_entry(entry: SidebarEntry, pairs: Pairs<'_>) -> SidebarEntry { path, include_parent, code, + recursive, }) => { let new_path: Option = replace_pairs(Some(path), pairs); if new_path.is_none() { @@ -302,6 +305,7 @@ fn process_entry(entry: SidebarEntry, pairs: Pairs<'_>) -> SidebarEntry { path: new_path.unwrap(), include_parent, code, + recursive, }) } SidebarEntry::Default(BasicEntry {