link the index page's owners and repos to a configurable site
Signed-off-by: dawn <90008@klbr.net>
83 unmodified lines848586878889909183 unmodified lines# up to 3 lines# og_description = "*{repos}* repos across *{users}* owners\nserved straight from nginx *{kaomoji}*"# the card's alt text, the og_* lines joined when unset# og_alt = "..."# owners and repos link to <links>/<owner>/<name>, "https://{hostname}" for a# frontend on this host# links = "https://tangled.org"
154 unmodified linesExpand all155156157158159160161162163204 unmodified linesExpand all154 unmodified linesExpand all ("index.description", &index.description), ("index.og_title", &index.og_title), ("index.og_subtitle", &index.og_subtitle), ("index.og_description", &index.og_description), ("index.links", &index.links), ] { hash_fields::text(&mut hasher, name.as_bytes(), value); } hash_fields::field(&mut hasher, b"index.og_alt", index.og_alt.as_deref());204 unmodified linesExpand all224 unmodified linesExpand all225226227228229230231232233234235236237224 unmodified linesExpand all assert!( format!("{error:#}").contains("more than 3 lines"), "{error:#}" );
let links = load_with("[index]\nlinks = \"https://{hostname}\""); assert_eq!(links.index.links, "https://{hostname}"); assert_ne!(links.config_digest(), defaults.config_digest()); let error = load_result("[index]\nlinks = \"javascript:alert(1)\"") .err() .expect("only http(s) links"); assert!(format!("{error:#}").contains("index.links"), "{error:#}");}221 unmodified linesExpand all2222232242252262272282292302317 unmodified lines2392402412422432442452462477 unmodified lines25525625725825926026126226326426526626726826927015 unmodified lines286287288289290291292293294295229 unmodified linesExpand all221 unmodified linesExpand all /// up to `MOST_OG_DESCRIPTION_LINES` lines, `*text*` in the accent colour pub og_description: String, /// derived from the og_* lines when unset pub og_alt: Option<String>, /// where owners and repos link to, as `<links>/<owner>/<name>` pub links: String,}
pub const MOST_OG_DESCRIPTION_LINES: usize = 3;
7 unmodified lines og_title: "{hostname}".to_string(), og_subtitle: "a static knot for *tangled*".to_string(), og_description: "*{repos}* repos across *{users}* owners\nserved straight from nginx *{kaomoji}*".to_string(), og_alt: None, links: "https://tangled.org".to_string(), } }}
7 unmodified lines og_title: raw.og_title.unwrap_or(defaults.og_title), og_subtitle: raw.og_subtitle.unwrap_or(defaults.og_subtitle), og_description: raw.og_description.unwrap_or(defaults.og_description), og_alt: raw.og_alt, links: raw.links.unwrap_or(defaults.links), }; anyhow::ensure!( index.links.starts_with("https://") || index.links.starts_with("http://"), "index.links {:?} is not an http(s) url", index.links ); anyhow::ensure!( index.og_description.lines().count() <= MOST_OG_DESCRIPTION_LINES, "index.og_description has more than {MOST_OG_DESCRIPTION_LINES} lines" ); Ok(index)15 unmodified lines #[serde(default)] pub(crate) og_description: Option<String>, #[serde(default)] pub(crate) og_alt: Option<String>, #[serde(default)] pub(crate) links: Option<String>,}
#[derive(Debug, Clone, Default)]pub struct WritesConfig {229 unmodified linesExpand all135 unmodified linesExpand all13613713813914014114214314420 unmodified lines165166167168169170171172173196 unmodified linesExpand all37037137237337437537637737810 unmodified lines38939039139239039339439539639714 unmodified lines412413414415413416417418419420272 unmodified linesExpand all135 unmodified linesExpand all pub og_title: String, pub og_subtitle: String, pub og_description: String, pub og_alt: String, pub links: String,}
impl Page { pub fn new(index: &IndexConfig, vars: &Vars) -> Self {20 unmodified lines og_title, og_subtitle, og_description, og_alt, links: vars.expand(&index.links).trim_end_matches('/').to_string(), } }}
196 unmodified linesExpand all let base_esc = escape(base_url); let og_url_esc = format!("{base_esc}/"); let og_image_esc = format!("{base_esc}/{OG_IMAGE_FILE}"); let og_image_alt_esc = escape(&page.og_alt); let links_esc = escape(&page.links); let h1_inner = render_hostname(hostname); let kaomoji = escape(kaomoji_for(generation_id)); let total_repos: usize = sections.iter().map(|s| s.repos.len()).sum();
10 unmodified lines "\n <input class=\"u-chk\" type=\"checkbox\" id=\"u-{sec_idx}\">" )); } people_html.push_str(&format!( "\n <header><a href=\"https://tangled.org/{owner}\">{owner}</a><span>{count}</span></header>\n <ul class=\"repos\">" "\n <header><a href=\"{links_esc}/{owner}\">{owner}</a><span>{count}</span></header>\n <ul class=\"repos\">" )); for (idx, repo) in section.repos.iter().enumerate() { let name = escape(&repo.name); let did = escape(&repo.did);14 unmodified lines .unwrap_or_default() .to_ascii_lowercase() )); people_html.push_str(&format!( "\n <li{cls} data-q=\"{query}\"><div class=\"row\"><a href=\"https://tangled.org/{owner}/{name}\" data-t=\"{name}\">{name}</a>" "\n <li{cls} data-q=\"{query}\"><div class=\"row\"><a href=\"{links_esc}/{owner}/{name}\" data-t=\"{name}\">{name}</a>" )); if let Some(desc) = &repo.description { let desc_esc = escape(desc); people_html.push_str(&format!("\n <div class=\"desc\">{desc_esc}</div>"));272 unmodified linesExpand all857 unmodified linesExpand all85885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390439 unmodified lines857 unmodified linesExpand all );}
#[test]fn owners_and_repos_link_under_the_configured_base() { let sections = [PersonSection { label: "ptr.pet".to_string(), repos: vec![ServedRepo { did: "did:plc:z1".to_string(), name: "yumak".to_string(), description: None, }], }]; let html_with = |index: &IndexConfig| { let page = page_with(index, "git.klbr.net", "gen-1", §ions); render( &test_url("git.klbr.net"), "git.klbr.net", "gen-1", §ions, &page, ) }; let tangled = html_with(&IndexConfig::default()); assert!(tangled.contains("<a href=\"https://tangled.org/ptr.pet\">ptr.pet</a>")); assert!(tangled.contains("<a href=\"https://tangled.org/ptr.pet/yumak\" data-t"));
let own = html_with(&IndexConfig { links: "https://{hostname}/".to_string(), ..IndexConfig::default() }); assert!( own.contains("<a href=\"https://git.klbr.net/ptr.pet\">ptr.pet</a>"), "{own}" ); assert!( own.contains("<a href=\"https://git.klbr.net/ptr.pet/yumak\" data-t"), "{own}" ); assert!(!own.contains("https://tangled.org/ptr.pet\""));}
#[test]fn og_card_renders_a_1200x630_png() { let index = IndexConfig { og_title: "git.klbr.net".to_string(), og_subtitle: "a static knot for *tangled*".to_string(),39 unmodified lines