diff --git a/crates/rari-doc/src/build.rs b/crates/rari-doc/src/build.rs index f034a6e8..f283e794 100644 --- a/crates/rari-doc/src/build.rs +++ b/crates/rari-doc/src/build.rs @@ -12,7 +12,10 @@ use std::path::PathBuf; use chrono::NaiveDateTime; use itertools::Itertools; -use rari_types::globals::{base_url, build_out_root, git_history}; +use rari_types::globals::{ + base_url, blog_root, build_out_root, contributor_spotlight_root, curriculum_root, + generic_content_root, git_history, +}; use rari_types::locale::{default_locale, Locale}; use rayon::iter::{IntoParallelIterator, ParallelIterator}; use sha2::{Digest, Sha256}; @@ -187,6 +190,9 @@ pub fn build_top_level_meta(locale_meta: Vec) -> Result<(), Doc /// This function will return an error if: /// - An error occurs while building any of the curriculum pages. pub fn build_curriculum_pages<'a>() -> Result>, DocError> { + if curriculum_root().is_none() { + return Err(DocError::NoCurriculumRoot); + } curriculum_files() .by_path .values() @@ -241,6 +247,9 @@ fn copy_blog_author_avatars() -> Result<(), DocError> { /// - An error occurs while copying blog author avatars. /// - An error occurs while building any of the blog pages. pub fn build_blog_pages<'a>() -> Result>, DocError> { + if blog_root().is_none() { + return Err(DocError::NoBlogRoot); + } copy_blog_author_avatars()?; let rss_file = build_out_root()? @@ -292,6 +301,9 @@ pub fn build_blog_pages<'a>() -> Result>, DocError> { /// This function will return an error if: /// - An error occurs while building any of the generic pages. pub fn build_generic_pages<'a>() -> Result>, DocError> { + if generic_content_root().is_none() { + return Err(DocError::NoGenericContentRoot); + } generic_content_files() .values() .map(|page| { @@ -320,6 +332,9 @@ pub fn build_generic_pages<'a>() -> Result>, DocError> { /// This function will return an error if: /// - An error occurs while building any of the contributor spotlight pages. pub fn build_contributor_spotlight_pages<'a>() -> Result>, DocError> { + if contributor_spotlight_root().is_none() { + return Err(DocError::NoContributorSpotlightRoot); + } contributor_spotlight_files() .values() .map(|page| { diff --git a/crates/rari-doc/src/cached_readers.rs b/crates/rari-doc/src/cached_readers.rs index 29f3b827..076f74bf 100644 --- a/crates/rari-doc/src/cached_readers.rs +++ b/crates/rari-doc/src/cached_readers.rs @@ -36,7 +36,7 @@ use rari_types::locale::Locale; use rari_utils::concat_strs; use rari_utils::io::read_to_string; use serde::{Deserialize, Serialize}; -use tracing::error; +use tracing::{error, warn}; use crate::contributors::{WikiHistories, WikiHistory}; use crate::error::DocError; @@ -319,7 +319,7 @@ fn gather_curriculum() -> Result { } } -fn gather_contributre_spotlight() -> Result, DocError> { +fn gather_contributor_spotlight() -> Result, DocError> { if let Some(root) = contributor_spotlight_root() { Ok(read_docs_parallel::(&[root], None)? .into_iter() @@ -339,7 +339,7 @@ fn gather_contributre_spotlight() -> Result, DocError> { .map(|page| (page.url().to_ascii_lowercase(), page)) .collect()) } else { - Err(DocError::NoGenericContentRoot) + Err(DocError::NoContributorSpotlightRoot) } } @@ -357,14 +357,14 @@ pub fn curriculum_files() -> Cow<'static, CurriculumFiles> { if cache_content() { Cow::Borrowed(CACHED_CURRICULUM.get_or_init(|| { gather_curriculum() - .map_err(|e| error!("{e}")) + .inspect_err(|e| warn!("{e}")) .ok() .unwrap_or_default() })) } else { Cow::Owned( gather_curriculum() - .map_err(|e| error!("{e}")) + .inspect_err(|e| warn!("{e}")) .unwrap_or_default(), ) } @@ -409,11 +409,11 @@ fn gather_blog_authors() -> Result>, DocError> { pub fn blog_files() -> Cow<'static, BlogFiles> { fn gather() -> BlogFiles { let posts = gather_blog_posts().unwrap_or_else(|e| { - error!("{e}"); + warn!("{e}"); Default::default() }); let authors = gather_blog_authors().unwrap_or_else(|e| { - error!("{e}"); + warn!("{e}"); Default::default() }); let mut sorted_meta = posts @@ -578,7 +578,7 @@ fn read_generic_content_config() -> Result { pub fn generic_content_config() -> Cow<'static, GenericContentConfig> { fn gather() -> GenericContentConfig { read_generic_content_config().unwrap_or_else(|e| { - error!("{e}"); + warn!("{e}"); Default::default() }) } @@ -603,7 +603,7 @@ pub fn generic_content_config() -> Cow<'static, GenericContentConfig> { pub fn generic_content_files() -> Cow<'static, UrlToPageMap> { fn gather() -> UrlToPageMap { gather_generic_content().unwrap_or_else(|e| { - error!("{e}"); + warn!("{e}"); Default::default() }) } @@ -627,8 +627,8 @@ pub fn generic_content_files() -> Cow<'static, UrlToPageMap> { /// if caching is enabled. Otherwise, returns a `Cow::Owned` containing the read-in contributor spotlight pages. pub fn contributor_spotlight_files() -> Cow<'static, UrlToPageMap> { fn gather() -> UrlToPageMap { - gather_contributre_spotlight().unwrap_or_else(|e| { - error!("{e}"); + gather_contributor_spotlight().unwrap_or_else(|e| { + warn!("{e}"); Default::default() }) } diff --git a/crates/rari-doc/src/error.rs b/crates/rari-doc/src/error.rs index 57015546..e42c521a 100644 --- a/crates/rari-doc/src/error.rs +++ b/crates/rari-doc/src/error.rs @@ -30,6 +30,8 @@ pub enum DocError { NoCurriculumRoot, #[error("No generic content root set")] NoGenericContentRoot, + #[error("No contributor spotlights root set")] + NoContributorSpotlightRoot, #[error("No generic content config found")] NoGenericContentConfig, #[error("No H1 found")]