diff options
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/Cargo.toml | 1 | ||||
| -rw-r--r-- | docs/src/contribs.rs | 25 | ||||
| -rw-r--r-- | docs/src/html.rs | 2 | ||||
| -rw-r--r-- | docs/src/lib.rs | 10 |
4 files changed, 17 insertions, 21 deletions
diff --git a/docs/Cargo.toml b/docs/Cargo.toml index 123e641f..326e85a9 100644 --- a/docs/Cargo.toml +++ b/docs/Cargo.toml @@ -22,5 +22,4 @@ serde = { version = "1", features = ["derive"] } serde_yaml = "0.8" unicode_names2 = "0.6.0" unscanny = "0.1" -ureq = { version = "2.6", features = ["json"] } yaml-front-matter = "0.1" diff --git a/docs/src/contribs.rs b/docs/src/contribs.rs index 7e43249a..901b5f69 100644 --- a/docs/src/contribs.rs +++ b/docs/src/contribs.rs @@ -4,23 +4,15 @@ use std::fmt::Write; use serde::Deserialize; -use super::Html; +use super::{Html, Resolver}; /// Build HTML detailing the contributors between two tags. -pub fn contributors(from: &str, to: &str) -> Option<Html> { +pub fn contributors(resolver: &dyn Resolver, from: &str, to: &str) -> Option<Html> { let staff = ["laurmaedje", "reknih"]; - let url = format!("https://api.github.com/repos/typst/typst/compare/{from}...{to}"); - let response: Response = ureq::get(&url) - .set("X-GitHub-Api-Version", "2022-11-28") - .call() - .ok()? - .into_json() - .ok()?; - // Determine number of contributions per person. let mut contributors = HashMap::<String, Contributor>::new(); - for commit in response.commits { + for commit in resolver.commits(from, to) { contributors .entry(commit.author.login.clone()) .or_insert_with(|| Contributor { @@ -80,18 +72,15 @@ struct Contributor { contributions: usize, } +/// A commit on the `typst` repository. #[derive(Debug, Deserialize)] -struct Response { - commits: Vec<Commit>, -} - -#[derive(Debug, Deserialize)] -struct Commit { +pub struct Commit { author: Author, } +/// A commit author. #[derive(Debug, Deserialize)] -struct Author { +pub struct Author { login: String, avatar_url: String, } diff --git a/docs/src/html.rs b/docs/src/html.rs index d3566b07..cd47d75b 100644 --- a/docs/src/html.rs +++ b/docs/src/html.rs @@ -121,7 +121,7 @@ impl<'a> Handler<'a> { md::Event::Html(html) if html.starts_with("<contributors") => { let from = html_attr(html, "from").unwrap(); let to = html_attr(html, "to").unwrap(); - let Some(output) = contributors(from, to) else { return false }; + let Some(output) = contributors(self.resolver, from, to) else { return false }; *html = output.raw.into(); } diff --git a/docs/src/lib.rs b/docs/src/lib.rs index 3fcfecd1..fcf3610c 100644 --- a/docs/src/lib.rs +++ b/docs/src/lib.rs @@ -3,7 +3,7 @@ mod contribs; mod html; -pub use contribs::contributors; +pub use contribs::{contributors, Author, Commit}; pub use html::Html; use std::fmt::{self, Debug, Formatter}; @@ -72,6 +72,9 @@ pub trait Resolver { /// Produce HTML for an example. fn example(&self, source: Html, frames: &[Frame]) -> Html; + + /// Determine the commits between two tags. + fn commits(&self, from: &str, to: &str) -> Vec<Commit>; } /// Details about a documentation page and its children. @@ -81,6 +84,7 @@ pub struct PageModel { pub title: String, pub description: String, pub part: Option<&'static str>, + pub outline: Vec<OutlineItem>, pub body: BodyModel, pub children: Vec<Self>, } @@ -784,5 +788,9 @@ mod tests { fn image(&self, _: &str, _: &[u8]) -> String { String::new() } + + fn commits(&self, _: &str, _: &str) -> Vec<Commit> { + vec![] + } } } |
