Render every page through templates
Browse filesThe repository header, branch menu, breadcrumbs, commit links, file and tags pages, diffs, code view, notices and the account page were built with format! and hand-placed escaping. They are now askama templates, which escape everything not explicitly marked safe, so the web code no longer interpolates data into HTML itself. layout.html and the page/layout helpers are gone; each page extends base.html. Rendered pages are unchanged apart from askama's numeric entities (& for &, " for a quote in text): 147 pages of the test fixture compared identical against the previous build. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Author
- Um9i vulgarmessiah@gmail.com
- Date
- 22 Nov 2026, 16:14
- Commit
- 48807f79c18d
- Parent
- ce526ea
20 files changed +397−278
| @@ -57,22 +57,15 @@ pub(crate) fn size(bytes: usize) -> String { | ||
| } | ||
| } | ||
| /// A page for someone signed in: the top bar links to their account. | ||
| pub(crate) fn page(title: &str, body: &str) -> String { | ||
| layout(title, body, true) | ||
| } | ||
| /// A page, with the account link in the top bar only when `signed_in`. | ||
| pub(crate) fn layout(title: &str, body: &str, signed_in: bool) -> String { | ||
| templates::Layout { title, body, signed_in }.to_string() | ||
| } | ||
| /// The page for anything that isn't there, or a malformed link. | ||
| pub(crate) fn view_missing(signed_in: bool) -> String { | ||
| layout( | ||
| "Not found", | ||
| r#"<section class="notfound"><h1 class="title">Nothing here</h1> | ||
| <p class="count">That repository, branch, file or commit doesn’t exist, or the link is malformed.</p> | ||
| <a class="button" href="/">Back to repositories</a></section>"#, | ||
| templates::Notice { | ||
| title: "Not found", | ||
| signed_in, | ||
| ) | ||
| heading: "Nothing here", | ||
| message: "That repository, branch, file or commit doesn’t exist, or the link is malformed.", | ||
| code: None, | ||
| link: Some(("/", "Back to repositories")), | ||
| } | ||
| .to_string() | ||
| } | ||
| @@ -22,14 +22,12 @@ use gitv::auth::{ | ||
| AuthError, Credentials, MIN_PASSWORD, auth_path, check_new_password, generate_password, random_bytes, | ||
| }; | ||
| use gitv::percent_decode; | ||
| use html_escape::{encode_double_quoted_attribute as attr, encode_text as esc}; | ||
| use serde::Deserialize; | ||
| use sha2::{Digest, Sha256}; | ||
| use subtle::ConstantTimeEq; | ||
| use super::SECURITY; | ||
| use super::throttle::{Client, Throttle}; | ||
| use crate::html::{layout, page}; | ||
| /// The session cookie. The `__Host-` prefix makes browsers insist on `Secure`, `Path=/` and no | ||
| /// `Domain`, so no other site or subdomain can set or overwrite it. | ||
| @@ -285,11 +283,12 @@ fn redirect(to: &str, cookie: Option<String>) -> Response { | ||
| fn not_set_up() -> Response { | ||
| html( | ||
| StatusCode::SERVICE_UNAVAILABLE, | ||
| layout( | ||
| notice( | ||
| "Sign-in isn't set up", | ||
| r#"<section class="notfound"><h1 class="title">Sign-in isn’t set up</h1> | ||
| <p class="count">Create the account on the server, then reload this page:</p><code>gitv-web setup</code></section>"#, | ||
| false, | ||
| "Sign-in isn’t set up", | ||
| "Create the account on the server, then reload this page:", | ||
| Some("gitv-web setup"), | ||
| ), | ||
| ) | ||
| } | ||
| @@ -324,7 +323,7 @@ fn challenge(error: Option<AuthError>, uri: &axum::http::Uri) -> Response { | ||
| eprintln!("gitv-web: {error}"); | ||
| return html( | ||
| StatusCode::SERVICE_UNAVAILABLE, | ||
| layout("Unavailable", "<p>Sign-in is unavailable.</p>", false), | ||
| notice("Unavailable", false, "Unavailable", "Sign-in is unavailable.", None), | ||
| ); | ||
| } | ||
| None => {} | ||
| @@ -439,7 +438,7 @@ pub async fn sign_out( | ||
| if !csrf_ok(&signed_in, &form.csrf) { | ||
| return html( | ||
| StatusCode::FORBIDDEN, | ||
| page("Not allowed", r#"<p class="note">That form has expired. Go back and try again.</p>"#), | ||
| notice("Not allowed", true, "Not allowed", "That form has expired. Go back and try again.", None), | ||
| ); | ||
| } | ||
| login.sessions.lock().unwrap_or_else(|e| e.into_inner()).remove(&signed_in.token_hash); | ||
| @@ -460,33 +459,22 @@ pub struct ChangePasswordForm { | ||
| } | ||
| fn account_page(status: StatusCode, user: &str, signed_in: &SignedIn, message: &str, ok: bool) -> Response { | ||
| let message = match message { | ||
| "" => String::new(), | ||
| m if ok => format!(r#"<p class="alert ok" role="status">{}</p>"#, esc(m)), | ||
| m => format!(r#"<p class="alert" role="alert">{}</p>"#, esc(m)), | ||
| let page = super::templates::Account { | ||
| title: "Account", | ||
| signed_in: true, | ||
| user, | ||
| message, | ||
| ok, | ||
| csrf: &signed_in.csrf, | ||
| min_password: MIN_PASSWORD, | ||
| }; | ||
| let csrf = attr(&signed_in.csrf); | ||
| html( | ||
| status, | ||
| page( | ||
| "Account", | ||
| &format!( | ||
| r#"<div class="pagehead"><h1 class="title">Account</h1><p class="count">Signed in as {user}</p></div>{message} | ||
| <section class="panel form-panel"><h2>Change password</h2> | ||
| <form class="form" method="post" action="/account"> | ||
| <input type="hidden" name="csrf" value="{csrf}"> | ||
| <label>Current password<input name="current" type="password" autocomplete="current-password" required></label> | ||
| <label>New password<span class="hint">At least {MIN_PASSWORD} characters.</span><input name="new" type="password" autocomplete="new-password" minlength="{MIN_PASSWORD}" required></label> | ||
| <label>Repeat new password<input name="repeat" type="password" autocomplete="new-password" minlength="{MIN_PASSWORD}" required></label> | ||
| <label>Authenticator code<input name="code" inputmode="numeric" autocomplete="one-time-code" pattern="[0-9]{{6}}" maxlength="6" required></label> | ||
| <button class="button primary" type="submit">Change password</button></form> | ||
| <p class="hint">Changing the password signs out every other session.</p></section> | ||
| <section class="panel form-panel"><h2>Sign out</h2> | ||
| <form method="post" action="/logout"><input type="hidden" name="csrf" value="{csrf}"><button class="button" type="submit">Sign out</button></form></section>"#, | ||
| user = esc(user) | ||
| ), | ||
| ), | ||
| ) | ||
| html(status, page.to_string()) | ||
| } | ||
| /// A page with a heading, a sentence and perhaps a command to copy. | ||
| fn notice(title: &str, signed_in: bool, heading: &str, message: &str, code: Option<&str>) -> String { | ||
| super::templates::Notice { title, signed_in, heading, message, code: code.map(str::to_string), link: None } | ||
| .to_string() | ||
| } | ||
| pub async fn account(State(login): State<Arc<Login>>, Extension(signed_in): Extension<SignedIn>) -> Response { | ||
| @@ -1,12 +1,162 @@ | ||
| //! Every page and repeated fragment, as askama templates, which escape everything they are | ||
| //! given unless it is marked `|safe`. Only HTML these templates or the Markdown and | ||
| //! highlighting renderers produced is ever passed as safe. | ||
| use askama::Template; | ||
| /// Wraps HTML already rendered and escaped by the existing page builders. | ||
| /// A page with a heading, a sentence, and optionally a command to copy and a button. | ||
| #[derive(Template)] | ||
| #[template(path = "layout.html")] | ||
| pub(super) struct Layout<'a> { | ||
| #[template(path = "notice.html")] | ||
| pub(crate) struct Notice<'a> { | ||
| pub title: &'a str, | ||
| pub signed_in: bool, | ||
| pub body: &'a str, | ||
| pub heading: &'a str, | ||
| pub message: &'a str, | ||
| pub code: Option<String>, | ||
| pub link: Option<(&'a str, &'a str)>, | ||
| } | ||
| /// A repository's name, clone address and tabs. | ||
| #[derive(Template)] | ||
| #[template(path = "masthead.html")] | ||
| pub(crate) struct Masthead<'a> { | ||
| pub owner: &'a str, | ||
| pub name: &'a str, | ||
| pub home: String, | ||
| pub protocol: &'a str, | ||
| pub address: String, | ||
| pub tabs: Vec<Tab>, | ||
| } | ||
| pub(crate) struct Tab { | ||
| pub href: String, | ||
| pub current: bool, | ||
| pub icon: String, | ||
| pub label: &'static str, | ||
| pub count: Option<usize>, | ||
| } | ||
| /// The branch and tag menu, then the path as breadcrumbs. | ||
| #[derive(Template)] | ||
| #[template(path = "locator.html")] | ||
| pub(crate) struct Locator<'a> { | ||
| pub branch_icon: String, | ||
| pub chevron_icon: String, | ||
| /// The reference as people see it. | ||
| pub current: std::borrow::Cow<'a, str>, | ||
| pub branches: Vec<MenuItem<'a>>, | ||
| pub tags: Vec<MenuItem<'a>>, | ||
| /// The repository root's link, when there is a path to show. | ||
| pub root: Option<String>, | ||
| pub repo_name: &'a str, | ||
| pub crumbs: Vec<Crumb<'a>>, | ||
| } | ||
| pub(crate) struct MenuItem<'a> { | ||
| pub href: String, | ||
| pub current: bool, | ||
| pub name: std::borrow::Cow<'a, str>, | ||
| } | ||
| /// One part of a path; the last has no link. | ||
| pub(crate) struct Crumb<'a> { | ||
| pub href: Option<String>, | ||
| pub name: std::borrow::Cow<'a, str>, | ||
| } | ||
| #[derive(Template)] | ||
| #[template(path = "sha-link.html")] | ||
| pub(crate) struct ShaLink<'a> { | ||
| pub href: String, | ||
| pub short: &'a str, | ||
| } | ||
| #[derive(Template)] | ||
| #[template(path = "empty.html")] | ||
| pub(crate) struct Empty<'a> { | ||
| pub title: String, | ||
| pub signed_in: bool, | ||
| pub masthead: String, | ||
| pub host: &'a str, | ||
| pub owner: &'a str, | ||
| pub name: &'a str, | ||
| } | ||
| /// Highlighted source with a line-number gutter. | ||
| #[derive(Template)] | ||
| #[template(path = "code.html")] | ||
| pub(crate) struct Code { | ||
| pub gutter: String, | ||
| pub code: String, | ||
| } | ||
| /// Preview and Code links for a Markdown file. | ||
| pub(crate) struct Views { | ||
| pub preview: String, | ||
| pub code: String, | ||
| pub as_code: bool, | ||
| } | ||
| #[derive(Template)] | ||
| #[template(path = "blob.html")] | ||
| pub(crate) struct Blob<'a> { | ||
| pub title: String, | ||
| pub signed_in: bool, | ||
| pub masthead: String, | ||
| pub locator: String, | ||
| pub file_icon: String, | ||
| pub name: &'a str, | ||
| pub facts: &'a str, | ||
| pub views: Option<Views>, | ||
| pub raw: String, | ||
| pub content: &'a str, | ||
| } | ||
| pub(crate) struct TagRow<'a> { | ||
| pub name: std::borrow::Cow<'a, str>, | ||
| pub note: Option<std::borrow::Cow<'a, str>>, | ||
| pub sha_link: String, | ||
| pub when: String, | ||
| pub browse: String, | ||
| } | ||
| #[derive(Template)] | ||
| #[template(path = "tags.html")] | ||
| pub(crate) struct Tags<'a> { | ||
| pub title: String, | ||
| pub signed_in: bool, | ||
| pub masthead: String, | ||
| pub rows: Vec<TagRow<'a>>, | ||
| } | ||
| /// One file of a commit's diff: its name and link, and its lines when they were read. | ||
| pub(crate) struct DiffFile<'a> { | ||
| pub href: String, | ||
| pub path: std::borrow::Cow<'a, str>, | ||
| pub status: &'static str, | ||
| pub diff: Option<&'a super::views::FileDiff>, | ||
| } | ||
| #[derive(Template)] | ||
| #[template(path = "diff.html")] | ||
| pub(crate) struct Diff<'a> { | ||
| pub file_count: String, | ||
| pub totals: Option<(usize, usize)>, | ||
| pub too_big: bool, | ||
| pub file_icon: String, | ||
| pub files: Vec<DiffFile<'a>>, | ||
| } | ||
| #[derive(Template)] | ||
| #[template(path = "account.html")] | ||
| pub(crate) struct Account<'a> { | ||
| pub title: &'a str, | ||
| pub signed_in: bool, | ||
| pub user: &'a str, | ||
| pub message: &'a str, | ||
| pub ok: bool, | ||
| pub csrf: &'a str, | ||
| pub min_password: usize, | ||
| } | ||
| #[derive(Template)] | ||
| @@ -1,16 +1,14 @@ | ||
| //! A file, highlighted or rendered, and its raw download. | ||
| use std::fmt::Write as _; | ||
| use std::sync::Arc; | ||
| use gitv::render; | ||
| use html_escape::{encode_double_quoted_attribute as attr, encode_text as esc}; | ||
| use super::tree::render_file; | ||
| use super::{RAW_LIMIT, Repo, SHOW_LIMIT, entry}; | ||
| use crate::View; | ||
| use crate::html::{icon, size}; | ||
| use crate::urls::{Q, clean_path, file_name, lossy, param, parent_of}; | ||
| use crate::{View, templates}; | ||
| pub(crate) fn view_blob(repo: &Repo, q: &Q, raw: bool) -> Option<View> { | ||
| let reference = q.get("ref").cloned().unwrap_or_else(|| repo.reader.default_ref()); | ||
| @@ -26,16 +24,18 @@ pub(crate) fn view_blob(repo: &Repo, q: &Q, raw: bool) -> Option<View> { | ||
| let name = lossy(file_name(&path)).into_owned(); | ||
| if raw { | ||
| if item.size > RAW_LIMIT { | ||
| return Some(View::Html(repo.page( | ||
| "File too large", | ||
| &format!( | ||
| r#"<section class="notfound"><h1 class="title">This file is too large to download here</h1> | ||
| <p class="count">{} is {}. Clone the repository to get it.</p><code>git clone {}</code></section>"#, | ||
| esc(&name), | ||
| size(item.size), | ||
| repo.clone_address().1 | ||
| ), | ||
| ))); | ||
| let message = format!("{name} is {}. Clone the repository to get it.", size(item.size)); | ||
| return Some(View::Html( | ||
| templates::Notice { | ||
| title: "File too large", | ||
| signed_in: repo.signed_in, | ||
| heading: "This file is too large to download here", | ||
| message: &message, | ||
| code: Some(format!("git clone {}", repo.clone_address().1)), | ||
| link: None, | ||
| } | ||
| .to_string(), | ||
| )); | ||
| } | ||
| let mut command = gitv::git_command(&repo.reader.dir); | ||
| command.args(["cat-file", "blob", &item.oid]); | ||
| @@ -57,27 +57,24 @@ pub(crate) fn view_blob(repo: &Repo, q: &Q, raw: bool) -> Option<View> { | ||
| }; | ||
| let (facts, content) = rendered.split_once('\x1f').unwrap_or(("", &rendered)); | ||
| let mut side = String::new(); | ||
| if markdown { | ||
| let link = |label: &str, view: &str, on: bool| { | ||
| let current = if on { r#" aria-current="true""# } else { "" }; | ||
| let extra = if view.is_empty() { String::new() } else { format!("view={view}") }; | ||
| format!(r#"<a href="{}"{current}>{label}</a>"#, attr(&repo.url_at("blob", &reference, &path, &extra))) | ||
| }; | ||
| let _ = write!( | ||
| side, | ||
| r#"<span class="segmented">{}{}</span>"#, | ||
| link("Preview", "", !as_code), | ||
| link("Code", "code", as_code) | ||
| ); | ||
| } | ||
| let _ = write!(side, r#"<a class="button" href="{}">Raw</a>"#, attr(&repo.url_at("raw", &reference, &path, ""))); | ||
| let body = repo.masthead("tree", &reference, Some(&commit)) | ||
| + &repo.locator("blob", &reference, &path) | ||
| + &format!( | ||
| r#"<section class="panel"><div class="panel-head"><div class="lead">{}<b>{}</b><span class="quiet">{facts}</span></div><div class="side">{side}</div></div>{content}</section>"#, | ||
| icon("file"), | ||
| esc(&name) | ||
| ); | ||
| Some(View::Html(repo.page(&format!("{} at {}", lossy(&path), lossy(&reference)), &body))) | ||
| let views = markdown.then(|| templates::Views { | ||
| preview: repo.url_at("blob", &reference, &path, ""), | ||
| code: repo.url_at("blob", &reference, &path, "view=code"), | ||
| as_code, | ||
| }); | ||
| Some(View::Html( | ||
| templates::Blob { | ||
| title: format!("{} at {}", lossy(&path), lossy(&reference)), | ||
| signed_in: repo.signed_in, | ||
| masthead: repo.masthead("tree", &reference, Some(&commit)), | ||
| locator: repo.locator("blob", &reference, &path), | ||
| file_icon: icon("file"), | ||
| name: &name, | ||
| facts, | ||
| views, | ||
| raw: repo.url_at("raw", &reference, &path, ""), | ||
| content, | ||
| } | ||
| .to_string(), | ||
| )) | ||
| } | ||
| @@ -1,9 +1,6 @@ | ||
| //! One commit and its changes. | ||
| use std::fmt::Write as _; | ||
| use gitv::git_capped; | ||
| use html_escape::{encode_double_quoted_attribute as attr, encode_text as esc}; | ||
| use super::{DIFF_LIMIT, Repo}; | ||
| use crate::cache::cached; | ||
| @@ -40,9 +37,33 @@ pub(crate) fn parse_changes(out: &[u8]) -> Vec<Change> { | ||
| changes | ||
| } | ||
| /// One line of a diff: `hunk`, `add`, `del` or `ctx`, its old and new line numbers (empty | ||
| /// where it has none), and its text. | ||
| pub(crate) struct DiffLine { | ||
| pub(crate) class: &'static str, | ||
| pub(crate) old: String, | ||
| pub(crate) new: String, | ||
| pub(crate) text: String, | ||
| } | ||
| impl DiffLine { | ||
| fn new(class: &'static str, old: String, new: String, text: &str) -> DiffLine { | ||
| DiffLine { class, old, new, text: text.to_string() } | ||
| } | ||
| /// The mark the page shows before the line. | ||
| pub(crate) fn sign(&self) -> &'static str { | ||
| match self.class { | ||
| "add" => "+", | ||
| "del" => "-", | ||
| _ => " ", | ||
| } | ||
| } | ||
| } | ||
| /// The lines of one file's diff: (class, old number, new number, text). | ||
| pub(crate) struct FileDiff { | ||
| pub(crate) rows: Vec<(&'static str, String, String, String)>, | ||
| pub(crate) rows: Vec<DiffLine>, | ||
| pub(crate) added: usize, | ||
| pub(crate) removed: usize, | ||
| pub(crate) binary: bool, | ||
| @@ -70,19 +91,19 @@ pub(crate) fn parse_diff(text: &str) -> Vec<FileDiff> { | ||
| .map(|r| r.trim_start_matches(['-', '+']).split(',').next().and_then(|n| n.parse().ok()).unwrap_or(0)) | ||
| .collect(); | ||
| (old, new) = (nums.first().copied().unwrap_or(0), nums.get(1).copied().unwrap_or(0)); | ||
| file.rows.push(("hunk", String::new(), String::new(), line.to_string())); | ||
| file.rows.push(DiffLine::new("hunk", String::new(), String::new(), line)); | ||
| } else if !in_hunk { | ||
| continue; | ||
| } else if let Some(t) = line.strip_prefix('+') { | ||
| file.rows.push(("add", String::new(), new.to_string(), t.to_string())); | ||
| file.rows.push(DiffLine::new("add", String::new(), new.to_string(), t)); | ||
| new += 1; | ||
| file.added += 1; | ||
| } else if let Some(t) = line.strip_prefix('-') { | ||
| file.rows.push(("del", old.to_string(), String::new(), t.to_string())); | ||
| file.rows.push(DiffLine::new("del", old.to_string(), String::new(), t)); | ||
| old += 1; | ||
| file.removed += 1; | ||
| } else if let Some(t) = line.strip_prefix(' ') { | ||
| file.rows.push(("ctx", old.to_string(), new.to_string(), t.to_string())); | ||
| file.rows.push(DiffLine::new("ctx", old.to_string(), new.to_string(), t)); | ||
| old += 1; | ||
| new += 1; | ||
| } | ||
| @@ -145,65 +166,29 @@ pub(crate) fn render_diff(repo: &Repo, oid: &str, parents: &str) -> Option<Strin | ||
| // names only rather than pair lines with the wrong file. | ||
| let paired = files.len() == changes.len(); | ||
| let mut body = String::new(); | ||
| let (added, removed) = files.iter().fold((0, 0), |(a, r), f| (a + f.added, r + f.removed)); | ||
| let totals = if paired { | ||
| format!(r#" <span class="plus">+{added}</span><span class="minus">−{removed}</span>"#) | ||
| } else { | ||
| String::new() | ||
| }; | ||
| let _ = write!(body, r#"<h2 class="changes">{} changed{totals}</h2>"#, plural(changes.len(), "file", "files")); | ||
| if too_big { | ||
| body += r#"<p class="note">This commit’s changes are too large to show line by line.</p>"#; | ||
| } | ||
| for (i, change) in changes.iter().enumerate() { | ||
| let file = files.get(i).filter(|_| paired); | ||
| let status = if change.status.is_empty() { | ||
| String::new() | ||
| } else { | ||
| format!(r#"<span class="status">{}</span>"#, change.status) | ||
| }; | ||
| // A deleted file still exists in the parent commit. | ||
| let at = if change.status == "Deleted" { parents.split_whitespace().next().unwrap_or(oid) } else { oid }; | ||
| let link = repo.url_at("blob", at.as_bytes(), &change.path, ""); | ||
| let counts = file.map_or(String::new(), |f| { | ||
| format!(r#"<span class="plus">+{}</span><span class="minus">−{}</span>"#, f.added, f.removed) | ||
| }); | ||
| let _ = write!( | ||
| body, | ||
| r#"<section class="panel"><div class="panel-head"><div class="lead">{}<a href="{}"><b>{}</b></a>{status}</div><div class="side">{counts}</div></div>"#, | ||
| icon("file"), | ||
| attr(&link), | ||
| esc(&lossy(&change.path)) | ||
| ); | ||
| match file { | ||
| None => {} | ||
| Some(f) if f.binary => body += r#"<p class="note">Binary file changed.</p>"#, | ||
| Some(f) if f.rows.is_empty() => body += r#"<p class="note">No content changes.</p>"#, | ||
| Some(f) => { | ||
| body += r#"<div class="diff-wrap"><table class="diff">"#; | ||
| for (class, o, n, text) in &f.rows { | ||
| if *class == "hunk" { | ||
| let _ = write!(body, r#"<tr class="hunk"><td colspan="3">{}</td></tr>"#, esc(text)); | ||
| } else { | ||
| let sign = match *class { | ||
| "add" => "+", | ||
| "del" => "-", | ||
| _ => " ", | ||
| }; | ||
| let _ = write!( | ||
| body, | ||
| r#"<tr class="{class}"><td class="num" data-n="{o}"></td><td class="num" data-n="{n}"></td><td class="line" data-s="{sign}">{}</td></tr>"#, | ||
| esc(text) | ||
| ); | ||
| } | ||
| } | ||
| body += "</table></div>"; | ||
| let panels: Vec<templates::DiffFile> = changes | ||
| .iter() | ||
| .enumerate() | ||
| .map(|(i, change)| { | ||
| // A deleted file still exists in the parent commit. | ||
| let at = if change.status == "Deleted" { parents.split_whitespace().next().unwrap_or(oid) } else { oid }; | ||
| templates::DiffFile { | ||
| href: repo.url_at("blob", at.as_bytes(), &change.path, ""), | ||
| path: lossy(&change.path), | ||
| status: change.status, | ||
| diff: files.get(i).filter(|_| paired), | ||
| } | ||
| } | ||
| body += "</section>"; | ||
| } | ||
| Some(body) | ||
| }) | ||
| .collect(); | ||
| let totals = paired.then(|| files.iter().fold((0, 0), |(a, r), f| (a + f.added, r + f.removed))); | ||
| let diff = templates::Diff { | ||
| file_count: plural(changes.len(), "file", "files"), | ||
| totals, | ||
| too_big, | ||
| file_icon: icon("file"), | ||
| files: panels, | ||
| }; | ||
| Some(diff.to_string()) | ||
| } | ||
| #[cfg(test)] | ||
| @@ -13,9 +13,8 @@ use std::os::unix::ffi::OsStrExt; | ||
| use std::time::Instant; | ||
| use gitv::{RepoDir, config, render, repo_dir}; | ||
| use html_escape::{encode_double_quoted_attribute as attr, encode_text as esc}; | ||
| use crate::html::{ago, icon, layout, subject_or_placeholder}; | ||
| use crate::html::{ago, icon, subject_or_placeholder}; | ||
| use crate::repository::Reader; | ||
| use crate::urls::{Q, encode, lossy}; | ||
| use crate::{View, templates}; | ||
| @@ -25,6 +24,7 @@ use log::view_log; | ||
| use tags::view_tags; | ||
| use tree::view_tree; | ||
| pub(crate) use commit::FileDiff; | ||
| pub(crate) use index::view_index; | ||
| pub(crate) const PAGE: usize = 50; | ||
| @@ -55,10 +55,6 @@ impl Repo { | ||
| Repo { signed_in: false, reader: Reader::new(dir), owner: owner.into(), name: name.into() } | ||
| } | ||
| pub(crate) fn page(&self, title: &str, body: &str) -> String { | ||
| layout(title, body, self.signed_in) | ||
| } | ||
| pub(crate) fn clone_address(&self) -> (&'static str, String) { | ||
| if self.reader.dir.is_public() { | ||
| ("HTTPS", format!("https://{}/{}/{}", config::host(), self.owner, self.name)) | ||
| @@ -128,91 +124,70 @@ impl Repo { | ||
| } | ||
| }) | ||
| } | ||
| /// Name, clone address and tabs, shared by every repository page. `commit` is `reference` | ||
| /// already resolved, when the caller has it. | ||
| pub(crate) fn masthead(&self, active: &str, reference: &[u8], commit: Option<&str>) -> String { | ||
| let commit = commit.map(str::to_string).or_else(|| self.reader.resolve(reference)); | ||
| let commits = commit.map_or(0, |c| self.reader.commit_count(&c)); | ||
| let tags = self.reader.tags().len(); | ||
| let tab = |view: &str, glyph: &str, label: &str, count: Option<usize>| { | ||
| let current = if view == active { r#" aria-current="page""# } else { "" }; | ||
| let tab_ref = if view == "tags" { b"" } else { reference }; | ||
| let badge = count.map_or(String::new(), |n| format!(r#"<span class="n">{n}</span>"#)); | ||
| format!( | ||
| r#"<a href="{}"{current}>{}{label}{badge}</a>"#, | ||
| attr(&self.url_at(view, tab_ref, b"", "")), | ||
| icon(glyph) | ||
| ) | ||
| let tab = |view: &str, glyph: &str, label: &'static str, count: Option<usize>| templates::Tab { | ||
| href: self.url_at(view, if view == "tags" { b"" } else { reference }, b"", ""), | ||
| current: view == active, | ||
| icon: icon(glyph), | ||
| label, | ||
| count, | ||
| }; | ||
| let (protocol, address) = self.clone_address(); | ||
| format!( | ||
| r#"<div class="repohead"><h1 class="reponame"><a class="own" href="/">{owner}</a><span class="sep">/</span><a href="{home}">{name}</a></h1> | ||
| <label class="clone"><span>{protocol}</span><input readonly aria-label="Clone address" value="{address}"></label></div> | ||
| <nav class="tabs" aria-label="Repository">{}{}{}</nav>"#, | ||
| tab("tree", "code", "Code", None), | ||
| tab("log", "commits", "Commits", Some(commits)), | ||
| tab("tags", "tag", "Tags", Some(tags)), | ||
| owner = esc(&self.owner), | ||
| name = esc(&self.name), | ||
| home = attr(&self.url("tree", &[])), | ||
| ) | ||
| templates::Masthead { | ||
| owner: &self.owner, | ||
| name: &self.name, | ||
| home: self.url("tree", &[]), | ||
| protocol, | ||
| address, | ||
| tabs: vec![ | ||
| tab("tree", "code", "Code", None), | ||
| tab("log", "commits", "Commits", Some(commits)), | ||
| tab("tags", "tag", "Tags", Some(self.reader.tags().len())), | ||
| ], | ||
| } | ||
| .to_string() | ||
| } | ||
| /// Branch and tag menu, then the path as breadcrumbs. | ||
| pub(crate) fn locator(&self, view: &str, reference: &[u8], path: &[u8]) -> String { | ||
| // `link` is what the URL carries; `name` is what people see. | ||
| let item = |link: Vec<u8>, name: &[u8]| { | ||
| let current = if link == reference { r#" aria-current="true""# } else { "" }; | ||
| let href = self.url_at(view, &link, path, ""); | ||
| format!(r#"<a href="{}"{current}>{}</a>"#, attr(&href), esc(&lossy(name))) | ||
| let item = |link: Vec<u8>, name: &'_ [u8]| templates::MenuItem { | ||
| href: self.url_at(view, &link, path, ""), | ||
| current: link == reference, | ||
| name: lossy(name).into_owned().into(), | ||
| }; | ||
| let branches: String = self.reader.heads().iter().map(|b| item(self.reader.branch_ref(b), b)).collect(); | ||
| let tags: String = self.reader.tags().iter().map(|t| item(self.reader.tag_ref(t), t)).collect(); | ||
| let mut menu = format!("<h2>Branches</h2>{branches}"); | ||
| if !tags.is_empty() { | ||
| menu += &format!("<h2>Tags</h2>{tags}"); | ||
| } | ||
| let mut crumbs = String::new(); | ||
| if !path.is_empty() { | ||
| let _ = write!( | ||
| crumbs, | ||
| r#"<a href="{}">{}</a>"#, | ||
| attr(&self.url_at("tree", reference, b"", "")), | ||
| esc(&self.name) | ||
| ); | ||
| let parts: Vec<&[u8]> = path.split(|b| *b == b'/').collect(); | ||
| for (i, part) in parts.iter().enumerate() { | ||
| crumbs += r#"<span class="sep">/</span>"#; | ||
| if i + 1 == parts.len() { | ||
| let _ = write!(crumbs, "<b>{}</b>", esc(&lossy(part))); | ||
| } else { | ||
| let href = self.url_at("tree", reference, &parts[..=i].join(&b'/'), ""); | ||
| let _ = write!(crumbs, r#"<a href="{}">{}</a>"#, attr(&href), esc(&lossy(part))); | ||
| } | ||
| } | ||
| crumbs = format!(r#"<nav class="crumbs" aria-label="Path">{crumbs}</nav>"#); | ||
| let parts: Vec<&[u8]> = if path.is_empty() { Vec::new() } else { path.split(|b| *b == b'/').collect() }; | ||
| let crumbs = parts | ||
| .iter() | ||
| .enumerate() | ||
| .map(|(i, part)| templates::Crumb { | ||
| href: (i + 1 < parts.len()).then(|| self.url_at("tree", reference, &parts[..=i].join(&b'/'), "")), | ||
| name: lossy(part), | ||
| }) | ||
| .collect(); | ||
| let shown = reference | ||
| .strip_prefix(b"refs/heads/") | ||
| .or_else(|| reference.strip_prefix(b"refs/tags/")) | ||
| .unwrap_or(reference); | ||
| templates::Locator { | ||
| branch_icon: icon("branch"), | ||
| chevron_icon: icon("chevron"), | ||
| current: lossy(shown), | ||
| branches: self.reader.heads().iter().map(|b| item(self.reader.branch_ref(b), b)).collect(), | ||
| tags: self.reader.tags().iter().map(|t| item(self.reader.tag_ref(t), t)).collect(), | ||
| root: (!path.is_empty()).then(|| self.url_at("tree", reference, b"", "")), | ||
| repo_name: &self.name, | ||
| crumbs, | ||
| } | ||
| format!( | ||
| r#"<div class="locator"><details class="refmenu"><summary>{}{}{}</summary><div class="menu">{menu}</div></details> | ||
| {crumbs}</div>"#, | ||
| icon("branch"), | ||
| esc(&lossy( | ||
| reference | ||
| .strip_prefix(b"refs/heads/") | ||
| .or_else(|| reference.strip_prefix(b"refs/tags/")) | ||
| .unwrap_or(reference) | ||
| )), | ||
| icon("chevron"), | ||
| ) | ||
| .to_string() | ||
| } | ||
| pub(crate) fn sha_link(&self, oid: &str) -> String { | ||
| format!( | ||
| r#"<a class="sha" href="{}">{}</a>"#, | ||
| attr(&self.url("commit", &[("id", oid)])), | ||
| &oid[..oid.len().min(7)] | ||
| ) | ||
| templates::ShaLink { href: self.url("commit", &[("id", oid)]), short: &oid[..oid.len().min(7)] }.to_string() | ||
| } | ||
| } | ||
| @@ -1,13 +1,9 @@ | ||
| //! The tags in a repository. | ||
| use std::fmt::Write as _; | ||
| use html_escape::{encode_double_quoted_attribute as attr, encode_text as esc}; | ||
| use super::Repo; | ||
| use crate::View; | ||
| use crate::html::ago; | ||
| use crate::urls::lossy; | ||
| use crate::{View, templates}; | ||
| pub(crate) fn view_tags(repo: &Repo) -> Option<View> { | ||
| let out = repo.reader.git_bytes(&[ | ||
| @@ -16,7 +12,7 @@ pub(crate) fn view_tags(repo: &Repo) -> Option<View> { | ||
| "--format=%(refname:lstrip=2)%1f%(objectname)%1f%(*objectname)%1f%(creatordate:unix)%1f%(creatordate:format:%-d %b %Y)%1f%(objecttype)%1f%(contents:subject)", | ||
| "refs/tags", | ||
| ])?; | ||
| let mut rows = String::new(); | ||
| let mut rows = Vec::new(); | ||
| for line in out.split(|b| *b == b'\n') { | ||
| // The tag's message goes last, so one containing the separator stays whole. | ||
| let Ok([name, direct, peeled, stamp, date, kind, note]) = | ||
| @@ -25,26 +21,21 @@ pub(crate) fn view_tags(repo: &Repo) -> Option<View> { | ||
| continue; | ||
| }; | ||
| let target = if peeled.is_empty() { direct } else { peeled }; | ||
| let note = if kind == b"tag" && !note.is_empty() { | ||
| format!(r#"<span class="tnote">{}</span>"#, esc(&lossy(note))) | ||
| } else { | ||
| String::new() | ||
| }; | ||
| let _ = write!( | ||
| rows, | ||
| r#"<li class="tag-row"><span class="tname">{}</span>{note}<span class="tmeta">{}{}</span> | ||
| <span class="tacts"><a class="button" href="{}">Browse files</a></span></li>"#, | ||
| esc(&lossy(name)), | ||
| repo.sha_link(&lossy(target)), | ||
| ago(&lossy(stamp), &lossy(date)), | ||
| attr(&repo.url_at("tree", &repo.reader.tag_ref(name), b"", "")) | ||
| ); | ||
| rows.push(templates::TagRow { | ||
| name: lossy(name), | ||
| note: (kind == b"tag" && !note.is_empty()).then(|| lossy(note)), | ||
| sha_link: repo.sha_link(&lossy(target)), | ||
| when: ago(&lossy(stamp), &lossy(date)), | ||
| browse: repo.url_at("tree", &repo.reader.tag_ref(name), b"", ""), | ||
| }); | ||
| } | ||
| let listing = if rows.is_empty() { | ||
| r#"<div class="panel empty"><h2>No tags yet</h2><p>Tag a release and push it to see it here.</p><code>git tag -a v1.0.0 -m "v1.0.0" && git push origin v1.0.0</code></div>"#.to_string() | ||
| } else { | ||
| format!(r#"<div class="panel"><ul class="rows">{rows}</ul></div>"#) | ||
| }; | ||
| let body = repo.masthead("tags", &repo.reader.default_ref(), None) + &listing; | ||
| Some(View::Html(repo.page(&format!("Tags in {}/{}", repo.owner, repo.name), &body))) | ||
| Some(View::Html( | ||
| templates::Tags { | ||
| title: format!("Tags in {}/{}", repo.owner, repo.name), | ||
| signed_in: repo.signed_in, | ||
| masthead: repo.masthead("tags", &repo.reader.default_ref(), None), | ||
| rows, | ||
| } | ||
| .to_string(), | ||
| )) | ||
| } | ||
| @@ -4,7 +4,6 @@ use std::ffi::OsStr; | ||
| use std::sync::Arc; | ||
| use gitv::{config, render}; | ||
| use html_escape::encode_text as esc; | ||
| use super::{Entry, PAGE, Repo, SHOW_LIMIT, entry}; | ||
| use crate::cache::cached; | ||
| @@ -19,15 +18,15 @@ pub(crate) fn view_tree(repo: &Repo, q: &Q) -> Option<View> { | ||
| if !repo.reader.heads().is_empty() { | ||
| return None; | ||
| } | ||
| let body = repo.masthead("tree", &reference, None) | ||
| + &format!( | ||
| r#"<div class="panel empty"><h2>This repository is empty</h2><p>Push a branch to get started.</p> | ||
| <code>git push git@{}:{}/{}.git main</code></div>"#, | ||
| config::host(), | ||
| esc(&repo.owner), | ||
| esc(&repo.name) | ||
| ); | ||
| return Some(View::Html(repo.page(&format!("{}/{}", repo.owner, repo.name), &body))); | ||
| let page = templates::Empty { | ||
| title: format!("{}/{}", repo.owner, repo.name), | ||
| signed_in: repo.signed_in, | ||
| masthead: repo.masthead("tree", &reference, None), | ||
| host: config::host(), | ||
| owner: &repo.owner, | ||
| name: &repo.name, | ||
| }; | ||
| return Some(View::Html(page.to_string())); | ||
| }; | ||
| let listing = [OsStr::new("ls-tree"), OsStr::new("-l"), OsStr::new("-z"), &spec(&commit, &path)]; | ||
| let Some(listing) = repo.reader.git_bytes(&listing) else { | ||
| @@ -151,8 +150,5 @@ pub(crate) fn render_file( | ||
| pub(crate) fn code_view(path: &str, text: &str) -> String { | ||
| let lines = text.lines().count().max(1); | ||
| let gutter: String = (1..=lines).map(|n| format!("{n}\n")).collect(); | ||
| format!( | ||
| r#"<div class="code-view"><pre class="gutter" aria-hidden="true">{gutter}</pre><pre class="code">{}</pre></div>"#, | ||
| render::highlight(path, text) | ||
| ) | ||
| templates::Code { gutter, code: render::highlight(path, text) }.to_string() | ||
| } | ||
+13−0
| @@ -0,0 +1,13 @@ | ||
| {% extends "base.html" %} | ||
| {% block content %}<div class="pagehead"><h1 class="title">Account</h1><p class="count">Signed in as {{ user }}</p></div>{% if !message.is_empty() %}{% if ok %}<p class="alert ok" role="status">{{ message }}</p>{% else %}<p class="alert" role="alert">{{ message }}</p>{% endif %}{% endif %} | ||
| <section class="panel form-panel"><h2>Change password</h2> | ||
| <form class="form" method="post" action="/account"> | ||
| <input type="hidden" name="csrf" value="{{ csrf }}"> | ||
| <label>Current password<input name="current" type="password" autocomplete="current-password" required></label> | ||
| <label>New password<span class="hint">At least {{ min_password }} characters.</span><input name="new" type="password" autocomplete="new-password" minlength="{{ min_password }}" required></label> | ||
| <label>Repeat new password<input name="repeat" type="password" autocomplete="new-password" minlength="{{ min_password }}" required></label> | ||
| <label>Authenticator code<input name="code" inputmode="numeric" autocomplete="one-time-code" pattern="[0-9]{6}" maxlength="6" required></label> | ||
| <button class="button primary" type="submit">Change password</button></form> | ||
| <p class="hint">Changing the password signs out every other session.</p></section> | ||
| <section class="panel form-panel"><h2>Sign out</h2> | ||
| <form method="post" action="/logout"><input type="hidden" name="csrf" value="{{ csrf }}"><button class="button" type="submit">Sign out</button></form></section>{% endblock %} | ||
templates/blob.htmlAdded
+5−0
| @@ -0,0 +1,5 @@ | ||
| {% extends "base.html" %} | ||
| {% block content %} | ||
| {{ masthead|safe }}{{ locator|safe }} | ||
| <section class="panel"><div class="panel-head"><div class="lead">{{ file_icon|safe }}<b>{{ name }}</b><span class="quiet">{{ facts }}</span></div><div class="side">{% if let Some(views) = views %}<span class="segmented"><a href="{{ views.preview }}"{% if !views.as_code %} aria-current="true"{% endif %}>Preview</a><a href="{{ views.code }}"{% if views.as_code %} aria-current="true"{% endif %}>Code</a></span>{% endif %}<a class="button" href="{{ raw }}">Raw</a></div></div>{{ content|safe }}</section> | ||
| {% endblock %} | ||
templates/code.htmlAdded
+1−0
| @@ -0,0 +1 @@ | ||
| <div class="code-view"><pre class="gutter" aria-hidden="true">{{ gutter }}</pre><pre class="code">{{ code|safe }}</pre></div> | ||
templates/diff.htmlAdded
+5−0
| @@ -0,0 +1,5 @@ | ||
| <h2 class="changes">{{ file_count }} changed{% if let Some((added, removed)) = totals %} <span class="plus">+{{ added }}</span><span class="minus">−{{ removed }}</span>{% endif %}</h2>{% if too_big %}<p class="note">This commit’s changes are too large to show line by line.</p>{% endif %} | ||
| {%- for file in files %}<section class="panel"><div class="panel-head"><div class="lead">{{ file_icon|safe }}<a href="{{ file.href }}"><b>{{ file.path }}</b></a>{% if !file.status.is_empty() %}<span class="status">{{ file.status }}</span>{% endif %}</div><div class="side">{% if let Some(diff) = file.diff %}<span class="plus">+{{ diff.added }}</span><span class="minus">−{{ diff.removed }}</span>{% endif %}</div></div> | ||
| {%- if let Some(diff) = file.diff %}{% if diff.binary %}<p class="note">Binary file changed.</p>{% else if diff.rows.is_empty() %}<p class="note">No content changes.</p>{% else %}<div class="diff-wrap"><table class="diff"> | ||
| {%- for row in diff.rows %}{% if row.class == "hunk" %}<tr class="hunk"><td colspan="3">{{ row.text }}</td></tr>{% else %}<tr class="{{ row.class }}"><td class="num" data-n="{{ row.old }}"></td><td class="num" data-n="{{ row.new }}"></td><td class="line" data-s="{{ row.sign() }}">{{ row.text }}</td></tr>{% endif %}{% endfor -%} | ||
| </table></div>{% endif %}{% endif %}</section>{% endfor %} | ||
templates/empty.htmlAdded
+5−0
| @@ -0,0 +1,5 @@ | ||
| {% extends "base.html" %} | ||
| {% block content %} | ||
| {{ masthead|safe }}<div class="panel empty"><h2>This repository is empty</h2><p>Push a branch to get started.</p> | ||
| <code>git push git@{{ host }}:{{ owner }}/{{ name }}.git main</code></div> | ||
| {% endblock %} | ||
templates/layout.htmlDeleted
+0−2
| @@ -1,2 +0,0 @@ | ||
| {% extends "base.html" %} | ||
| {% block content %}{{ body|safe }}{% endblock %} | ||
+2−0
| @@ -0,0 +1,2 @@ | ||
| <div class="locator"><details class="refmenu"><summary>{{ branch_icon|safe }}{{ current }}{{ chevron_icon|safe }}</summary><div class="menu"><h2>Branches</h2>{% for item in branches %}<a href="{{ item.href }}"{% if item.current %} aria-current="true"{% endif %}>{{ item.name }}</a>{% endfor %}{% if !tags.is_empty() %}<h2>Tags</h2>{% for item in tags %}<a href="{{ item.href }}"{% if item.current %} aria-current="true"{% endif %}>{{ item.name }}</a>{% endfor %}{% endif %}</div></details> | ||
| {% if let Some(root) = root %}<nav class="crumbs" aria-label="Path"><a href="{{ root }}">{{ repo_name }}</a>{% for crumb in crumbs %}<span class="sep">/</span>{% if let Some(href) = crumb.href %}<a href="{{ href }}">{{ crumb.name }}</a>{% else %}<b>{{ crumb.name }}</b>{% endif %}{% endfor %}</nav>{% endif %}</div> | ||
+3−0
| @@ -0,0 +1,3 @@ | ||
| <div class="repohead"><h1 class="reponame"><a class="own" href="/">{{ owner }}</a><span class="sep">/</span><a href="{{ home }}">{{ name }}</a></h1> | ||
| <label class="clone"><span>{{ protocol }}</span><input readonly aria-label="Clone address" value="{{ address }}"></label></div> | ||
| <nav class="tabs" aria-label="Repository">{% for tab in tabs %}<a href="{{ tab.href }}"{% if tab.current %} aria-current="page"{% endif %}>{{ tab.icon|safe }}{{ tab.label }}{% if let Some(n) = tab.count %}<span class="n">{{ n }}</span>{% endif %}</a>{% endfor %}</nav> | ||
+3−0
| @@ -0,0 +1,3 @@ | ||
| {% extends "base.html" %} | ||
| {% block content %}<section class="notfound"><h1 class="title">{{ heading }}</h1> | ||
| {% if !message.is_empty() %}<p class="count">{{ message }}</p>{% endif %}{% if let Some(code) = code %}<code>{{ code }}</code>{% endif %}{% if let Some((href, label)) = link %}<a class="button" href="{{ href }}">{{ label }}</a>{% endif %}</section>{% endblock %} | ||
+1−0
| @@ -0,0 +1 @@ | ||
| <a class="sha" href="{{ href }}">{{ short }}</a> | ||
templates/tags.htmlAdded
+7−0
| @@ -0,0 +1,7 @@ | ||
| {% extends "base.html" %} | ||
| {% block content %} | ||
| {{ masthead|safe }} | ||
| {% if rows.is_empty() %}<div class="panel empty"><h2>No tags yet</h2><p>Tag a release and push it to see it here.</p><code>git tag -a v1.0.0 -m "v1.0.0" && git push origin v1.0.0</code></div> | ||
| {% else %}<div class="panel"><ul class="rows">{% for row in rows %}<li class="tag-row"><span class="tname">{{ row.name }}</span>{% if let Some(note) = row.note %}<span class="tnote">{{ note }}</span>{% endif %}<span class="tmeta">{{ row.sha_link|safe }}{{ row.when }}</span> | ||
| <span class="tacts"><a class="button" href="{{ row.browse }}">Browse files</a></span></li>{% endfor %}</ul></div>{% endif %} | ||
| {% endblock %} | ||
+7−6
| @@ -250,9 +250,10 @@ fn diff_links_survive_odd_names() { | ||
| for (shown, encoded) in | ||
| [("x b/c.txt", "x%20b/c.txt"), ("q\"uote.txt", "q%22uote.txt"), ("latin1-caf\u{fffd}.txt", "latin1-caf%E9.txt")] | ||
| { | ||
| assert!(html.contains(&format!("<b>{shown}</b>")), "{shown} missing: {html}"); | ||
| // Templates write `"` and `&` as numeric entities. | ||
| assert!(html.contains(&format!("<b>{}</b>", shown.replace('"', """))), "{shown} missing: {html}"); | ||
| let path = format!("/ada/site/blob?ref={}&path={encoded}", fixture().oddities); | ||
| assert!(html.contains(&path.replace('&', "&")), "{shown} isn't linked to {path}"); | ||
| assert!(html.contains(&path.replace('&', "&")), "{shown} isn't linked to {path}"); | ||
| assert_eq!(s.get(&path).status, 200, "{path}"); | ||
| } | ||
| let log = s.get("/ada/site/log?ref=odd").text(); | ||
| @@ -430,7 +431,7 @@ fn file_view_highlights_with_line_numbers() { | ||
| assert!(html.contains("changed") && !html.contains("<hi>"), "current content, escaped"); | ||
| assert!(html.contains("3 lines, 39 bytes")); | ||
| assert!(html.contains("<b>main.rs</b>")); | ||
| assert!(html.contains("href=\"/ada/site/raw?ref=main&path=src/main.rs\">Raw")); | ||
| assert!(html.contains("href=\"/ada/site/raw?ref=main&path=src/main.rs\">Raw")); | ||
| // A second view comes from the cache and is identical. | ||
| assert_eq!(s.get("/ada/site/blob?path=src/main.rs").text(), html); | ||
| @@ -542,12 +543,12 @@ fn commit_shows_message_facts_and_diff() { | ||
| assert!(html.contains("<h2 class=\"ctitle\">Remove old.txt</h2>")); | ||
| assert!(html.contains(&format!("<span class=\"sha\">{}</span>", &f.removal[..12]))); | ||
| assert!(html.contains(&format!("id={}\" ", f.first)) || html.contains(&format!("id={}\"", f.first)), "parent link"); | ||
| assert!(html.contains("3 files changed"), "{html}"); | ||
| assert!(html.contains("3 files changed <span class=\"plus\">+"), "the totals follow the count: {html}"); | ||
| assert!(html.contains("<span class=\"status\">Deleted</span>")); | ||
| // A deleted file links to its last version, in the parent commit. | ||
| assert!(html.contains(&format!("href=\"/ada/site/blob?ref={}&path=old.txt\"", f.first))); | ||
| assert!(html.contains(&format!("href=\"/ada/site/blob?ref={}&path=old.txt\"", f.first))); | ||
| assert!(html.contains("<tr class=\"del\"><td class=\"num\" data-n=\"1\"></td><td class=\"num\" data-n=\"\"></td><td class=\"line\" data-s=\"-\">going away</td></tr>")); | ||
| assert!(html.contains("data-s=\"+\"> println!(\"changed\");</td>")); | ||
| assert!(html.contains("data-s=\"+\"> println!("changed");</td>")); | ||
| assert!(html.contains(&format!("href=\"/ada/site/tree?ref={}\">Browse files", f.removal))); | ||
| let first = s.get(&format!("/ada/site/commit?id={}", &f.first[..10])).text(); | ||