diff options
| author | Laurenz <laurmaedje@gmail.com> | 2023-05-17 14:31:55 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2023-05-17 14:31:55 +0200 |
| commit | 8971588486b6ffa9269344b4bda71de86af9d908 (patch) | |
| tree | 420a51975c654741c99d00b7869a58cf291f3a6a | |
| parent | d14d1e867f83de631e7252ec5bdb2aa2dd870c8e (diff) | |
Externalize contributor fetching
| -rw-r--r-- | Cargo.lock | 105 | ||||
| -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 |
5 files changed, 18 insertions, 125 deletions
@@ -124,12 +124,6 @@ checksum = "7b7e4c2464d97fe331d41de9d5db0def0a96f4d823b8b32a2efd503578988973" [[package]] name = "base64" -version = "0.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" - -[[package]] -name = "base64" version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a4a4ddaa51a5bc52a6948f74c06d20aaaddb71924eab79b8c97a8c556e942d6a" @@ -1647,21 +1641,6 @@ dependencies = [ ] [[package]] -name = "ring" -version = "0.16.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3053cf52e236a3ed746dfc745aa9cacf1b791d846bdaf412f60a8d7d6e17c8fc" -dependencies = [ - "cc", - "libc", - "once_cell", - "spin", - "untrusted", - "web-sys", - "winapi", -] - -[[package]] name = "roff" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1719,18 +1698,6 @@ dependencies = [ ] [[package]] -name = "rustls" -version = "0.20.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fff78fc74d175294f4e83b28343315ffcfb114b156f0185e9741cb5570f50e2f" -dependencies = [ - "log", - "ring", - "sct", - "webpki", -] - -[[package]] name = "rustversion" version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1780,16 +1747,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1792db035ce95be60c3f8853017b3999209281c24e2ba5bc8e59bf97a0c590c1" [[package]] -name = "sct" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d53dcdb7c9f8158937a7981b48accfd39a43af418591a5d008c7b22b5e1b7ca4" -dependencies = [ - "ring", - "untrusted", -] - -[[package]] name = "semver" version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1893,12 +1850,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" [[package]] -name = "spin" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" - -[[package]] name = "stable_deref_trait" version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2365,7 +2316,6 @@ dependencies = [ "typst-library", "unicode_names2", "unscanny", - "ureq", "yaml-front-matter", ] @@ -2540,30 +2490,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e9df2af067a7953e9c3831320f35c1cc0600c30d44d9f7a12b01db1cd88d6b47" [[package]] -name = "untrusted" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" - -[[package]] -name = "ureq" -version = "2.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "338b31dd1314f68f3aabf3ed57ab922df95ffcd902476ca7ba3c4ce7b908c46d" -dependencies = [ - "base64 0.13.1", - "flate2", - "log", - "once_cell", - "rustls", - "serde", - "serde_json", - "url", - "webpki", - "webpki-roots", -] - -[[package]] name = "url" version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2580,7 +2506,7 @@ version = "0.32.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4b44e14b7678bcc5947b397991432d0c4e02a103958a0ed5e1b9b961ddd08b21" dependencies = [ - "base64 0.21.0", + "base64", "log", "pico-args", "usvg-parser", @@ -2723,35 +2649,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0046fef7e28c3804e5e38bfa31ea2a0f73905319b677e57ebe37e49358989b5d" [[package]] -name = "web-sys" -version = "0.3.61" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e33b99f4b23ba3eec1a53ac264e35a755f00e966e0065077d6027c0f575b0b97" -dependencies = [ - "js-sys", - "wasm-bindgen", -] - -[[package]] -name = "webpki" -version = "0.22.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f095d78192e208183081cc07bc5515ef55216397af48b873e5edcd72637fa1bd" -dependencies = [ - "ring", - "untrusted", -] - -[[package]] -name = "webpki-roots" -version = "0.22.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6c71e40d7d2c34a5106301fb632274ca37242cd0c9d3e64dbece371a40a2d87" -dependencies = [ - "webpki", -] - -[[package]] name = "weezl" version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" 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![] + } } } |
