diff --git a/crates/rari-doc/src/helpers/summary_hack.rs b/crates/rari-doc/src/helpers/summary_hack.rs index 05eae64..11cce37 100644 --- a/crates/rari-doc/src/helpers/summary_hack.rs +++ b/crates/rari-doc/src/helpers/summary_hack.rs @@ -1,3 +1,4 @@ +use itertools::Itertools; use rari_md::{m2h_internal, M2HOptions}; use crate::error::DocError; @@ -7,23 +8,30 @@ use crate::templ::render::render_for_summary; /// There's a few places were we still tansplant content. /// Yari had a hidden hacky way to do this and we have to mimic this for now. pub fn get_hacky_summary_md(page: &Page) -> Result { - page.content() + let summary_md = page + .content() .lines() - .find(|line| { - !(line.trim().is_empty() + .skip_while(|line| { + line.trim().is_empty() || line.starts_with("{{") && line.ends_with("}}") - || line.starts_with("##")) + || line.starts_with("##") + }) + .take_while(|line| { + !(line.trim().is_empty() + || (line.starts_with("{{") && line.ends_with("}}") || line.starts_with("##"))) }) - .map(|line| { - render_for_summary(line).and_then(|md| { - Ok(m2h_internal( - md.trim(), - page.locale(), - M2HOptions { sourcepos: false }, - )?) - }) + .join("\n"); + if summary_md.is_empty() { + Ok(String::from("No summray found.")) + } else { + render_for_summary(&summary_md).and_then(|md| { + Ok(m2h_internal( + md.trim(), + page.locale(), + M2HOptions { sourcepos: false }, + )?) }) - .unwrap_or_else(|| Ok(String::from("No summray found."))) + } } /// Trims a `

` tag in good faith. diff --git a/crates/rari-doc/src/templ/templs/inheritance_diagram.rs b/crates/rari-doc/src/templ/templs/inheritance_diagram.rs index be659c7..c6aeebb 100644 --- a/crates/rari-doc/src/templ/templs/inheritance_diagram.rs +++ b/crates/rari-doc/src/templ/templs/inheritance_diagram.rs @@ -9,12 +9,15 @@ use crate::helpers::api_inheritance::inheritance; #[rari_f] pub fn inheritance_diagram(interface: Option) -> Result { - let main_if = interface.as_deref().unwrap_or( - env.slug - .strip_prefix("Web/API/") - .map(|s| &s[..s.find('/').unwrap_or(s.len())]) - .ok_or_else(|| DocError::InvalidSlugForX(env.slug.to_string()))?, - ); + println!("{interface:?}"); + let main_if = interface + .as_deref() + .or_else(|| { + env.slug + .strip_prefix("Web/API/") + .map(|s| &s[..s.find('/').unwrap_or(s.len())]) + }) + .ok_or_else(|| DocError::InvalidSlugForX(env.slug.to_string()))?; let inheritance_chain = inheritance(main_if); if inheritance_chain.is_empty() {