Skip to content

Commit b2d36b5

Browse files
LeoMcAfiji-flo
andauthored
chore(generic-content): rename generic pages to match repo name (#43)
Co-authored-by: Florian Dieminger <[email protected]>
1 parent 72a96ef commit b2d36b5

File tree

6 files changed

+24
-23
lines changed

6 files changed

+24
-23
lines changed

Diff for: crates/rari-doc/src/build.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ use sha2::{Digest, Sha256};
1717
use tracing::{span, Level};
1818

1919
use crate::cached_readers::{
20-
blog_files, contributor_spotlight_files, curriculum_files, generic_pages_files, wiki_histories,
20+
blog_files, contributor_spotlight_files, curriculum_files, generic_content_files,
21+
wiki_histories,
2122
};
2223
use crate::contributors::contributors_txt;
2324
use crate::error::DocError;
@@ -234,7 +235,7 @@ pub fn build_blog_pages<'a>() -> Result<Vec<SitemapMeta<'a>>, DocError> {
234235
/// This function will return an error if:
235236
/// - An error occurs while building any of the generic pages.
236237
pub fn build_generic_pages<'a>() -> Result<Vec<SitemapMeta<'a>>, DocError> {
237-
generic_pages_files()
238+
generic_content_files()
238239
.values()
239240
.map(|page| {
240241
build_single_page(page).map(|_| SitemapMeta {

Diff for: crates/rari-doc/src/cached_readers.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
//!
1919
//! - **Specialized Caches**: These caches store specific types of documentation content.
2020
//! - `CACHED_CURRICULUM`: Stores curriculum files, indexed by URL, path, and index,
21-
//! - `GENERIC_PAGES_FILES`: Stores generic pages indexed by URL.
21+
//! - `GENERIC_CONTENT_FILES`: Stores generic pages indexed by URL.
2222
//! - `CONTRIBUTOR_SPOTLIGHT_FILES`: Stores contributor spotlight pages indexed by URL.
2323
2424
use std::borrow::Cow;
@@ -30,7 +30,7 @@ use std::sync::{Arc, LazyLock, OnceLock};
3030
use dashmap::DashMap;
3131
use rari_types::globals::{
3232
blog_root, cache_content, content_root, content_translated_root, contributor_spotlight_root,
33-
curriculum_root, generic_pages_root,
33+
curriculum_root, generic_content_root,
3434
};
3535
use rari_types::locale::Locale;
3636
use rari_utils::concat_strs;
@@ -63,7 +63,7 @@ type SidebarFilesCache = Arc<DashMap<(String, Locale), Arc<MetaSidebar>>>;
6363
pub(crate) static CACHED_SIDEBAR_FILES: LazyLock<SidebarFilesCache> =
6464
LazyLock::new(|| Arc::new(DashMap::new()));
6565
pub(crate) static CACHED_CURRICULUM: OnceLock<CurriculumFiles> = OnceLock::new();
66-
pub(crate) static GENERIC_PAGES_FILES: OnceLock<UrlToPageMap> = OnceLock::new();
66+
pub(crate) static GENERIC_CONTENT_FILES: OnceLock<UrlToPageMap> = OnceLock::new();
6767
pub(crate) static CONTRIBUTOR_SPOTLIGHT_FILES: OnceLock<UrlToPageMap> = OnceLock::new();
6868
pub(crate) static WIKI_HISTORY: OnceLock<WikiHistories> = OnceLock::new();
6969

@@ -241,8 +241,8 @@ fn gather_blog_posts() -> Result<HashMap<String, Page>, DocError> {
241241
}
242242
}
243243

244-
fn gather_generic_pages() -> Result<HashMap<String, Page>, DocError> {
245-
if let Some(root) = generic_pages_root() {
244+
fn gather_generic_content() -> Result<HashMap<String, Page>, DocError> {
245+
if let Some(root) = generic_content_root() {
246246
Ok(read_docs_parallel::<GenericPage>(&[root], Some("*.md"))?
247247
.into_iter()
248248
.filter_map(|page| {
@@ -261,7 +261,7 @@ fn gather_generic_pages() -> Result<HashMap<String, Page>, DocError> {
261261
.map(|page| (page.url().to_ascii_lowercase(), page))
262262
.collect())
263263
} else {
264-
Err(DocError::NoGenericPagesRoot)
264+
Err(DocError::NoGenericContentRoot)
265265
}
266266
}
267267

@@ -338,7 +338,7 @@ fn gather_contributre_spotlight() -> Result<HashMap<String, Page>, DocError> {
338338
.map(|page| (page.url().to_ascii_lowercase(), page))
339339
.collect())
340340
} else {
341-
Err(DocError::NoGenericPagesRoot)
341+
Err(DocError::NoGenericContentRoot)
342342
}
343343
}
344344

@@ -521,22 +521,22 @@ pub type UrlToPageMap = HashMap<String, Page>;
521521
///
522522
/// This function returns a `Cow<'static, UrlToPageMap>` containing the generic pages.
523523
/// If caching is enabled (as determined by `cache_content()`), it attempts to get the cached
524-
/// generic pages from `GENERIC_PAGES_FILES`, initializing it if needed.
524+
/// generic pages from `GENERIC_CONTENT_FILES`, initializing it if needed.
525525
/// If caching is not enabled, it directly reads the generic pages and returns them.
526526
///
527527
/// # Returns
528528
///
529529
/// * `Cow<'static, UrlToPageMap>` - Returns a `Cow::Borrowed` containing the cached generic pages
530530
/// if caching is enabled. Otherwise, returns a `Cow::Owned` containing the read-in generic pages.
531-
pub fn generic_pages_files() -> Cow<'static, UrlToPageMap> {
531+
pub fn generic_content_files() -> Cow<'static, UrlToPageMap> {
532532
fn gather() -> UrlToPageMap {
533-
gather_generic_pages().unwrap_or_else(|e| {
533+
gather_generic_content().unwrap_or_else(|e| {
534534
error!("{e}");
535535
Default::default()
536536
})
537537
}
538538
if cache_content() {
539-
Cow::Borrowed(GENERIC_PAGES_FILES.get_or_init(gather))
539+
Cow::Borrowed(GENERIC_CONTENT_FILES.get_or_init(gather))
540540
} else {
541541
Cow::Owned(gather())
542542
}

Diff for: crates/rari-doc/src/error.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ pub enum DocError {
2626
NoSuchPrefix(#[from] StripPrefixError),
2727
#[error("No curricm root set")]
2828
NoCurriculumRoot,
29-
#[error("No generic pages roots set")]
30-
NoGenericPagesRoot,
29+
#[error("No generic content root set")]
30+
NoGenericContentRoot,
3131
#[error("No H1 found")]
3232
NoH1,
3333
#[error(transparent)]

Diff for: crates/rari-doc/src/pages/types/generic.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ use std::path::{Path, PathBuf};
22
use std::sync::Arc;
33

44
use rari_types::fm_types::{FeatureStatus, PageType};
5-
use rari_types::globals::generic_pages_root;
5+
use rari_types::globals::generic_content_root;
66
use rari_types::locale::Locale;
77
use rari_types::RariEnv;
88
use rari_utils::concat_strs;
99
use rari_utils::io::read_to_string;
1010
use serde::Deserialize;
1111

12-
use crate::cached_readers::generic_pages_files;
12+
use crate::cached_readers::generic_content_files;
1313
use crate::error::DocError;
1414
use crate::pages::page::{Page, PageLike, PageReader};
1515
use crate::utils::split_fm;
@@ -68,7 +68,7 @@ impl PageReader for GenericPage {
6868
locale: Option<Locale>,
6969
) -> Result<crate::pages::page::Page, DocError> {
7070
let path = path.into();
71-
let root = generic_pages_root().ok_or(DocError::NoGenericPagesRoot)?;
71+
let root = generic_content_root().ok_or(DocError::NoGenericContentRoot)?;
7272
let without_root: &Path = path.strip_prefix(root)?;
7373
let (slug_prefix, title_suffix, root) = if without_root.starts_with("plus/") {
7474
(Some("plus/docs"), "MDN Plus", root.join("plus"))
@@ -106,7 +106,7 @@ pub struct GenericPage {
106106
impl GenericPage {
107107
pub fn from_slug(slug: &str, locale: Locale) -> Option<Page> {
108108
let url = concat_strs!("/", locale.as_url_str(), "/", slug).to_ascii_lowercase();
109-
generic_pages_files().get(&url).cloned()
109+
generic_content_files().get(&url).cloned()
110110
}
111111

112112
pub fn as_locale(&self, locale: Locale) -> Self {
@@ -126,7 +126,7 @@ impl GenericPage {
126126

127127
pub fn is_generic(slug: &str, locale: Locale) -> bool {
128128
let url = concat_strs!("/", locale.as_url_str(), "/", slug).to_ascii_lowercase();
129-
generic_pages_files().contains_key(&url)
129+
generic_content_files().contains_key(&url)
130130
}
131131
}
132132

Diff for: crates/rari-types/src/globals.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ pub fn blog_root() -> Option<&'static Path> {
2121
}
2222

2323
#[inline(always)]
24-
pub fn generic_pages_root() -> Option<&'static Path> {
25-
settings().generic_pages_root.as_deref()
24+
pub fn generic_content_root() -> Option<&'static Path> {
25+
settings().generic_content_root.as_deref()
2626
}
2727
#[inline(always)]
2828
pub fn curriculum_root() -> Option<&'static Path> {

Diff for: crates/rari-types/src/settings.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub struct Settings {
1212
pub content_translated_root: Option<PathBuf>,
1313
pub build_out_root: Option<PathBuf>,
1414
pub blog_root: Option<PathBuf>,
15-
pub generic_pages_root: Option<PathBuf>,
15+
pub generic_content_root: Option<PathBuf>,
1616
pub curriculum_root: Option<PathBuf>,
1717
pub contributor_spotlight_root: Option<PathBuf>,
1818
pub deny_warnings: bool,

0 commit comments

Comments
 (0)