From 34b38843c3eb20f136a20f36182318cb8c133b3c Mon Sep 17 00:00:00 2001 From: delan azabani Date: Thu, 13 Aug 2026 17:25:06 +0800 Subject: [PATCH] Run with --highfive-answers-path to show Highfive answers --- src/commit.rs | 4 ++++ src/main.rs | 4 ++++ src/web.rs | 29 ++++++++++++++++++++--------- static/index.html | 16 +++++++++++++++- static/main.js | 3 +++ 5 files changed, 46 insertions(+), 10 deletions(-) diff --git a/src/commit.rs b/src/commit.rs index ae8641d..a014e84 100644 --- a/src/commit.rs +++ b/src/commit.rs @@ -28,6 +28,10 @@ pub struct Commit { } impl Commit { + pub fn number(&self) -> &str { + self.hash_number.strip_prefix("#").expect("guaranteed by format") + } + pub fn tags(&self) -> &str { if let Some((tags, _notes)) = self.label.split_once(";") { return tags; diff --git a/src/main.rs b/src/main.rs index 5f97740..22f2ba9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -64,6 +64,10 @@ pub struct Args { #[arg(long)] git_show_output_cache_path: Option, + /// read Highfive answers from this directory + #[arg(long)] + highfive_answers_path: Option, + /// compute word clouds with this dictionary file #[arg(long, default_value = "/usr/share/dict/words")] dictionary_path: PathBuf, diff --git a/src/web.rs b/src/web.rs index 1593d6b..15f010e 100644 --- a/src/web.rs +++ b/src/web.rs @@ -70,28 +70,38 @@ pub fn shutdown() { } pub fn update(commit: &Commit) { - let mut options = comrak::Options::default(); - options.extension.autolink = true; - options.extension.table = true; - options.render.gfm_quirks = true; - options.render.hardbreaks = true; - options.render.r#unsafe = true; - let unsafe_body = markdown_to_html(&commit.body.join("\n"), &options); - let body = ammonia::clean(&unsafe_body); let git_show = if let Some(path) = ARGS.git_show_output_cache_path.as_ref() { std::fs::read_to_string(path.join(&commit.hash)).unwrap_or_else(|_| "".to_owned()) } else { "[enable `git show` output with --git-show-cache-path]".to_owned() }; + let highfive_answers = if let Some(path) = ARGS.highfive_answers_path.as_ref() { + std::fs::read_to_string(path.join(commit.number())).ok() + } else { + Some("[enable Highfive answers with --highfive-answers-path]".to_owned()) + }; let content = Response { commit: commit.clone(), - rendered_body: body, + rendered_body: safe_render_markdown(&commit.body.join("\n")), git_show, + rendered_highfive_answers: highfive_answers.map(|answers| safe_render_markdown(&answers)), }; *CONTENT.write().unwrap() = serde_json::to_string(&content).unwrap(); UPDATE.0.send(()).unwrap(); } +fn safe_render_markdown(unsafe_markdown: &str) -> String { + let mut options = comrak::Options::default(); + options.extension.autolink = true; + options.extension.table = true; + options.render.gfm_quirks = true; + options.render.hardbreaks = true; + options.render.r#unsafe = true; + let unsafe_html = markdown_to_html(unsafe_markdown, &options); + let safe_html = ammonia::clean(&unsafe_html); + safe_html +} + #[get("/ws")] fn ws(ws: rocket_ws::WebSocket) -> rocket_ws::Channel<'static> { let mut update = UPDATE.1.resubscribe(); @@ -192,6 +202,7 @@ struct Response { commit: Commit, rendered_body: String, git_show: String, + rendered_highfive_answers: Option, } #[derive(Deserialize)] diff --git a/static/index.html b/static/index.html index a926c7d..20f3dff 100644 --- a/static/index.html +++ b/static/index.html @@ -103,6 +103,17 @@ #title.Accepted { color: green; } + #answersBox { + border: thin solid #1192e8; + padding: 0 1em; + } + #answers:empty:before { + content: "BUG: has “monthly update” label but no Highfive answers?"; + display: block; + margin: 1em 0; + font-style: italic; + opacity: 0.5; + } #gitShow { flex: 1 0 40rem; max-height: 100vh; @@ -213,7 +224,10 @@

    -
    +
    +
    +
    +
    
    diff --git a/static/main.js b/static/main.js
    index ec084bd..37d34f8 100644
    --- a/static/main.js
    +++ b/static/main.js
    @@ -54,6 +54,9 @@ ws.addEventListener("message", event => {
             li.append(hint);
             hints.append(li);
         }
    +    answersBox.hidden = commitExt.rendered_highfive_answers == null;
    +    noAnswers.hidden = commitExt.rendered_highfive_answers != null;
    +    answers.innerHTML = commitExt.rendered_highfive_answers;
         content.innerHTML = commitExt.rendered_body;
         input.value = commitExt.commit.label;