Skip to content

Commit

Permalink
feat(sidebars): add recursive listSubPages[Grouped] option
Browse files Browse the repository at this point in the history
  • Loading branch information
caugner committed Jan 3, 2025
1 parent eff3195 commit c93dcde
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
3 changes: 2 additions & 1 deletion crates/rari-doc/src/helpers/subpages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,15 @@ pub fn list_sub_pages_grouped_internal(
out: &mut String,
url: &str,
locale: Locale,
depth: Option<usize>,
ListSubPagesContext {
sorter,
page_types,
code,
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() {
Expand Down
13 changes: 12 additions & 1 deletion crates/rari-doc/src/html/sidebar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -328,12 +330,14 @@ pub enum MetaChildren {
tags: Vec<PageType>,
code: bool,
include_parent: bool,
recursive: bool,
},
ListSubPagesGrouped {
path: String,
tags: Vec<PageType>,
code: bool,
include_parent: bool,
recursive: bool,
},
WebExtApi,
#[default]
Expand Down Expand Up @@ -440,6 +444,7 @@ impl TryFrom<SidebarEntry> for SidebarMetaEntry {
path,
code,
include_parent,
recursive,
}) => SidebarMetaEntry {
section: false,
details,
Expand All @@ -450,6 +455,7 @@ impl TryFrom<SidebarEntry> for SidebarMetaEntry {
tags,
code,
include_parent,
recursive,
},
},
SidebarEntry::ListSubPagesGrouped(SubPageEntry {
Expand All @@ -461,6 +467,7 @@ impl TryFrom<SidebarEntry> for SidebarMetaEntry {
path,
code,
include_parent,
recursive,
}) => SidebarMetaEntry {
section: false,
details,
Expand All @@ -471,6 +478,7 @@ impl TryFrom<SidebarEntry> for SidebarMetaEntry {
tags,
code,
include_parent,
recursive,
},
},
SidebarEntry::Default(BasicEntry {
Expand Down Expand Up @@ -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)
Expand All @@ -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,
Expand All @@ -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)
Expand All @@ -640,6 +650,7 @@ impl SidebarMetaEntry {
out,
&url,
locale,
Some(if *recursive { usize::MAX - 1 } else { 1 }),
ListSubPagesContext {
sorter: None,
page_types: tags,
Expand Down
4 changes: 4 additions & 0 deletions crates/rari-tools/src/sidebars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ fn process_entry(entry: SidebarEntry, pairs: Pairs<'_>) -> SidebarEntry {
path,
include_parent,
code,
recursive,
}) => {
let new_path: Option<String> = replace_pairs(Some(path), pairs);
if new_path.is_none() {
Expand All @@ -277,6 +278,7 @@ fn process_entry(entry: SidebarEntry, pairs: Pairs<'_>) -> SidebarEntry {
path: new_path.unwrap(),
include_parent,
code,
recursive,
})
}
SidebarEntry::ListSubPagesGrouped(SubPageEntry {
Expand All @@ -288,6 +290,7 @@ fn process_entry(entry: SidebarEntry, pairs: Pairs<'_>) -> SidebarEntry {
path,
include_parent,
code,
recursive,
}) => {
let new_path: Option<String> = replace_pairs(Some(path), pairs);
if new_path.is_none() {
Expand All @@ -302,6 +305,7 @@ fn process_entry(entry: SidebarEntry, pairs: Pairs<'_>) -> SidebarEntry {
path: new_path.unwrap(),
include_parent,
code,
recursive,
})
}
SidebarEntry::Default(BasicEntry {
Expand Down

0 comments on commit c93dcde

Please sign in to comment.