Skip to content

Commit

Permalink
feat(generics): prepare support for community page
Browse files Browse the repository at this point in the history
  • Loading branch information
fiji-flo committed Sep 25, 2024
1 parent 1874d87 commit 05d39f2
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions crates/rari-doc/src/pages/types/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ impl PageReader for GenericPage {
let path = path.into();
let root = generic_pages_root().ok_or(DocError::NoGenericPagesRoot)?;
let without_root: &Path = path.strip_prefix(root)?;
let (slug, title_suffix, root) = if without_root.starts_with("plus/") {
("plus/docs", "MDN Plus", root.join("plus"))
let (slug_prefix, title_suffix, root) = if without_root.starts_with("plus/") {
(Some("plus/docs"), "MDN Plus", root.join("plus"))
} else if without_root.starts_with("observatory/") {
(
"observatory/docs",
Some("observatory/docs"),
"HTTP Observatory",
root.join("observatory"),
)
Expand All @@ -84,8 +84,14 @@ impl PageReader for GenericPage {
crate::pages::page::PageCategory::GenericPage,
));
};
read_generic_page(path, locale.unwrap_or_default(), slug, title_suffix, &root)
.map(|g| Page::GenericPage(Arc::new(g)))
read_generic_page(
path,
locale.unwrap_or_default(),
slug_prefix,
title_suffix,
&root,
)
.map(|g| Page::GenericPage(Arc::new(g)))
}
}
#[derive(Debug, Clone)]
Expand Down Expand Up @@ -193,7 +199,7 @@ impl PageLike for GenericPage {
fn read_generic_page(
path: impl Into<PathBuf>,
locale: Locale,
slug: &str,
slug_prefix: Option<&str>,
title_suffix: &str,
root: &Path,
) -> Result<GenericPage, DocError> {
Expand All @@ -205,7 +211,11 @@ fn read_generic_page(
let path = full_path.strip_prefix(root)?.to_path_buf();
let page = path.with_extension("");
let page = page.to_string_lossy();
let slug = concat_strs!(slug, "/", page.as_ref());
let slug = if let Some(slug) = slug_prefix {
concat_strs!(slug, "/", page.as_ref())
} else {
page.to_string()
};

Ok(GenericPage {
meta: GenericPageMeta::from_fm(
Expand Down

0 comments on commit 05d39f2

Please sign in to comment.