Skip to content

Commit

Permalink
fix(templ): fix summary and inheritancediagram
Browse files Browse the repository at this point in the history
  • Loading branch information
fiji-flo committed Oct 31, 2024
1 parent f8228a9 commit c0890a4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 19 deletions.
34 changes: 21 additions & 13 deletions crates/rari-doc/src/helpers/summary_hack.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use itertools::Itertools;
use rari_md::{m2h_internal, M2HOptions};

use crate::error::DocError;
Expand All @@ -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<String, DocError> {
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 `<p>` tag in good faith.
Expand Down
15 changes: 9 additions & 6 deletions crates/rari-doc/src/templ/templs/inheritance_diagram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ use crate::helpers::api_inheritance::inheritance;

#[rari_f]
pub fn inheritance_diagram(interface: Option<String>) -> Result<String, DocError> {
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() {
Expand Down

0 comments on commit c0890a4

Please sign in to comment.