-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(templs): glossarydisambiguation
Inlcudes: - link fixes - hacky summary support - test fixes - json fixes - other fixes
- Loading branch information
Showing
16 changed files
with
166 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use crate::docs::doc::render_md_to_html; | ||
use crate::docs::page::{Page, PageLike}; | ||
use crate::error::DocError; | ||
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() | ||
.lines() | ||
.find(|line| { | ||
!(line.trim().is_empty() | ||
|| line.starts_with("{{") && line.ends_with("}}") | ||
|| line.starts_with("##")) | ||
}) | ||
.map(|line| { | ||
render_for_summary(line).and_then(|md| render_md_to_html(md.trim(), page.locale())) | ||
}) | ||
.unwrap_or_else(|| Ok(String::from("No summray found."))) | ||
} | ||
|
||
/// Trims a `<p>` tag in good faith. | ||
/// This does not check if theres a `<p>` as root and will | ||
/// result in invalid html for input like: | ||
/// ``` | ||
/// <p>foo</p>bar | ||
/// ``` | ||
pub fn strip_paragraph_unckecked(input: &str) -> &str { | ||
let out = input.trim().strip_prefix("<p>").unwrap_or(input); | ||
let out = out.trim().strip_suffix("</p>").unwrap_or(out); | ||
|
||
out | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
crates/rari-doc/src/templ/templs/glossarydisambiguation.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use rari_templ_func::rari_f; | ||
|
||
use crate::docs::page::PageLike; | ||
use crate::error::DocError; | ||
use crate::helpers::subpages::get_sub_pages; | ||
use crate::helpers::summary_hack::{get_hacky_summary_md, strip_paragraph_unckecked}; | ||
|
||
#[rari_f] | ||
pub fn glossarydisambiguation() -> Result<String, DocError> { | ||
let mut out = String::new(); | ||
let pages = get_sub_pages( | ||
env.url, | ||
Some(1), | ||
crate::helpers::subpages::SubPagesSorter::Title, | ||
)?; | ||
out.push_str("<dl>"); | ||
|
||
for page in pages { | ||
out.extend([ | ||
r#"<dt><a href=""#, | ||
page.url(), | ||
r#"">"#, | ||
page.title(), | ||
r#"</a></dt><dd>"#, | ||
strip_paragraph_unckecked(get_hacky_summary_md(&page)?.as_str()), | ||
r#"</dd>"#, | ||
]); | ||
} | ||
out.push_str("</dl>"); | ||
|
||
Ok(out) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.