GITv

Tidy the top bar and stop serving stale stylesheets

Browse files

Pages link the stylesheet by a hash of its contents and serve it as immutable, so a style change can never meet a cached copy (a stale one had run the wordmark and host together). The top bar drops the host, which the clone address already shows, for a logo that follows the colour scheme. Breadcrumbs appear only inside a folder or file, and commit pages gain a Browse files button. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Author
Um9i vulgarmessiah@gmail.com
Date
22 Nov 2026, 11:10
Commit
13ff131c4742
Parent
f1cb563

2 files changed +35−14

@@ -36,9 +36,11 @@ code,pre,kbd,.mono{font-family:var(--f-mono)}
/* Top bar */
.top{background:var(--surface);border-bottom:1px solid var(--rule)}
.bar{display:flex;align-items:center;justify-content:space-between;gap:16px;max-width:1080px;height:56px;margin:0 auto;padding:0 24px}
.mark{font:800 20px/1 var(--f-display);letter-spacing:-.02em;color:var(--ink)}
.mark:hover{text-decoration:none;color:var(--accent)}
.host{font-family:var(--f-mono);font-size:13px;color:var(--ink-2)}
.mark{display:inline-flex;align-items:center;gap:10px;min-height:44px;font:800 20px/1 var(--f-display);letter-spacing:-.02em;color:var(--ink)}
.mark:hover{text-decoration:none}
.logo{width:26px;height:26px;flex:none}
.logo rect{fill:var(--accent)}
.logo g{stroke:var(--surface)}
main{max-width:1080px;margin:0 auto;padding:32px 24px 72px}
/* Page and repository headings */
@@ -182,8 +184,9 @@ a.entry:hover .name{color:var(--accent)}
/* Commit */
.cmsg{padding:24px 28px 22px}
.ctitle{font:700 clamp(22px,3.4vw,28px)/1.2 var(--f-display);letter-spacing:-.015em;margin:0 0 10px;max-width:42ch;overflow-wrap:anywhere}
.cbody{margin:0;max-width:72ch;font:15px/1.6 var(--f-text);color:var(--ink-2);white-space:pre-wrap;overflow-wrap:anywhere}
.chead{display:flex;align-items:flex-start;justify-content:space-between;gap:12px 24px;flex-wrap:wrap}
.ctitle{font:700 clamp(22px,3.4vw,28px)/1.2 var(--f-display);letter-spacing:-.015em;margin:0;max-width:42ch;overflow-wrap:anywhere}
.cbody{margin:12px 0 0;max-width:72ch;font:15px/1.6 var(--f-text);color:var(--ink-2);white-space:pre-wrap;overflow-wrap:anywhere}
.facts{display:flex;flex-wrap:wrap;gap:12px 36px;margin:0;padding:16px 28px;font-size:14px;background:var(--sunk);border-top:1px solid var(--rule)}
.facts dt{font-size:12.5px;font-weight:600;color:var(--ink-2);margin-bottom:2px}
.facts dd{margin:0;overflow-wrap:anywhere}
@@ -20,6 +20,18 @@ const FONT_TEXT: &[u8] = include_bytes!("../../assets/fonts/text.woff2");
const FONT_MONO: &[u8] = include_bytes!("../../assets/fonts/mono.woff2");
const FAVICON: &str = r##"<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"><rect width="32" height="32" rx="8" fill="#0f6b5f"/><g fill="none" stroke="#fff" stroke-width="2.6" stroke-linecap="round"><circle cx="11" cy="9" r="2.6"/><circle cx="11" cy="23" r="2.6"/><circle cx="22" cy="12" r="2.6"/><path d="M11 11.6v8.8M22 14.6c0 4-3.4 5-11 6"/></g></svg>"##;
/// The stylesheet's URL carries a hash of its contents, so browsers can cache it for good and
/// still pick up every change.
static STYLE_URL: std::sync::LazyLock<String> = std::sync::LazyLock::new(|| {
use std::hash::{Hash, Hasher};
let mut hasher = std::hash::DefaultHasher::new();
STYLESHEET.hash(&mut hasher);
format!("/style.css?v={:012x}", hasher.finish() & 0xffff_ffff_ffff)
});
/// The favicon's branch glyph, coloured by the stylesheet so it follows light and dark mode.
const LOGO: &str = r#"<svg class="logo" viewBox="0 0 32 32" aria-hidden="true"><rect width="32" height="32" rx="8"/><g fill="none" stroke-width="2.6" stroke-linecap="round"><circle cx="11" cy="9" r="2.6"/><circle cx="11" cy="23" r="2.6"/><circle cx="22" cy="12" r="2.6"/><path d="M11 11.6v8.8M22 14.6c0 4-3.4 5-11 6"/></g></svg>"#;
const PAGE: usize = 50;
const RAW_LIMIT: usize = 50 << 20;
const DIFF_LIMIT: usize = 2 << 20;
@@ -73,6 +85,11 @@ fn static_file(kind: &'static str, data: &'static [u8]) -> Response {
([(header::CONTENT_TYPE, kind), (header::CACHE_CONTROL, "max-age=86400")], data).into_response()
}
fn stylesheet() -> Response {
let headers = [(header::CONTENT_TYPE, "text/css; charset=utf-8"), (header::CACHE_CONTROL, "max-age=31536000, immutable")];
(headers, STYLESHEET).into_response()
}
// ---------------------------------------------------------------------------------------------
// Helpers
@@ -151,13 +168,14 @@ fn page(title: &str, body: &str) -> String {
r##"<!doctype html><html lang="en"><head><meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>{title} | GITv</title>
<link rel="stylesheet" href="/style.css"><link rel="icon" href="/favicon.svg" type="image/svg+xml">
<link rel="stylesheet" href="{style}"><link rel="icon" href="/favicon.svg" type="image/svg+xml">
<link rel="preload" href="/fonts/display.woff2" as="font" type="font/woff2" crossorigin>
<link rel="preload" href="/fonts/text.woff2" as="font" type="font/woff2" crossorigin></head>
<body><a class="skip" href="#main">Skip to content</a>
<header class="top"><div class="bar"><a class="mark" href="/">GITv</a><span class="host">{HOST}</span></div></header>
<header class="top"><div class="bar"><a class="mark" href="/">{LOGO}GITv</a></div></header>
<main id="main">{body}</main></body></html>"##,
title = esc(title)
title = esc(title),
style = STYLE_URL.as_str(),
)
}
@@ -302,9 +320,7 @@ impl Repo {
menu += &format!("<h2>Tags</h2>{tags}");
}
let mut crumbs = String::new();
if path.is_empty() {
let _ = write!(crumbs, "<b>{}</b>", esc(&self.name));
} else {
if !path.is_empty() {
let _ = write!(crumbs, r#"<a href="{}">{}</a>"#, attr(&self.url("tree", &[("ref", reference)])), esc(&self.name));
let parts: Vec<&str> = path.split('/').collect();
for (i, part) in parts.iter().enumerate() {
@@ -316,10 +332,11 @@ impl Repo {
let _ = write!(crumbs, r#"<a href="{}">{}</a>"#, attr(&href), esc(part));
}
}
crumbs = format!(r#"<nav class="crumbs" aria-label="Path">{crumbs}</nav>"#);
}
format!(
r#"<div class="locator"><details class="refmenu"><summary>{}{}{}</summary><div class="menu">{menu}</div></details>
<nav class="crumbs" aria-label="Path">{crumbs}</nav></div>"#,
{crumbs}</div>"#,
icon("branch"),
esc(reference),
icon("chevron"),
@@ -616,10 +633,11 @@ fn view_commit(repo: &Repo, q: &Q) -> Option<View> {
let parent_links: String = parents.split_whitespace().map(|p| repo.sha_link(p)).collect::<Vec<_>>().join(" ");
let mut body = repo.masthead("log", &repo.default_ref());
let message = message.trim();
let _ = write!(body, r#"<section class="panel"><div class="cmsg"><h2 class="ctitle">{}</h2>{}</div><dl class="facts">
let _ = write!(body, r#"<section class="panel"><div class="cmsg"><div class="chead"><h2 class="ctitle">{}</h2><a class="button" href="{}">Browse files</a></div>{}</div><dl class="facts">
<div><dt>Author</dt><dd>{} <span class="quiet">{}</span></dd></div><div><dt>Date</dt><dd>{}</dd></div>
<div><dt>Commit</dt><dd><span class="sha">{}</span></dd></div>{}</dl></section>"#,
esc(subject),
attr(&repo.url("tree", &[("ref", oid)])),
if message.is_empty() { String::new() } else { format!(r#"<p class="cbody">{}</p>"#, esc(message)) },
esc(author), esc(email), esc(date), &oid[..12],
if parent_links.is_empty() { String::new() } else { format!("<div><dt>Parent</dt><dd>{parent_links}</dd></div>") });
@@ -707,7 +725,7 @@ async fn main() {
let Action::Serve { port } = Cli::parse().action;
let app = Router::new()
.route("/", get(|| blocking(view_index)))
.route("/style.css", get(|| async { static_file("text/css; charset=utf-8", STYLESHEET.as_bytes()) }))
.route("/style.css", get(|| async { stylesheet() }))
.route("/favicon.svg", get(|| async { static_file("image/svg+xml", FAVICON.as_bytes()) }))
.route("/fonts/display.woff2", get(|| async { static_file("font/woff2", FONT_DISPLAY) }))
.route("/fonts/text.woff2", get(|| async { static_file("font/woff2", FONT_TEXT) }))