2026-10-19 11:00:10 +03:00
|
|
|
|
//! Pages of the site: one HTML template, a translation file per language, the data of
|
|
|
|
|
|
//! the latest release filled in on every request (so the download buttons are right
|
|
|
|
|
|
//! without JavaScript).
|
|
|
|
|
|
|
|
|
|
|
|
use std::collections::HashMap;
|
|
|
|
|
|
use std::path::Path;
|
|
|
|
|
|
|
|
|
|
|
|
use serde_json::{Value, json};
|
|
|
|
|
|
|
|
|
|
|
|
use crate::Release;
|
|
|
|
|
|
|
|
|
|
|
|
/// Languages of the site: code, own name, Open Graph locale. English is at `/`, the
|
|
|
|
|
|
/// others at `/<code>/`.
|
|
|
|
|
|
pub const LANGS: &[(&str, &str, &str)] = &[
|
|
|
|
|
|
("en", "English", "en_US"),
|
|
|
|
|
|
("ru", "Русский", "ru_RU"),
|
|
|
|
|
|
("fr", "Français", "fr_FR"),
|
|
|
|
|
|
("de", "Deutsch", "de_DE"),
|
|
|
|
|
|
("es", "Español", "es_ES"),
|
|
|
|
|
|
("it", "Italiano", "it_IT"),
|
2026-10-24 12:48:03 +03:00
|
|
|
|
("pt", "Português", "pt_BR"),
|
|
|
|
|
|
("uz", "Oʻzbekcha", "uz_UZ"),
|
|
|
|
|
|
("kk", "Қазақша", "kk_KZ"),
|
2026-10-19 11:00:10 +03:00
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
/// Screenshots in gallery order (file stem); the first one is shown in the hero.
|
|
|
|
|
|
const SHOTS: &[&str] = &[
|
|
|
|
|
|
"01-game",
|
|
|
|
|
|
"02-engine",
|
Website: new features and fresh screenshots; no missing glyphs in the app
The site lists the reference tab, games from Lichess and Chess.com, translated
comments and self-update, and the notation and animation under "Make it
yours", in six languages. Thirteen screenshots (three new: reference,
translation, online games) on the owner's green board with Merida pieces, the
"looks" one on another board. The translation shot shows a real ChatGPT
translation of our own German comments to Reti-Tartakower 1910, put into the
screenshot cache once (shots/translate-for-shots.py); the shots send nothing.
The app: "✕" next to the Chess.com nickname, "⌂" in board search and "✓" in
translation texts had no glyph (empty boxes): replaced by the bundled 🗙, 🏠
and ✔. A test now checks every character of the translations and the string
literals against the character maps of the bundled fonts. The online games dev
hook takes two nicknames.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-21 23:47:14 +03:00
|
|
|
|
"03-reference",
|
Website: nine screenshots (play against the computer, Android) and the texts for 1.6
The owner's choice: the game, the engine, the reference, the report, the
play dialog (Rodent V, Tal), Android (dark, four screens), filters, position
search, the looks; translation, variations, marks, preview, library and
online go. The play section: Maia 600–2600 and Rodent V 800–3000 on their
own scales, draw offers, games written to the player's database; the hero
and Android texts. The screenshot script follows the new set.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 17:50:11 +03:00
|
|
|
|
"04-review",
|
|
|
|
|
|
"05-play",
|
|
|
|
|
|
"06-android",
|
|
|
|
|
|
"07-filters",
|
|
|
|
|
|
"08-position-search",
|
|
|
|
|
|
"09-looks",
|
2026-10-19 11:00:10 +03:00
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
/// Strings the page script needs (download panel, buttons, lightbox).
|
|
|
|
|
|
const CLIENT_KEYS: &[&str] = &[
|
|
|
|
|
|
"btn_windows",
|
|
|
|
|
|
"btn_macos",
|
|
|
|
|
|
"btn_linux",
|
|
|
|
|
|
"btn_version",
|
|
|
|
|
|
"btn_latest",
|
|
|
|
|
|
"apple_silicon",
|
|
|
|
|
|
"mac_requires",
|
|
|
|
|
|
"mac_intel_warning",
|
|
|
|
|
|
"chromeos",
|
|
|
|
|
|
"copy_link",
|
2026-10-19 17:34:38 +03:00
|
|
|
|
"mail_copy",
|
|
|
|
|
|
"mail_copied",
|
2026-10-19 11:00:10 +03:00
|
|
|
|
"link_copied",
|
|
|
|
|
|
"share_link",
|
|
|
|
|
|
"started",
|
|
|
|
|
|
"try_again",
|
|
|
|
|
|
"choose_another",
|
|
|
|
|
|
"close",
|
|
|
|
|
|
"next_windows",
|
|
|
|
|
|
"next_macos_title",
|
|
|
|
|
|
"mac_step1",
|
2026-10-19 15:32:03 +03:00
|
|
|
|
"mac_warn_title",
|
|
|
|
|
|
"mac_warn_text",
|
|
|
|
|
|
"mac_way1",
|
|
|
|
|
|
"mac_open1",
|
2026-10-19 11:00:10 +03:00
|
|
|
|
"mac15_step2",
|
|
|
|
|
|
"mac15_step3",
|
2026-10-19 15:32:03 +03:00
|
|
|
|
"mac_open4",
|
|
|
|
|
|
"mac_way2",
|
|
|
|
|
|
"mac_way2_text",
|
2026-10-19 11:00:10 +03:00
|
|
|
|
"next_linux",
|
|
|
|
|
|
"copy",
|
|
|
|
|
|
"copied",
|
|
|
|
|
|
"lb_count",
|
|
|
|
|
|
"meta_title",
|
2026-10-22 22:20:26 +03:00
|
|
|
|
"btn_android",
|
2026-10-23 00:33:33 +03:00
|
|
|
|
"and_light_title",
|
2026-10-22 22:20:26 +03:00
|
|
|
|
"and_requires",
|
|
|
|
|
|
"and_alpha",
|
|
|
|
|
|
"next_android",
|
2026-10-19 11:00:10 +03:00
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
pub struct Site {
|
|
|
|
|
|
template: String,
|
|
|
|
|
|
strings: HashMap<String, HashMap<String, String>>,
|
|
|
|
|
|
/// Public address without a trailing slash (`https://chesspenguin.example`).
|
|
|
|
|
|
pub url: String,
|
|
|
|
|
|
asset_version: String,
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl Site {
|
|
|
|
|
|
pub fn load(dir: &Path, url: String) -> Site {
|
|
|
|
|
|
let template = std::fs::read_to_string(dir.join("index.html")).expect("site/index.html");
|
|
|
|
|
|
let mut strings = HashMap::new();
|
|
|
|
|
|
for (code, _, _) in LANGS {
|
|
|
|
|
|
let path = dir.join("i18n").join(format!("{code}.json"));
|
|
|
|
|
|
let map: HashMap<String, String> = std::fs::read_to_string(&path)
|
|
|
|
|
|
.ok()
|
|
|
|
|
|
.and_then(|s| serde_json::from_str(&s).ok())
|
|
|
|
|
|
.unwrap_or_else(|| {
|
|
|
|
|
|
eprintln!("no translations in {}", path.display());
|
|
|
|
|
|
HashMap::new()
|
|
|
|
|
|
});
|
|
|
|
|
|
strings.insert(code.to_string(), map);
|
|
|
|
|
|
}
|
|
|
|
|
|
// Changes with every start: browsers fetch the new CSS and JS after a deploy.
|
|
|
|
|
|
let asset_version = format!(
|
|
|
|
|
|
"{:x}",
|
|
|
|
|
|
std::time::SystemTime::now()
|
|
|
|
|
|
.duration_since(std::time::UNIX_EPOCH)
|
|
|
|
|
|
.map_or(0, |d| d.as_secs())
|
|
|
|
|
|
);
|
|
|
|
|
|
Site {
|
|
|
|
|
|
template,
|
|
|
|
|
|
strings,
|
|
|
|
|
|
url: url.trim_end_matches('/').to_string(),
|
|
|
|
|
|
asset_version,
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn has_lang(&self, code: &str) -> bool {
|
|
|
|
|
|
LANGS.iter().any(|(c, _, _)| *c == code)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// A string in `lang`, else in English, else the key.
|
|
|
|
|
|
fn t<'a>(&'a self, lang: &str, key: &'a str) -> &'a str {
|
|
|
|
|
|
self.strings
|
|
|
|
|
|
.get(lang)
|
|
|
|
|
|
.and_then(|m| m.get(key))
|
|
|
|
|
|
.or_else(|| self.strings.get("en").and_then(|m| m.get(key)))
|
|
|
|
|
|
.map_or(key, String::as_str)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn path(lang: &str) -> String {
|
|
|
|
|
|
if lang == "en" {
|
|
|
|
|
|
"/".to_string()
|
|
|
|
|
|
} else {
|
|
|
|
|
|
format!("/{lang}/")
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// The page in `lang` with the release's version, sizes and file names.
|
|
|
|
|
|
pub fn page(&self, lang: &str, release: Option<&Release>) -> String {
|
|
|
|
|
|
let mut html = self.translate(&self.template, lang);
|
|
|
|
|
|
let page_url = format!("{}{}", self.url, Self::path(lang));
|
|
|
|
|
|
let alternates: String = LANGS
|
|
|
|
|
|
.iter()
|
|
|
|
|
|
.map(|(c, _, _)| {
|
|
|
|
|
|
format!(
|
|
|
|
|
|
"<link rel=\"alternate\" hreflang=\"{c}\" href=\"{}{}\">\n",
|
|
|
|
|
|
self.url,
|
|
|
|
|
|
Self::path(c)
|
|
|
|
|
|
)
|
|
|
|
|
|
})
|
|
|
|
|
|
.chain(std::iter::once(format!(
|
|
|
|
|
|
"<link rel=\"alternate\" hreflang=\"x-default\" href=\"{}/\">",
|
|
|
|
|
|
self.url
|
|
|
|
|
|
)))
|
|
|
|
|
|
.collect();
|
|
|
|
|
|
let lang_options: String = LANGS
|
|
|
|
|
|
.iter()
|
|
|
|
|
|
.map(|(c, name, _)| {
|
|
|
|
|
|
format!(
|
|
|
|
|
|
"<option value=\"{c}\"{}>{name}</option>",
|
|
|
|
|
|
if *c == lang { " selected" } else { "" }
|
|
|
|
|
|
)
|
|
|
|
|
|
})
|
|
|
|
|
|
.collect();
|
|
|
|
|
|
let lang_links: String = LANGS
|
|
|
|
|
|
.iter()
|
|
|
|
|
|
.map(|(c, name, _)| format!("<a href=\"{}\" hreflang=\"{c}\" data-lang=\"{c}\">{name}</a>", Self::path(c)))
|
|
|
|
|
|
.collect::<Vec<_>>()
|
|
|
|
|
|
.join(" · ");
|
|
|
|
|
|
let locale = LANGS
|
|
|
|
|
|
.iter()
|
|
|
|
|
|
.find(|(c, _, _)| *c == lang)
|
|
|
|
|
|
.map_or("en_US", |l| l.2);
|
|
|
|
|
|
let root_redirect = if lang == "en" { ROOT_REDIRECT } else { "" };
|
|
|
|
|
|
let gallery: String = SHOTS
|
|
|
|
|
|
.iter()
|
|
|
|
|
|
.enumerate()
|
|
|
|
|
|
.skip(1)
|
|
|
|
|
|
.map(|(i, stem)| {
|
|
|
|
|
|
let n = i + 1;
|
|
|
|
|
|
format!(
|
|
|
|
|
|
"<li><a href=\"/screenshots/{stem}.png\" data-shot=\"{n}\"><picture>\
|
|
|
|
|
|
<source type=\"image/webp\" srcset=\"/screenshots/{stem}-640.webp 640w, /screenshots/{stem}-1280.webp 1280w\" sizes=\"(min-width: 900px) 360px, (min-width: 640px) 50vw, 85vw\">\
|
|
|
|
|
|
<img src=\"/screenshots/{stem}-640.jpg\" width=\"1920\" height=\"1080\" loading=\"lazy\" alt=\"{alt}\"></picture></a>\
|
|
|
|
|
|
<p>{cap}</p></li>",
|
|
|
|
|
|
alt = attr(self.t(lang, &format!("alt{n}"))),
|
|
|
|
|
|
cap = self.t(lang, &format!("shot{n}")),
|
|
|
|
|
|
)
|
|
|
|
|
|
})
|
|
|
|
|
|
.collect();
|
|
|
|
|
|
let t: serde_json::Map<String, Value> = CLIENT_KEYS
|
|
|
|
|
|
.iter()
|
|
|
|
|
|
.map(|k| (k.to_string(), Value::String(self.t(lang, k).to_string())))
|
|
|
|
|
|
.collect();
|
|
|
|
|
|
let shots: Vec<Value> = SHOTS
|
|
|
|
|
|
.iter()
|
|
|
|
|
|
.enumerate()
|
|
|
|
|
|
.map(|(i, stem)| {
|
|
|
|
|
|
json!({
|
|
|
|
|
|
"full": format!("/screenshots/{stem}.png"),
|
|
|
|
|
|
"src": format!("/screenshots/{stem}-1920.webp"),
|
|
|
|
|
|
"fallback": format!("/screenshots/{stem}-1280.jpg"),
|
|
|
|
|
|
"caption": self.t(lang, &format!("shot{}", i + 1)),
|
|
|
|
|
|
"alt": self.t(lang, &format!("alt{}", i + 1)),
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|
|
|
|
|
|
.collect();
|
|
|
|
|
|
let assets: serde_json::Map<String, Value> = release
|
|
|
|
|
|
.map(|r| {
|
|
|
|
|
|
r.assets
|
|
|
|
|
|
.iter()
|
|
|
|
|
|
.map(|a| {
|
|
|
|
|
|
(
|
|
|
|
|
|
a.platform.to_string(),
|
|
|
|
|
|
json!({ "file": a.name, "size": size(a.size) }),
|
|
|
|
|
|
)
|
|
|
|
|
|
})
|
|
|
|
|
|
.collect()
|
|
|
|
|
|
})
|
|
|
|
|
|
.unwrap_or_default();
|
|
|
|
|
|
let client = json!({
|
|
|
|
|
|
"lang": lang,
|
|
|
|
|
|
"home": Self::path(lang),
|
|
|
|
|
|
"version": release.map(|r| r.version.clone()),
|
|
|
|
|
|
"assets": assets,
|
|
|
|
|
|
"shots": shots,
|
|
|
|
|
|
"t": t,
|
|
|
|
|
|
});
|
|
|
|
|
|
let json_ld = json!({
|
|
|
|
|
|
"@context": "https://schema.org",
|
|
|
|
|
|
"@type": "SoftwareApplication",
|
|
|
|
|
|
"name": "ChessPenguin",
|
Android: design review fixes, icon, signed releases, the site's Android downloads
- The design review (docs/design/android-ui.md §17): the move buttons in the
bottom bar (snackbars above them), ripple on press, larger ◀ ▶, coordinates
over the pieces, readable NAG colors in the light theme, 16 dp edges, the
⋮ menu (game details, copy PGN/FEN, share), "Deeper" next to ▾, TalkBack
states, no "*" for unfinished games, "Found N of M", texts.
- The penguin as the adaptive icon and on the splash screen; dark window.
- Release builds: R8, signing from the environment, androidApp/scripts/release.sh
(two APKs, apksigner and 16 KB alignment checks); the release workflow builds
them from the repository secrets.
- Website: the Android tab with both APKs, "Download for Android" on phones.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 01:57:03 +03:00
|
|
|
|
"operatingSystem": "Windows, macOS, Linux, Android",
|
2026-10-19 11:00:10 +03:00
|
|
|
|
"applicationCategory": "GameApplication",
|
|
|
|
|
|
"license": "https://www.gnu.org/licenses/gpl-3.0.html",
|
|
|
|
|
|
"softwareVersion": release.map(|r| r.version.clone()),
|
|
|
|
|
|
"downloadUrl": format!("{}/#download", self.url),
|
|
|
|
|
|
"offers": { "@type": "Offer", "price": "0", "priceCurrency": "USD" },
|
|
|
|
|
|
});
|
|
|
|
|
|
for (key, value) in [
|
|
|
|
|
|
("{{lang}}", lang.to_string()),
|
|
|
|
|
|
("{{locale}}", locale.to_string()),
|
|
|
|
|
|
("{{page_url}}", page_url),
|
|
|
|
|
|
("{{site}}", self.url.clone()),
|
|
|
|
|
|
("{{home}}", Self::path(lang)),
|
|
|
|
|
|
("{{alternates}}", alternates),
|
|
|
|
|
|
("{{lang_options}}", lang_options),
|
|
|
|
|
|
("{{lang_links}}", lang_links),
|
|
|
|
|
|
("{{root_redirect}}", root_redirect.to_string()),
|
|
|
|
|
|
("{{gallery}}", gallery),
|
|
|
|
|
|
// `</` must not close the script element the JSON sits in.
|
|
|
|
|
|
("{{client_json}}", client.to_string().replace("</", "<\\/")),
|
|
|
|
|
|
("{{json_ld}}", json_ld.to_string().replace("</", "<\\/")),
|
|
|
|
|
|
("{{asset_version}}", self.asset_version.clone()),
|
|
|
|
|
|
] {
|
|
|
|
|
|
html = html.replace(key, &value);
|
|
|
|
|
|
}
|
|
|
|
|
|
self.fill_release(html, lang, release)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// `{{t:key}}` → the string in `lang`.
|
|
|
|
|
|
fn translate(&self, template: &str, lang: &str) -> String {
|
|
|
|
|
|
let mut out = String::with_capacity(template.len() + 8192);
|
|
|
|
|
|
let mut rest = template;
|
|
|
|
|
|
while let Some(start) = rest.find("{{t:") {
|
|
|
|
|
|
out.push_str(&rest[..start]);
|
|
|
|
|
|
let after = &rest[start + 4..];
|
|
|
|
|
|
let Some(end) = after.find("}}") else {
|
|
|
|
|
|
out.push_str(&rest[start..]);
|
|
|
|
|
|
return out;
|
|
|
|
|
|
};
|
|
|
|
|
|
out.push_str(self.t(lang, &after[..end]));
|
|
|
|
|
|
rest = &after[end + 2..];
|
|
|
|
|
|
}
|
|
|
|
|
|
out.push_str(rest);
|
|
|
|
|
|
out
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// `{version}`, `{date}`, `{size:<platform>}`, `{file:<platform>}`.
|
|
|
|
|
|
fn fill_release(&self, mut html: String, lang: &str, release: Option<&Release>) -> String {
|
|
|
|
|
|
let version = release.map_or("", |r| r.version.as_str());
|
|
|
|
|
|
html = html.replace("{version}", version);
|
|
|
|
|
|
html = html.replace("{date}", &release.map(|r| date(&r.published, lang)).unwrap_or_default());
|
|
|
|
|
|
for (platform, _) in crate::PLATFORMS {
|
|
|
|
|
|
let asset = release.and_then(|r| r.assets.iter().find(|a| a.platform == *platform));
|
|
|
|
|
|
html = html.replace(
|
|
|
|
|
|
&format!("{{size:{platform}}}"),
|
|
|
|
|
|
&asset.map(|a| size(a.size)).unwrap_or_default(),
|
|
|
|
|
|
);
|
|
|
|
|
|
html = html.replace(
|
|
|
|
|
|
&format!("{{file:{platform}}}"),
|
|
|
|
|
|
&asset.map_or_else(String::new, |a| a.name.clone()),
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
html
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn not_found(&self, lang: &str) -> String {
|
|
|
|
|
|
format!(
|
|
|
|
|
|
"<!doctype html><html lang=\"{lang}\"><head><meta charset=\"utf-8\"><meta name=\"viewport\" content=\"width=device-width,initial-scale=1\">\
|
|
|
|
|
|
<title>{title} · ChessPenguin</title><link rel=\"stylesheet\" href=\"/css/site.css?v={v}\"></head>\
|
|
|
|
|
|
<body><main class=\"wrap nf\"><h1>{title}</h1><p>{text}</p><p><a class=\"btn btn-small btn-accent\" href=\"{home}#download\">{link}</a></p></main></body></html>",
|
|
|
|
|
|
title = self.t(lang, "nf_title"),
|
|
|
|
|
|
text = self.t(lang, "nf_text"),
|
|
|
|
|
|
link = self.t(lang, "nf_link"),
|
|
|
|
|
|
home = Self::path(lang),
|
|
|
|
|
|
v = self.asset_version,
|
|
|
|
|
|
)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn sitemap(&self) -> String {
|
|
|
|
|
|
let mut out = String::from(
|
|
|
|
|
|
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\" xmlns:xhtml=\"http://www.w3.org/1999/xhtml\">\n",
|
|
|
|
|
|
);
|
|
|
|
|
|
for (code, _, _) in LANGS {
|
|
|
|
|
|
out.push_str(&format!("<url><loc>{}{}</loc>", self.url, Self::path(code)));
|
|
|
|
|
|
for (alt, _, _) in LANGS {
|
|
|
|
|
|
out.push_str(&format!(
|
|
|
|
|
|
"<xhtml:link rel=\"alternate\" hreflang=\"{alt}\" href=\"{}{}\"/>",
|
|
|
|
|
|
self.url,
|
|
|
|
|
|
Self::path(alt)
|
|
|
|
|
|
));
|
|
|
|
|
|
}
|
|
|
|
|
|
out.push_str("</url>\n");
|
|
|
|
|
|
}
|
|
|
|
|
|
out.push_str("</urlset>\n");
|
|
|
|
|
|
out
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// On `/` only, before anything is drawn: the language chosen before, else the first
|
|
|
|
|
|
/// browser language the site has, else English stays.
|
2026-10-24 12:48:03 +03:00
|
|
|
|
const ROOT_REDIRECT: &str = r#"<script>(function(){var L=["ru","fr","de","es","it","pt","uz","kk"],p=null;try{p=localStorage.getItem("lang")}catch(e){}if(!p){var ls=navigator.languages||[navigator.language||""];for(var i=0;i<ls.length;i++){var c=(ls[i]||"").slice(0,2).toLowerCase();if(c==="en"||L.indexOf(c)>=0){p=c;break}}}if(p&&p!=="en"&&L.indexOf(p)>=0){location.replace("/"+p+"/"+location.hash)}})();</script>"#;
|
2026-10-19 11:00:10 +03:00
|
|
|
|
|
|
|
|
|
|
fn attr(s: &str) -> String {
|
|
|
|
|
|
s.replace('&', "&").replace('"', """).replace('<', "<")
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// "14 MB", "8.4 MB" (decimal megabytes, as browsers and Finder show).
|
|
|
|
|
|
pub fn size(bytes: u64) -> String {
|
|
|
|
|
|
let mb = bytes as f64 / 1e6;
|
|
|
|
|
|
if mb < 10.0 {
|
|
|
|
|
|
format!("{mb:.1} MB")
|
|
|
|
|
|
} else {
|
|
|
|
|
|
format!("{:.0} MB", mb)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// "October 19, 2026" in the page's language, from an RFC 3339 time.
|
|
|
|
|
|
fn date(rfc3339: &str, lang: &str) -> String {
|
|
|
|
|
|
let Some((y, rest)) = rfc3339.split_once('-') else {
|
|
|
|
|
|
return String::new();
|
|
|
|
|
|
};
|
|
|
|
|
|
let (m, rest) = rest.split_once('-').unwrap_or(("", ""));
|
|
|
|
|
|
let d: u32 = rest.get(..2).and_then(|s| s.parse().ok()).unwrap_or(0);
|
|
|
|
|
|
let m: usize = m.parse().unwrap_or(0);
|
|
|
|
|
|
if m == 0 || m > 12 || d == 0 {
|
|
|
|
|
|
return String::new();
|
|
|
|
|
|
}
|
|
|
|
|
|
let months: [&str; 12] = match lang {
|
|
|
|
|
|
"ru" => ["января", "февраля", "марта", "апреля", "мая", "июня", "июля", "августа", "сентября", "октября", "ноября", "декабря"],
|
|
|
|
|
|
"fr" => ["janvier", "février", "mars", "avril", "mai", "juin", "juillet", "août", "septembre", "octobre", "novembre", "décembre"],
|
|
|
|
|
|
"de" => ["Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember"],
|
|
|
|
|
|
"es" => ["enero", "febrero", "marzo", "abril", "mayo", "junio", "julio", "agosto", "septiembre", "octubre", "noviembre", "diciembre"],
|
|
|
|
|
|
"it" => ["gennaio", "febbraio", "marzo", "aprile", "maggio", "giugno", "luglio", "agosto", "settembre", "ottobre", "novembre", "dicembre"],
|
2026-10-24 12:48:03 +03:00
|
|
|
|
"pt" => ["janeiro", "fevereiro", "março", "abril", "maio", "junho", "julho", "agosto", "setembro", "outubro", "novembro", "dezembro"],
|
|
|
|
|
|
"uz" => ["yanvar", "fevral", "mart", "aprel", "may", "iyun", "iyul", "avgust", "sentabr", "oktabr", "noyabr", "dekabr"],
|
|
|
|
|
|
"kk" => ["қаңтар", "ақпан", "наурыз", "сәуір", "мамыр", "маусым", "шілде", "тамыз", "қыркүйек", "қазан", "қараша", "желтоқсан"],
|
2026-10-19 11:00:10 +03:00
|
|
|
|
_ => ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
|
|
|
|
|
|
};
|
|
|
|
|
|
let month = months[m - 1];
|
|
|
|
|
|
match lang {
|
|
|
|
|
|
"en" => format!("{month} {d}, {y}"),
|
|
|
|
|
|
"de" => format!("{d}. {month} {y}"),
|
2026-10-24 12:48:03 +03:00
|
|
|
|
"es" | "pt" => format!("{d} de {month} de {y}"),
|
|
|
|
|
|
"uz" => format!("{y}-yil {d}-{month}"),
|
|
|
|
|
|
"kk" => format!("{y} жылғы {d} {month}"),
|
2026-10-19 11:00:10 +03:00
|
|
|
|
_ => format!("{d} {month} {y}"),
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
|
|
mod tests {
|
|
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
|
fn sizes_and_dates() {
|
|
|
|
|
|
assert_eq!(size(15_673_262), "16 MB");
|
|
|
|
|
|
assert_eq!(size(8_400_000), "8.4 MB");
|
|
|
|
|
|
assert_eq!(date("2026-10-19T06:54:58Z", "en"), "October 19, 2026");
|
|
|
|
|
|
assert_eq!(date("2026-10-19T06:54:58Z", "ru"), "19 октября 2026");
|
|
|
|
|
|
assert_eq!(date("2026-10-19T06:54:58Z", "de"), "19. Oktober 2026");
|
|
|
|
|
|
assert_eq!(date("2026-10-19T06:54:58Z", "es"), "19 de octubre de 2026");
|
2026-10-24 12:48:03 +03:00
|
|
|
|
assert_eq!(date("2026-10-19T06:54:58Z", "pt"), "19 de outubro de 2026");
|
|
|
|
|
|
assert_eq!(date("2026-10-19T06:54:58Z", "uz"), "2026-yil 19-oktabr");
|
|
|
|
|
|
assert_eq!(date("2026-10-19T06:54:58Z", "kk"), "2026 жылғы 19 қазан");
|
2026-10-19 11:00:10 +03:00
|
|
|
|
assert_eq!(date("bad", "en"), "");
|
|
|
|
|
|
}
|
2026-10-22 22:20:26 +03:00
|
|
|
|
|
|
|
|
|
|
/// Every text the page script asks for is sent to it: a key left out shows as
|
|
|
|
|
|
/// itself ("btn_android") on the page.
|
|
|
|
|
|
#[test]
|
|
|
|
|
|
fn the_script_gets_every_text_it_uses() {
|
|
|
|
|
|
let script = include_str!("../../static/js/site.js");
|
|
|
|
|
|
let en: HashMap<String, String> =
|
|
|
|
|
|
serde_json::from_str(include_str!("../../site/i18n/en.json")).expect("en.json");
|
|
|
|
|
|
let quoted = script.split('"').skip(1).step_by(2);
|
|
|
|
|
|
let missing: Vec<&str> = quoted
|
|
|
|
|
|
.filter(|k| en.contains_key(*k) && !CLIENT_KEYS.contains(k))
|
|
|
|
|
|
.collect();
|
|
|
|
|
|
assert!(missing.is_empty(), "not in CLIENT_KEYS: {missing:?}");
|
|
|
|
|
|
}
|
2026-10-19 11:00:10 +03:00
|
|
|
|
}
|