Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ pub struct Args {
#[arg(long)]
git_show_output_cache_path: Option<PathBuf>,

/// read Highfive answers from this directory
#[arg(long)]
highfive_answers_path: Option<PathBuf>,

/// compute word clouds with this dictionary file
#[arg(long, default_value = "/usr/share/dict/words")]
dictionary_path: PathBuf,
Expand Down
29 changes: 20 additions & 9 deletions src/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -192,6 +202,7 @@ struct Response {
commit: Commit,
rendered_body: String,
git_show: String,
rendered_highfive_answers: Option<String>,
}

#[derive(Deserialize)]
Expand Down
16 changes: 15 additions & 1 deletion static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -213,7 +224,10 @@ <h1 id="title"></h1>
<div id="meta"></div>
<div id="label"></div>
<ul id="hints"></ul>
<hr>
<div id="answersBox">
<div id="answers"></div>
</div>
<hr id="noAnswers">
<div id="content"></div>
</main>
<pre id="gitShow"></pre>
Expand Down
3 changes: 3 additions & 0 deletions static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down