forge
Explore
Log in

Don't you dare go Hollow

Relative times on every page keep themselves current

Browse files at this commit

bcaef901dbc87aecf8dc13e336bc101cfd50455eAhmet Kaan GümüşParent: 868c8a6
  • feat
    • relative times on every page keep themselves current
Show full message
⚡ feat: relative times on every page keep themselves current

Server-rendered relative times ("3 hours ago") were static text, so an open page
aged without moving. Every `<time>` that shows an age now carries data-rel, and
nav.js re-words it locally, arming one setTimeout for the next real change of
wording. No request is made.

- views: rel_words() gives the wording; the <html> element carries it as
  data-rel-words with the server clock in data-rel-now, copied on each swap.
- All relative <time> tags across pages get data-rel="true", plus the
  standalone labels (blame, tree, branches, banner, dashboard, runners,
  export, import) that now wrap a stamped <time>.
- CI run list is live on every page, not only page 1.
- Run rows and the run header show their age as a <time data-rel>.
- Tests: rel_words asserts added to relative_time_picks_the_unit; three
  asserts updated for the live list and the <time> markup.
crates/forge-web/assets/nav.jsmodified+53 -1
@@ -145,7 +145,7 @@
145 145
146 function adopt(doc, keepFields, dd, jobs) {146 function adopt(doc, keepFields, dd, jobs) {
147 document.title = doc.title;147 document.title = doc.title;
148- ['lang', 'data-theme', 'data-accent-light', 'data-accent-dark', 'data-base-light', 'data-base-dark', 'data-sidebar', 'data-ui'].forEach(function (name) {148+ ['lang', 'data-theme', 'data-accent-light', 'data-accent-dark', 'data-base-light', 'data-base-dark', 'data-sidebar', 'data-ui', 'data-rel-words', 'data-rel-now'].forEach(function (name) {
149 if (doc.documentElement.hasAttribute(name)) { root.setAttribute(name, doc.documentElement.getAttribute(name)); }149 if (doc.documentElement.hasAttribute(name)) { root.setAttribute(name, doc.documentElement.getAttribute(name)); }
150 else { root.removeAttribute(name); }150 else { root.removeAttribute(name); }
151 });151 });
@@ -172,6 +172,7 @@
172 syncLive();172 syncLive();
173 syncPush();173 syncPush();
174 syncTick();174 syncTick();
175+ syncRel();
175 }176 }
176 177
177 // The log tail is a terminal: it opens at its end. A reader who scrolls up keeps their place.178 // The log tail is a terminal: it opens at its end. A reader who scrolls up keeps their place.
@@ -1514,6 +1515,56 @@
1514 tickAll();1515 tickAll();
1515 }1516 }
1516 1517
1518+ // Relative times. A `<time data-rel>` carries its stamp in datetime, and its label is re-worded
1519+ // here as the clock moves. The words come from the html element's data-rel-words (the server's own
1520+ // wording, see views::rel_words): "just now", then the singular and plural of each unit with {n}.
1521+ // The wording changes only at fixed ages, so one setTimeout is armed for the soonest of them. No
1522+ // request is made. A swap re-arms it, and the server clock (data-rel-now) sets the offset.
1523+ var relTimer = null;
1524+ var relSkew = 0; // server clock minus the browser's, in ms
1525+
1526+ // The wording index, the number and the age at which the wording next changes, for an age in
1527+ // whole seconds. Units are minute, hour, day, month and year, as the server splits them.
1528+ function relWording(secs) {
1529+ var units = [[60, 0], [3600, 1], [86400, 2], [2592000, 3], [31536000, 4]];
1530+ if (secs < 60) { return { idx: 0, n: 0, next: 60 }; }
1531+ var u = 0;
1532+ while (u < 4 && secs >= units[u + 1][0]) { u++; }
1533+ var size = units[u][0];
1534+ var n = Math.floor(secs / size);
1535+ var next = (n + 1) * size;
1536+ if (u < 4 && next > units[u + 1][0]) { next = units[u + 1][0]; }
1537+ return { idx: 1 + 2 * units[u][1] + (n === 1 ? 0 : 1), n: n, next: next };
1538+ }
1539+
1540+ function relUpdate() {
1541+ relTimer = null;
1542+ var words = (document.documentElement.getAttribute('data-rel-words') || '').split('|');
1543+ if (words.length < 11) { return; } // no wording from the server: nothing to re-word
1544+ var nowSec = (Date.now() + relSkew) / 1000;
1545+ var soonest = Infinity;
1546+ Array.prototype.forEach.call(document.querySelectorAll('time[data-rel]'), function (el) {
1547+ var at = Date.parse(el.getAttribute('datetime') || '');
1548+ if (isNaN(at)) { return; }
1549+ var unix = Math.floor(at / 1000);
1550+ var age = nowSec - unix;
1551+ var w = relWording(Math.max(0, Math.floor(age)));
1552+ var label = words[w.idx].replace('{n}', w.n);
1553+ if (el.textContent !== label) { el.textContent = label; }
1554+ soonest = Math.min(soonest, unix + w.next - nowSec);
1555+ });
1556+ if (soonest !== Infinity) {
1557+ relTimer = setTimeout(relUpdate, Math.max(0, Math.ceil(soonest * 1000)) + 50);
1558+ }
1559+ }
1560+
1561+ function syncRel() {
1562+ var now = document.documentElement.getAttribute('data-rel-now');
1563+ relSkew = now === null ? 0 : (parseInt(now, 10) || 0) * 1000 - Date.now();
1564+ if (relTimer) { clearTimeout(relTimer); relTimer = null; }
1565+ relUpdate();
1566+ }
1567+
1517 function fmtDuration(secs, root) {1568 function fmtDuration(secs, root) {
1518 secs = Math.max(0, Math.floor(secs));1569 secs = Math.max(0, Math.floor(secs));
1519 if (secs >= 60) {1570 if (secs >= 60) {
@@ -1581,6 +1632,7 @@
1581 syncLive();1632 syncLive();
1582 syncPush();1633 syncPush();
1583 syncTick();1634 syncTick();
1635+ syncRel();
1584 1636
1585 window.__forgeQuery = function (href) {1637 window.__forgeQuery = function (href) {
1586 var url = pageUrl(href);1638 var url = pageUrl(href);
crates/forge-web/src/pages/admin_runners.rsmodified+5 -2
@@ -143,6 +143,8 @@ struct RunnerRow {
143 last_seen: String,143 last_seen: String,
144 /// The absolute time in the viewer's zone, for the `title` tooltip. Empty when never seen.144 /// The absolute time in the viewer's zone, for the `title` tooltip. Empty when never seen.
145 last_seen_full: String,145 last_seen_full: String,
146+ /// The last-seen stamp, for the `<time>` that shows `last_seen`. Empty when never seen.
147+ last_seen_at: String,
146 disabled: bool,148 disabled: bool,
147 toggle_action: String,149 toggle_action: String,
148 delete_action: String,150 delete_action: String,
@@ -218,6 +220,7 @@ fn runner_row(runner: &CiRunner, tz: &str, lang: Lang, now: i64) -> RunnerRow {
218 labels: runner.labels.clone(),220 labels: runner.labels.clone(),
219 last_seen,221 last_seen,
220 last_seen_full,222 last_seen_full,
223+ last_seen_at: runner.last_seen_at.clone().unwrap_or_default(),
221 disabled: runner.disabled,224 disabled: runner.disabled,
222 toggle_action: format!("/admin/runners/{}/disabled", enc(&runner.id)),225 toggle_action: format!("/admin/runners/{}/disabled", enc(&runner.id)),
223 delete_action: format!("/admin/runners/{}/delete", enc(&runner.id)),226 delete_action: format!("/admin/runners/{}/delete", enc(&runner.id)),
@@ -328,7 +331,7 @@ async fn runners_view(
328 }331 }
329 <span class=(format!("ci-state {}", row.build_class))>(row.build_label)</span>332 <span class=(format!("ci-state {}", row.build_class))>(row.build_label)</span>
330 </td>333 </td>
331- <td class="runner-seen small" data-label=(g::t(lang, K::LastSeen)) title=(row.last_seen_full.as_str())>(row.last_seen.as_str())</td>334+ <td class="runner-seen small" data-label=(g::t(lang, K::LastSeen)) title=(row.last_seen_full.as_str())><time data-rel="true" datetime=(row.last_seen_at.as_str())>(row.last_seen.as_str())</time></td>
332 <td class="runner-state" data-label=(g::t(lang, K::TableState))>335 <td class="runner-state" data-label=(g::t(lang, K::TableState))>
333 if row.disabled {336 if row.disabled {
334 <span class="ci-state runner-disabled">(g::t(lang, K::Disabled))</span>337 <span class="ci-state runner-disabled">(g::t(lang, K::Disabled))</span>
@@ -1124,7 +1127,7 @@ async fn runner_detail_view(
1124 <section class="card">1127 <section class="card">
1125 <div class="srv-grid srv-stats">1128 <div class="srv-grid srv-stats">
1126 <div class="srv-field"><span class="srv-label">(s(lang, "Running jobs", "Çalışan işler"))</span><strong>(in_use.as_str())</strong></div>1129 <div class="srv-field"><span class="srv-label">(s(lang, "Running jobs", "Çalışan işler"))</span><strong>(in_use.as_str())</strong></div>
1127- <div class="srv-field"><span class="srv-label">(g::t(lang, K::LastSeen))</span><strong title=(row.last_seen_full.as_str())>(row.last_seen.as_str())</strong></div>1130+ <div class="srv-field"><span class="srv-label">(g::t(lang, K::LastSeen))</span><strong title=(row.last_seen_full.as_str())><time data-rel="true" datetime=(row.last_seen_at.as_str())>(row.last_seen.as_str())</time></strong></div>
1128 <div class="srv-field"><span class="srv-label">(s(lang, "Build", "Derleme"))</span><strong class="runner-build-stat" title=(row.build.as_str())>(if row.build_short.is_empty() { "-" } else { row.build_short.as_str() })<span class=(format!("ci-state {}", row.build_class))>(row.build_label)</span></strong></div>1131 <div class="srv-field"><span class="srv-label">(s(lang, "Build", "Derleme"))</span><strong class="runner-build-stat" title=(row.build.as_str())>(if row.build_short.is_empty() { "-" } else { row.build_short.as_str() })<span class=(format!("ci-state {}", row.build_class))>(row.build_label)</span></strong></div>
1129 <div class="srv-field"><span class="srv-label">(s(lang, "Runner version", "Çalıştırıcı sürümü"))</span><strong>(version.as_str())</strong></div>1132 <div class="srv-field"><span class="srv-label">(s(lang, "Runner version", "Çalıştırıcı sürümü"))</span><strong>(version.as_str())</strong></div>
1130 <div class="srv-field"><span class="srv-label">(s(lang, "CPUs", "CPU sayısı"))</span><strong>(cpus.as_str())</strong></div>1133 <div class="srv-field"><span class="srv-label">(s(lang, "CPUs", "CPU sayısı"))</span><strong>(cpus.as_str())</strong></div>
crates/forge-web/src/pages/blame.rsmodified+1 -1
@@ -115,7 +115,7 @@ async fn blame_table(rows: Vec<Row>, lang: Lang) -> Result<impl View> {
115 <div class="blame-top">115 <div class="blame-top">
116 <a class="mono" href=(meta.commit_href.as_str())>(meta.short.as_str())</a>116 <a class="mono" href=(meta.commit_href.as_str())>(meta.short.as_str())</a>
117 <span class="blame-author">(meta.author.as_str())</span>117 <span class="blame-author">(meta.author.as_str())</span>
118- <time class="muted" datetime=(meta.iso.as_str())>(meta.age.as_str())</time>118+ <time class="muted" data-rel="true" datetime=(meta.iso.as_str())>(meta.age.as_str())</time>
119 </div>119 </div>
120 <a class="blame-summary" href=(meta.commit_href.as_str()) title=(meta.summary.as_str())>(meta.summary.as_str())</a>120 <a class="blame-summary" href=(meta.commit_href.as_str()) title=(meta.summary.as_str())>(meta.summary.as_str())</a>
121 if let Some(prior) = meta.prior_href {121 if let Some(prior) = meta.prior_href {
crates/forge-web/src/pages/branches.rsmodified+8 -2
@@ -29,7 +29,7 @@ use crate::pages::repo_ctx::{RepoCtx, load_repo};
29 use crate::pages::tree::{LastCommit, last_commit_view};29 use crate::pages::tree::{LastCommit, last_commit_view};
30 use crate::post_update::after_ref_update;30 use crate::post_update::after_ref_update;
31 use crate::state::AppState;31 use crate::state::AppState;
32-use crate::views::{alert, now_unix, relative_time, repo_href, shell};32+use crate::views::{alert, iso_time, now_unix, relative_time, repo_href, shell};
33 33
34 path_param!(owner);34 path_param!(owner);
35 path_param!(repo);35 path_param!(repo);
@@ -90,6 +90,8 @@ struct BranchRow {
90 last: Option<LastCommit>,90 last: Option<LastCommit>,
91 author: String,91 author: String,
92 age: String,92 age: String,
93+ /// The last commit's author time as a stamp, for the `<time>` that shows `age`.
94+ iso: String,
93 /// "3 ahead, 1 behind", or None when not counted.95 /// "3 ahead, 1 behind", or None when not counted.
94 counts: Option<String>,96 counts: Option<String>,
95 up_to_date: bool,97 up_to_date: bool,
@@ -168,7 +170,7 @@ async fn branch_table(
168 }170 }
169 <td class="branch-author">171 <td class="branch-author">
170 <span>(row.author.as_str())</span>172 <span>(row.author.as_str())</span>
171- <span class="muted small">(row.age.as_str())</span>173+ <span class="muted small"><time data-rel="true" datetime=(row.iso.as_str())>(row.age.as_str())</time></span>
172 </td>174 </td>
173 <td class="branch-counts">175 <td class="branch-counts">
174 if let Some(counts) = row.counts {176 if let Some(counts) = row.counts {
@@ -270,6 +272,10 @@ async fn branches_page(cx: &Cx) -> Result<impl View> {
270 .as_ref()272 .as_ref()
271 .map(|c| relative_time(lang, c.author_time, now))273 .map(|c| relative_time(lang, c.author_time, now))
272 .unwrap_or_default(),274 .unwrap_or_default(),
275+ iso: commit
276+ .as_ref()
277+ .map(|c| iso_time(c.author_time))
278+ .unwrap_or_default(),
273 counts,279 counts,
274 up_to_date,280 up_to_date,
275 pr_href,281 pr_href,
crates/forge-web/src/pages/ci_job.rsmodified+2 -2
@@ -312,10 +312,10 @@ async fn job_body(
312 }312 }
313 </p>313 </p>
314 if !job.started.is_empty() {314 if !job.started.is_empty() {
315- <p class="muted small">(g::t(lang, K::Started)) " " <time datetime=(job.started_full.as_str()) title=(full_date(job.started_full.as_str()))>(job.started.as_str())</time></p>315+ <p class="muted small">(g::t(lang, K::Started)) " " <time datetime=(job.started_full.as_str()) data-rel="true" title=(full_date(job.started_full.as_str()))>(job.started.as_str())</time></p>
316 }316 }
317 if !job.finished.is_empty() {317 if !job.finished.is_empty() {
318- <p class="muted small">(g::t(lang, K::Finished)) " " <time datetime=(job.finished_full.as_str()) title=(full_date(job.finished_full.as_str()))>(job.finished.as_str())</time></p>318+ <p class="muted small">(g::t(lang, K::Finished)) " " <time datetime=(job.finished_full.as_str()) data-rel="true" title=(full_date(job.finished_full.as_str()))>(job.finished.as_str())</time></p>
319 }319 }
320 if !job.duration.is_empty() {320 if !job.duration.is_empty() {
321 <p class="muted small">(g::t(lang, K::Duration)) " " (job.duration.as_str())</p>321 <p class="muted small">(g::t(lang, K::Duration)) " " (job.duration.as_str())</p>
crates/forge-web/src/pages/ci_runs.rsmodified+31 -13
@@ -4,7 +4,7 @@
4 //! error of a run. Starting a manual run, cancelling, re-running and approving need Write, and the4 //! error of a run. Starting a manual run, cancelling, re-running and approving need Write, and the
5 //! buttons are shown only to writers. Anyone else gets a 404 for a private repo and a refusal for a5 //! buttons are shown only to writers. Anyone else gets a 404 for a private repo and a refusal for a
6 //! change. Every change notifies the job waker and syncs the commit status of each job it changed. A run6 //! change. Every change notifies the job waker and syncs the commit status of each job it changed. A run
7-//! or job page that is not finished stays live. The split view is live on page 1 of the list through7+//! or job page that is not finished stays live. The split view is live on every page of the list through
8 //! `/{owner}/{repo}/ci/events`, which fires on every run created or changed in the repo, and a run or job8 //! `/{owner}/{repo}/ci/events`, which fires on every run created or changed in the repo, and a run or job
9 //! page opens its own `changed` stream (`.../events`) when it is not finished.9 //! page opens its own `changed` stream (`.../events`) when it is not finished.
10 10
@@ -340,7 +340,7 @@ struct RunRow {
340 /// The run's start and the list's scale, which the ticker needs to grow the running segments.340 /// The run's start and the list's scale, which the ticker needs to grow the running segments.
341 origin: String,341 origin: String,
342 scale: String,342 scale: String,
343- meta: String,343+ meta: RowMeta,
344 }344 }
345 345
346 /// The run-list form that starts a manual run.346 /// The run-list form that starts a manual run.
@@ -418,7 +418,9 @@ struct RunDetail {
418 commit_href: String,418 commit_href: String,
419 commit: String,419 commit: String,
420 actor: String,420 actor: String,
421+ /// The run's creation as an age, and its stamp for the `<time>` that carries it.
421 when: String,422 when: String,
423+ when_at: String,
422 duration: String,424 duration: String,
423 /// Unix seconds the header duration counts from while the run is not finished.425 /// Unix seconds the header duration counts from while the run is not finished.
424 since: Option<String>,426 since: Option<String>,
@@ -1116,24 +1118,39 @@ fn timing_of(job: &CiJob, runner: String, lang: Lang) -> Timing {
1116 }1118 }
1117 1119
1118 /// "test OOM" for a failed run: the first failed job's message, or its name and state.1120 /// "test OOM" for a failed run: the first failed job's message, or its name and state.
1119-fn row_meta(run: &CiRun, jobs: &[Timing], actor: &str, lang: Lang) -> String {1121+/// One row's meta line: `#50 · e62e309 · tahinli · ` then the age, then the failure hint if any.
1120- let mut meta = format!("#{} \u{b7} {}", run.number, short_oid(&run.commit_oid));1122+struct RowMeta {
1123+ head: String,
1124+ at: String,
1125+ age: String,
1126+ hint: String,
1127+}
1128+
1129+/// The meta line of a run row. The hint is "test OOM" for a failed run: the first failed job's
1130+/// message, or its name and state.
1131+fn row_meta(run: &CiRun, jobs: &[Timing], actor: &str, lang: Lang) -> RowMeta {
1132+ let mut head = format!("#{} \u{b7} {}", run.number, short_oid(&run.commit_oid));
1121 if !actor.is_empty() {1133 if !actor.is_empty() {
1122- meta.push_str(&format!(" \u{b7} {actor}"));1134+ head.push_str(&format!(" \u{b7} {actor}"));
1123 }1135 }
1124- meta.push_str(&format!(" \u{b7} {}", age_text(lang, &run.created_at)));1136+ let mut hint = String::new();
1125 if let Some(job) = jobs1137 if let Some(job) = jobs
1126 .iter()1138 .iter()
1127 .find(|job| matches!(job.state, JobState::Failure | JobState::Error))1139 .find(|job| matches!(job.state, JobState::Failure | JobState::Error))
1128 {1140 {
1129- let hint = if job.message.is_empty() {1141+ let text = if job.message.is_empty() {
1130 format!("{} {}", job.name, state_text(lang, job.state.as_str()))1142 format!("{} {}", job.name, state_text(lang, job.state.as_str()))
1131 } else {1143 } else {
1132 job.message.clone()1144 job.message.clone()
1133 };1145 };
1134- meta.push_str(&format!(" \u{b7} {hint}"));1146+ hint = format!(" \u{b7} {text}");
1147+ }
1148+ RowMeta {
1149+ head: format!("{head} \u{b7} "),
1150+ at: run.created_at.clone(),
1151+ age: age_text(lang, &run.created_at),
1152+ hint,
1135 }1153 }
1136- meta
1137 }1154 }
1138 1155
1139 /// Drops the ANSI escape sequences and the other control characters (a tab stays) of a log line.1156 /// Drops the ANSI escape sequences and the other control characters (a tab stays) of a log line.
@@ -1251,7 +1268,7 @@ struct SplitPage {
1251 1268
1252 /// The split view of the runs: the list (left) and the selected run (right). Both routes render it.1269 /// The split view of the runs: the list (left) and the selected run (right). Both routes render it.
1253 /// `number` is the run the URL names. Without one, the newest run of the list page is selected.1270 /// `number` is the run the URL names. Without one, the newest run of the list page is selected.
1254-/// The list is live on page 1 only, since a new run can appear there at any time.1271+/// The list is live on every page: a run's state, its hint and its age change on any page of it.
1255 async fn runs_split(cx: &Cx, number: Option<&str>) -> Result<SplitPage> {1272 async fn runs_split(cx: &Cx, number: Option<&str>) -> Result<SplitPage> {
1256 let owner = path_param::<Owner>(cx);1273 let owner = path_param::<Owner>(cx);
1257 let name = path_param::<Repo>(cx);1274 let name = path_param::<Repo>(cx);
@@ -1425,7 +1442,7 @@ async fn runs_split(cx: &Cx, number: Option<&str>) -> Result<SplitPage> {
1425 forge_ci::cron::next_after(&schedules, now).and_then(next_run_text)1442 forge_ci::cron::next_after(&schedules, now).and_then(next_run_text)
1426 },1443 },
1427 };1444 };
1428- let live = (page == 1).then(|| format!("{base}/events"));1445+ let live = Some(format!("{base}/events"));
1429 let notice = notice_from_query(cx, lang);1446 let notice = notice_from_query(cx, lang);
1430 let head = ctx.head(state, "ci").await?;1447 let head = ctx.head(state, "ci").await?;
1431 let page_title = match detail.as_ref() {1448 let page_title = match detail.as_ref() {
@@ -1544,6 +1561,7 @@ async fn run_detail(
1544 commit: short_oid(&run.commit_oid).to_owned(),1561 commit: short_oid(&run.commit_oid).to_owned(),
1545 actor: header.actor,1562 actor: header.actor,
1546 when: age_text(lang, &run.created_at),1563 when: age_text(lang, &run.created_at),
1564+ when_at: run.created_at.clone(),
1547 duration: duration_text(1565 duration: duration_text(
1548 lang,1566 lang,
1549 Some(run.created_at.as_str()),1567 Some(run.created_at.as_str()),
@@ -1666,7 +1684,7 @@ async fn runs_body(
1666 </svg>1684 </svg>
1667 <span class="ci-row-dur" data-since=(row.since.as_deref())>(row.duration.as_str())</span>1685 <span class="ci-row-dur" data-since=(row.since.as_deref())>(row.duration.as_str())</span>
1668 </span>1686 </span>
1669- <span class="ci-row-meta">(row.meta.as_str())</span>1687+ <span class="ci-row-meta">(row.meta.head.as_str())<time datetime=(row.meta.at.as_str()) data-rel="true">(row.meta.age.as_str())</time>(row.meta.hint.as_str())</span>
1670 </a>1688 </a>
1671 </li>1689 </li>
1672 }1690 }
@@ -1709,7 +1727,7 @@ async fn runs_body(
1709 if !run.actor.is_empty() {1727 if !run.actor.is_empty() {
1710 " \u{b7} " (run.actor.as_str())1728 " \u{b7} " (run.actor.as_str())
1711 }1729 }
1712- " \u{b7} " (run.when.as_str())1730+ " \u{b7} " <time datetime=(run.when_at.as_str()) data-rel="true">(run.when.as_str())</time>
1713 if !run.duration.is_empty() {1731 if !run.duration.is_empty() {
1714 " \u{b7} " <span data-since=(run.since.as_deref())>(run.duration.as_str())</span>1732 " \u{b7} " <span data-since=(run.since.as_deref())>(run.duration.as_str())</span>
1715 }1733 }
crates/forge-web/src/pages/ci_tests.rsmodified+3 -3
@@ -339,7 +339,7 @@ async fn run_list_pages_and_its_live_marker() {
339 Some(&cookie_for("tahinli-token")),339 Some(&cookie_for("tahinli-token")),
340 )340 )
341 .await;341 .await;
342- assert!(!second.text().contains("data-live="), "page 2 is not live");342+ assert!(second.text().contains("data-live="), "page 2 is live too");
343 let run = get(343 let run = get(
344 &fx.app,344 &fx.app,
345 &format!("{RUN_BASE}/runs/30?page=2"),345 &format!("{RUN_BASE}/runs/30?page=2"),
@@ -347,8 +347,8 @@ async fn run_list_pages_and_its_live_marker() {
347 )347 )
348 .await;348 .await;
349 assert!(349 assert!(
350- !run.text().contains("data-live="),350+ run.text().contains("data-live="),
351- "a run on page 2 is not live"351+ "a run on page 2 is live too"
352 );352 );
353 }353 }
354 }354 }
crates/forge-web/src/pages/commit.rsmodified+2 -2
@@ -193,9 +193,9 @@ async fn commit_page(cx: &Cx) -> Result<impl View> {
193 if let Some(summary) = checks {193 if let Some(summary) = checks {
194 checks_summary(summary: summary, lang: StatusLang(lang))194 checks_summary(summary: summary, lang: StatusLang(lang))
195 }195 }
196- <p class="muted">(g::t(lang, K::AuthorLabel)) <strong>(author.name.as_str())</strong> " · " <time datetime=(author.iso.as_str()) title=(author.absolute.as_str())>(author.relative.as_str())</time></p>196+ <p class="muted">(g::t(lang, K::AuthorLabel)) <strong>(author.name.as_str())</strong> " · " <time data-rel="true" datetime=(author.iso.as_str()) title=(author.absolute.as_str())>(author.relative.as_str())</time></p>
197 if committer_differs {197 if committer_differs {
198- <p class="muted">(g::t(lang, K::CommitterLabel)) <strong>(committer.name.as_str())</strong> " · " <time datetime=(committer.iso.as_str()) title=(committer.absolute.as_str())>(committer.relative.as_str())</time></p>198+ <p class="muted">(g::t(lang, K::CommitterLabel)) <strong>(committer.name.as_str())</strong> " · " <time data-rel="true" datetime=(committer.iso.as_str()) title=(committer.absolute.as_str())>(committer.relative.as_str())</time></p>
199 }199 }
200 if is_root {200 if is_root {
201 <p class="muted">(g::t(lang, K::RootCommit))</p>201 <p class="muted">(g::t(lang, K::RootCommit))</p>
crates/forge-web/src/pages/commits.rsmodified+2 -2
@@ -296,11 +296,11 @@ async fn commits_page(cx: &Cx) -> Result<impl View> {
296 <div class="commit-meta muted small">296 <div class="commit-meta muted small">
297 <span class="commit-author">(row.author.as_str())</span>297 <span class="commit-author">(row.author.as_str())</span>
298 if lang == Lang::Tr {298 if lang == Lang::Tr {
299- <time datetime=(row.iso.as_str()) title=(row.absolute.as_str())>(row.relative.as_str())</time>299+ <time data-rel="true" datetime=(row.iso.as_str()) title=(row.absolute.as_str())>(row.relative.as_str())</time>
300 <span>(g::t(lang, K::Committed))</span>300 <span>(g::t(lang, K::Committed))</span>
301 } else {301 } else {
302 <span>(g::t(lang, K::Committed))</span>302 <span>(g::t(lang, K::Committed))</span>
303- <time datetime=(row.iso.as_str()) title=(row.absolute.as_str())>(row.relative.as_str())</time>303+ <time data-rel="true" datetime=(row.iso.as_str()) title=(row.absolute.as_str())>(row.relative.as_str())</time>
304 }304 }
305 </div>305 </div>
306 </div>306 </div>
crates/forge-web/src/pages/compare.rsmodified+2 -2
@@ -349,11 +349,11 @@ async fn compare_view(
349 <div class="commit-meta muted small">349 <div class="commit-meta muted small">
350 <span class="commit-author">(row.author.as_str())</span>350 <span class="commit-author">(row.author.as_str())</span>
351 if lang == i18n::Lang::Tr {351 if lang == i18n::Lang::Tr {
352- <time datetime=(row.iso.as_str()) title=(row.absolute.as_str())>(row.relative.as_str())</time>352+ <time data-rel="true" datetime=(row.iso.as_str()) title=(row.absolute.as_str())>(row.relative.as_str())</time>
353 <span>(g::t(lang, K::Committed))</span>353 <span>(g::t(lang, K::Committed))</span>
354 } else {354 } else {
355 <span>(g::t(lang, K::Committed))</span>355 <span>(g::t(lang, K::Committed))</span>
356- <time datetime=(row.iso.as_str()) title=(row.absolute.as_str())>(row.relative.as_str())</time>356+ <time data-rel="true" datetime=(row.iso.as_str()) title=(row.absolute.as_str())>(row.relative.as_str())</time>
357 }357 }
358 </div>358 </div>
359 </div>359 </div>
crates/forge-web/src/pages/dashboard.rsmodified+4 -1
@@ -45,6 +45,8 @@ struct AttentionRow {
45 reference: String,45 reference: String,
46 title: String,46 title: String,
47 kind: &'static str,47 kind: &'static str,
48+ /// The item's update stamp, for the `<time>` that shows `relative`.
49+ updated: String,
48 relative: String,50 relative: String,
49 }51 }
50 52
@@ -228,7 +230,7 @@ async fn dashboard(dash: Dashboard, lang: Lang) -> Result<impl View> {
228 for item in dash.attention.into_iter() {230 for item in dash.attention.into_iter() {
229 <li>231 <li>
230 <a href=(item.href.as_str())><span class="mono">(item.reference.as_str())</span>" "(item.title.as_str())</a>232 <a href=(item.href.as_str())><span class="mono">(item.reference.as_str())</span>" "(item.title.as_str())</a>
231- <span class="sub">(item.kind) " · " (item.relative.as_str())</span>233+ <span class="sub">(item.kind) " · " <time data-rel="true" datetime=(item.updated.as_str())>(item.relative.as_str())</time></span>
232 </li>234 </li>
233 }235 }
234 </ul>236 </ul>
@@ -253,6 +255,7 @@ fn attention_row(lang: Lang, note: &Notification, now: i64) -> AttentionRow {
253 reference: format!("{}/{} #{}", note.repo_owner, note.repo_name, note.number),255 reference: format!("{}/{} #{}", note.repo_owner, note.repo_name, note.number),
254 title: note.title.clone(),256 title: note.title.clone(),
255 kind,257 kind,
258+ updated: note.updated_at.clone(),
256 relative: relative_time(lang, stamp_unix(&note.updated_at), now),259 relative: relative_time(lang, stamp_unix(&note.updated_at), now),
257 }260 }
258 }261 }
crates/forge-web/src/pages/discussion_view.rsmodified+2 -2
@@ -186,7 +186,7 @@ async fn comment_article(item: CommentView) -> Result<impl View> {
186 } else {186 } else {
187 <a href=(profile.as_str())><img class="avatar avatar-sm" src=(avatar.as_str()) alt="" width="24" height="24"></a>187 <a href=(profile.as_str())><img class="avatar avatar-sm" src=(avatar.as_str()) alt="" width="24" height="24"></a>
188 <strong>user_link(shown: author.as_str(), login: login.as_str())</strong>188 <strong>user_link(shown: author.as_str(), login: login.as_str())</strong>
189- <time datetime=(when.iso.as_str()) title=(when.absolute.as_str())>(when.relative.as_str())</time>189+ <time data-rel="true" datetime=(when.iso.as_str()) title=(when.absolute.as_str())>(when.relative.as_str())</time>
190 }190 }
191 if accepted {191 if accepted {
192 <span class="issue-badge issue-badge-completed">(g::t(lang, K::Answer))</span>192 <span class="issue-badge issue-badge-completed">(g::t(lang, K::Answer))</span>
@@ -415,7 +415,7 @@ async fn discussion_page(
415 }415 }
416 " " <strong>user_link(shown: author.as_str(), login: author_login.as_str())</strong>416 " " <strong>user_link(shown: author.as_str(), login: author_login.as_str())</strong>
417 (g::t(lang, K::OpenedThis))417 (g::t(lang, K::OpenedThis))
418- <time datetime=(opened.iso.as_str()) title=(opened.absolute.as_str())>(opened.relative.as_str())</time>418+ <time data-rel="true" datetime=(opened.iso.as_str()) title=(opened.absolute.as_str())>(opened.relative.as_str())</time>
419 (g::t(lang, K::OpenedSeparator))419 (g::t(lang, K::OpenedSeparator))
420 (comments_label.as_str())420 (comments_label.as_str())
421 </p>421 </p>
crates/forge-web/src/pages/discussions.rsmodified+1 -1
@@ -331,7 +331,7 @@ async fn discussions_list_page(cx: &Cx) -> Result<impl View> {
331 <span>(by_before)</span>331 <span>(by_before)</span>
332 <span>user_link(shown: row.author.as_str(), login: row.author.as_str())</span>332 <span>user_link(shown: row.author.as_str(), login: row.author.as_str())</span>
333 <span>(by_middle)</span>333 <span>(by_middle)</span>
334- <time datetime=(row.iso.as_str()) title=(row.absolute.as_str())>(row.relative.as_str())</time>334+ <time data-rel="true" datetime=(row.iso.as_str()) title=(row.absolute.as_str())>(row.relative.as_str())</time>
335 if !by_after.is_empty() {335 if !by_after.is_empty() {
336 <span>(by_after)</span>336 <span>(by_after)</span>
337 }337 }
crates/forge-web/src/pages/edit_history.rsmodified+1 -1
@@ -270,7 +270,7 @@ async fn history_entry(lang: Lang, entry: HistoryEntry) -> Result<impl View> {
270 <header class="issue-item-head">270 <header class="issue-item-head">
271 <strong>(editor.as_str())</strong>271 <strong>(editor.as_str())</strong>
272 (g::t(lang, K::EditedBy))272 (g::t(lang, K::EditedBy))
273- <time datetime=(when.iso.as_str()) title=(when.absolute.as_str())>(when.relative.as_str())</time>273+ <time data-rel="true" datetime=(when.iso.as_str()) title=(when.absolute.as_str())>(when.relative.as_str())</time>
274 (g::edited_after(lang))274 (g::edited_after(lang))
275 </header>275 </header>
276 if let Some(text) = title_text {276 if let Some(text) = title_text {
crates/forge-web/src/pages/import.rsmodified+1 -1
@@ -965,7 +965,7 @@ async fn jobs_list(lang: Lang, jobs: Vec<(ImportJob, Option<Repo>)>) -> Result<i
965 <li class="item import-job-row">965 <li class="item import-job-row">
966 <div class="item-main">966 <div class="item-main">
967 <a href=(format!("/import/{}", job.id)) class="import-job-name">(job.source_ref.as_str())</a>967 <a href=(format!("/import/{}", job.id)) class="import-job-name">(job.source_ref.as_str())</a>
968- <span class="muted small">(g::t(lang, K::JobStarted)) " " (ago(lang, &job.created_at))</span>968+ <span class="muted small">(g::t(lang, K::JobStarted)) " " <time data-rel="true" datetime=(job.created_at.as_str())>(ago(lang, &job.created_at))</time></span>
969 </div>969 </div>
970 if let Some(repo) = repo {970 if let Some(repo) = repo {
971 <a href=(format!("/{}/{}", repo.owner_name, repo.name)) class="muted small mono">(format!("{}/{}", repo.owner_name, repo.name))</a>971 <a href=(format!("/{}/{}", repo.owner_name, repo.name)) class="muted small mono">(format!("{}/{}", repo.owner_name, repo.name))</a>
crates/forge-web/src/pages/issue_parts.rsmodified+3 -3
@@ -426,7 +426,7 @@ pub(crate) async fn comment_item(lang: Lang, item: CommentView) -> Result<impl V
426 <header class="issue-item-head">426 <header class="issue-item-head">
427 <a href=(profile.as_str())><img class="avatar avatar-sm" src=(avatar.as_str()) alt="" width="24" height="24"></a>427 <a href=(profile.as_str())><img class="avatar avatar-sm" src=(avatar.as_str()) alt="" width="24" height="24"></a>
428 <strong>user_link(shown: author.as_str(), login: login.as_str())</strong>428 <strong>user_link(shown: author.as_str(), login: login.as_str())</strong>
429- <time datetime=(when.iso.as_str()) title=(when.absolute.as_str())>(when.relative.as_str())</time>429+ <time data-rel="true" datetime=(when.iso.as_str()) title=(when.absolute.as_str())>(when.relative.as_str())</time>
430 if let Some(href) = history_href {430 if let Some(href) = history_href {
431 <a class="issue-edited" href=(href.as_str())>(g::t(lang, K::Edited))</a>431 <a class="issue-edited" href=(href.as_str())>(g::t(lang, K::Edited))</a>
432 }432 }
@@ -553,7 +553,7 @@ pub(crate) async fn event_item(line: EventLine) -> Result<impl View> {
553 (after.as_str())553 (after.as_str())
554 }554 }
555 " "555 " "
556- <time datetime=(when.iso.as_str()) title=(when.absolute.as_str())>(when.relative.as_str())</time>556+ <time data-rel="true" datetime=(when.iso.as_str()) title=(when.absolute.as_str())>(when.relative.as_str())</time>
557 </div>557 </div>
558 })558 })
559 }559 }
@@ -596,7 +596,7 @@ pub(crate) async fn review_item(lang: Lang, review: ReviewView) -> Result<impl V
596 <a href=(profile.as_str())><img class="avatar avatar-sm" src=(avatar.as_str()) alt="" width="24" height="24"></a>596 <a href=(profile.as_str())><img class="avatar avatar-sm" src=(avatar.as_str()) alt="" width="24" height="24"></a>
597 <strong>user_link(shown: author.as_str(), login: login.as_str())</strong>597 <strong>user_link(shown: author.as_str(), login: login.as_str())</strong>
598 <span class=(verb_class)>(verb)</span>598 <span class=(verb_class)>(verb)</span>
599- <time datetime=(when.iso.as_str()) title=(when.absolute.as_str())>(when.relative.as_str())</time>599+ <time data-rel="true" datetime=(when.iso.as_str()) title=(when.absolute.as_str())>(when.relative.as_str())</time>
600 </header>600 </header>
601 if dismissed {601 if dismissed {
602 <p class="review-dismissed">(g::t(lang, K::DismissedPrefix)) (dismissed_reason.as_str())</p>602 <p class="review-dismissed">(g::t(lang, K::DismissedPrefix)) (dismissed_reason.as_str())</p>
crates/forge-web/src/pages/issue_view.rsmodified+1 -1
@@ -99,7 +99,7 @@ async fn issue_page(
99 <span class=(state_class)>(state_text)</span>99 <span class=(state_class)>(state_text)</span>
100 <strong>user_link(shown: author.as_str(), login: author_login.as_str())</strong>100 <strong>user_link(shown: author.as_str(), login: author_login.as_str())</strong>
101 (g::t(lang, K::OpenedThis))101 (g::t(lang, K::OpenedThis))
102- <time datetime=(opened.iso.as_str()) title=(opened.absolute.as_str())>(opened.relative.as_str())</time>102+ <time data-rel="true" datetime=(opened.iso.as_str()) title=(opened.absolute.as_str())>(opened.relative.as_str())</time>
103 (g::opened_after(lang))103 (g::opened_after(lang))
104 " · "104 " · "
105 (comments_label.as_str())105 (comments_label.as_str())
crates/forge-web/src/pages/issues_list.rsmodified+2 -2
@@ -561,11 +561,11 @@ async fn issues_list_page(cx: &Cx) -> Result<impl View> {
561 if lang == Lang::Tr {561 if lang == Lang::Tr {
562 <span>user_link(shown: row.author.as_str(), login: row.author.as_str())</span>562 <span>user_link(shown: row.author.as_str(), login: row.author.as_str())</span>
563 <span>(g::t(lang, K::By))</span>563 <span>(g::t(lang, K::By))</span>
564- <time datetime=(row.iso.as_str()) title=(row.absolute.as_str())>(row.relative.as_str())</time>564+ <time data-rel="true" datetime=(row.iso.as_str()) title=(row.absolute.as_str())>(row.relative.as_str())</time>
565 <span>(g::t(lang, K::Opened))</span>565 <span>(g::t(lang, K::Opened))</span>
566 } else {566 } else {
567 <span>(g::t(lang, K::Opened))</span>567 <span>(g::t(lang, K::Opened))</span>
568- <time datetime=(row.iso.as_str()) title=(row.absolute.as_str())>(row.relative.as_str())</time>568+ <time data-rel="true" datetime=(row.iso.as_str()) title=(row.absolute.as_str())>(row.relative.as_str())</time>
569 <span>(g::t(lang, K::By))</span>569 <span>(g::t(lang, K::By))</span>
570 <span>user_link(shown: row.author.as_str(), login: row.author.as_str())</span>570 <span>user_link(shown: row.author.as_str(), login: row.author.as_str())</span>
571 }571 }
crates/forge-web/src/pages/notifications.rsmodified+1 -1
@@ -1009,7 +1009,7 @@ async fn inbox_list(
1009 <a class="notif-title" href=(row.open_href.as_str())>(row.title_line.as_str())</a>1009 <a class="notif-title" href=(row.open_href.as_str())>(row.title_line.as_str())</a>
1010 <span class="badge">(row.reason)</span>1010 <span class="badge">(row.reason)</span>
1011 <span class="muted small">(row.activity.as_str())</span>1011 <span class="muted small">(row.activity.as_str())</span>
1012- <time class="muted small" datetime=(row.iso.as_str()) title=(row.absolute.as_str())>(row.relative.as_str())</time>1012+ <time class="muted small" data-rel="true" datetime=(row.iso.as_str()) title=(row.absolute.as_str())>(row.relative.as_str())</time>
1013 if row.unread {1013 if row.unread {
1014 <form method="post" action=(row.read_action.as_str()) class="notif-inline-form">1014 <form method="post" action=(row.read_action.as_str()) class="notif-inline-form">
1015 csrf_field(token: csrf.as_str())1015 csrf_field(token: csrf.as_str())
crates/forge-web/src/pages/pull_view.rsmodified+3 -3
@@ -233,7 +233,7 @@ pub(crate) async fn pull_header(frame: Frame) -> Result<impl View> {
233 <code>(head_label.as_str())</code>233 <code>(head_label.as_str())</code>
234 }234 }
235 (byline_end)235 (byline_end)
236- <time datetime=(opened.iso.as_str()) title=(opened.absolute.as_str())>(opened.relative.as_str())</time>236+ <time data-rel="true" datetime=(opened.iso.as_str()) title=(opened.absolute.as_str())>(opened.relative.as_str())</time>
237 </p>237 </p>
238 </section>238 </section>
239 })239 })
@@ -467,7 +467,7 @@ async fn merged_notice(
467 <section class="merge-box merge-merged">467 <section class="merge-box merge-merged">
468 <p class="merge-headline">468 <p class="merge-headline">
469 (prefix) <strong>user_link(shown: who.as_str(), login: who.as_str())</strong> (middle)469 (prefix) <strong>user_link(shown: who.as_str(), login: who.as_str())</strong> (middle)
470- <time datetime=(when.iso.as_str()) title=(when.absolute.as_str())>(when.relative.as_str())</time>470+ <time data-rel="true" datetime=(when.iso.as_str()) title=(when.absolute.as_str())>(when.relative.as_str())</time>
471 if !commit.is_empty() {471 if !commit.is_empty() {
472 (as_sep)472 (as_sep)
473 <a class="mono" href=(commit_href.as_str())>(short.as_str())</a>473 <a class="mono" href=(commit_href.as_str())>(short.as_str())</a>
@@ -570,7 +570,7 @@ async fn commit_list(rows: Vec<CommitRow>, lang: Lang) -> Result<impl View> {
570 <div class="commit-meta muted small">570 <div class="commit-meta muted small">
571 <span class="commit-author">(row.author.as_str())</span>571 <span class="commit-author">(row.author.as_str())</span>
572 <span>(committed)</span>572 <span>(committed)</span>
573- <time datetime=(row.iso.as_str()) title=(row.absolute.as_str())>(row.relative.as_str())</time>573+ <time data-rel="true" datetime=(row.iso.as_str()) title=(row.absolute.as_str())>(row.relative.as_str())</time>
574 </div>574 </div>
575 </div>575 </div>
576 <div class="commit-actions">576 <div class="commit-actions">
crates/forge-web/src/pages/pulls_list.rsmodified+2 -2
@@ -323,10 +323,10 @@ async fn pulls_list_page(cx: &Cx) -> Result<impl View> {
323 <span>(g::t(lang, K::MetaBeforeTime))</span>323 <span>(g::t(lang, K::MetaBeforeTime))</span>
324 <span>user_link(shown: row.author.as_str(), login: row.author.as_str())</span>324 <span>user_link(shown: row.author.as_str(), login: row.author.as_str())</span>
325 <span>(g::t(lang, K::MetaAfterTime))</span>325 <span>(g::t(lang, K::MetaAfterTime))</span>
326- <time datetime=(row.iso.as_str()) title=(row.absolute.as_str())>(row.relative.as_str())</time>326+ <time data-rel="true" datetime=(row.iso.as_str()) title=(row.absolute.as_str())>(row.relative.as_str())</time>
327 } else {327 } else {
328 <span>(g::t(lang, K::MetaBeforeTime))</span>328 <span>(g::t(lang, K::MetaBeforeTime))</span>
329- <time datetime=(row.iso.as_str()) title=(row.absolute.as_str())>(row.relative.as_str())</time>329+ <time data-rel="true" datetime=(row.iso.as_str()) title=(row.absolute.as_str())>(row.relative.as_str())</time>
330 <span>(g::t(lang, K::MetaAfterTime))</span>330 <span>(g::t(lang, K::MetaAfterTime))</span>
331 <span>user_link(shown: row.author.as_str(), login: row.author.as_str())</span>331 <span>user_link(shown: row.author.as_str(), login: row.author.as_str())</span>
332 }332 }
crates/forge-web/src/pages/repo.rsmodified+6 -2
@@ -283,6 +283,8 @@ const RECENT_PUSH_WINDOW: Duration = Duration::from_secs(60 * 60);
283 struct PushBanner {283 struct PushBanner {
284 branch: String,284 branch: String,
285 at_unix: i64,285 at_unix: i64,
286+ /// The push's stamp, for the `<time>` that shows its age.
287+ at: String,
286 href: String,288 href: String,
287 }289 }
288 290
@@ -378,6 +380,7 @@ async fn recent_push_banners(
378 banners.push(PushBanner {380 banners.push(PushBanner {
379 branch,381 branch,
380 at_unix: stamp_unix(&at),382 at_unix: stamp_unix(&at),
383+ at: at.clone(),
381 href,384 href,
382 });385 });
383 }386 }
@@ -393,7 +396,7 @@ async fn recent_pushes(banners: Vec<PushBanner>, now: i64, lang: Lang) -> Result
393 <p class="recent-push">396 <p class="recent-push">
394 <code>(banner.branch)</code>397 <code>(banner.branch)</code>
395 (g::t(lang, K::HadRecentPushes))398 (g::t(lang, K::HadRecentPushes))
396- (relative_time(lang, banner.at_unix, now))399+ <time data-rel="true" datetime=(banner.at.as_str())>(relative_time(lang, banner.at_unix, now))</time>
397 ". "400 ". "
398 <a href=(banner.href)>(g::t(lang, K::CompareAndPr))</a>401 <a href=(banner.href)>(g::t(lang, K::CompareAndPr))</a>
399 </p>402 </p>
@@ -813,7 +816,8 @@ mod tests {
813 816
814 let (status, body) = get_as(&router, "/tahinli/demo", Some(&cookie)).await;817 let (status, body) = get_as(&router, "/tahinli/demo", Some(&cookie)).await;
815 assert_eq!(status, 200);818 assert_eq!(status, 200);
816- assert!(body.contains("had recent pushes 5 minutes ago"), "{body}");819+ assert!(body.contains("had recent pushes"), "{body}");
820+ assert!(body.contains("5 minutes ago</time>"), "{body}");
817 assert!(body.contains("compare/main...feature"), "{body}");821 assert!(body.contains("compare/main...feature"), "{body}");
818 assert!(body.contains("Compare &amp; pull request"), "{body}");822 assert!(body.contains("Compare &amp; pull request"), "{body}");
819 }823 }
crates/forge-web/src/pages/settings_export.rsmodified+1 -1
@@ -92,7 +92,7 @@ async fn export_view(lang: Lang, csrf: &str, exports: Vec<DataExport>) -> Result
92 for export in exports.iter() {92 for export in exports.iter() {
93 <li class="item export-row">93 <li class="item export-row">
94 <div class="item-main">94 <div class="item-main">
95- <strong>(g::t(lang, K::ExportRequested)) " " (ago(lang, &export.created_at))</strong>95+ <strong>(g::t(lang, K::ExportRequested)) " " <time data-rel="true" datetime=(export.created_at.as_str())>(ago(lang, &export.created_at))</time></strong>
96 if export.state == ExportState::Ready {96 if export.state == ExportState::Ready {
97 <span class="muted small">97 <span class="muted small">
98 (g::t(lang, K::ExportSize)) ": " (human_size(lang, u64::try_from(export.size).unwrap_or(0)))98 (g::t(lang, K::ExportSize)) ": " (human_size(lang, u64::try_from(export.size).unwrap_or(0)))
crates/forge-web/src/pages/tree.rsmodified+2 -2
@@ -422,7 +422,7 @@ pub async fn latest_commit_bar(bar: LatestBar, lang: Lang) -> Result<impl View>
422 <a class="latest-subject" href=(last.href.as_str())>(last.summary)</a>422 <a class="latest-subject" href=(last.href.as_str())>(last.summary)</a>
423 <span class="latest-meta">423 <span class="latest-meta">
424 <a class="mono latest-sha" href=(last.href.as_str())>(short)</a>424 <a class="mono latest-sha" href=(last.href.as_str())>(short)</a>
425- <time class="latest-age" datetime=(last.iso.as_str()) title=(last.absolute.as_str())>(last.age)</time>425+ <time class="latest-age" data-rel="true" datetime=(last.iso.as_str()) title=(last.absolute.as_str())>(last.age)</time>
426 <a class="latest-count" href=(commits_href.as_str())>426 <a class="latest-count" href=(commits_href.as_str())>
427 <svg class="ico" viewBox="0 0 24 24" aria-hidden="true"><path d="M3 12a9 9 0 1 0 3-6.7L3 8"/><path d="M3 3v5h5"/><path d="M12 7v5l3 2"/></svg>427 <svg class="ico" viewBox="0 0 24 24" aria-hidden="true"><path d="M3 12a9 9 0 1 0 3-6.7L3 8"/><path d="M3 3v5h5"/><path d="M12 7v5l3 2"/></svg>
428 (commits_label)428 (commits_label)
@@ -476,7 +476,7 @@ pub async fn tree_table(
476 if let Some(last) = row.last {476 if let Some(last) = row.last {
477 <td class="tree-commit"><a href=(last.href)>(last.summary)</a></td>477 <td class="tree-commit"><a href=(last.href)>(last.summary)</a></td>
478 <td class="age">478 <td class="age">
479- <time datetime=(last.iso.clone()) title=(last.absolute)>(last.age)</time>479+ <time data-rel="true" datetime=(last.iso.clone()) title=(last.absolute)>(last.age)</time>
480 </td>480 </td>
481 } else {481 } else {
482 <td class="tree-commit"></td>482 <td class="tree-commit"></td>
crates/forge-web/src/views/mod.rsmodified+31 -1
@@ -193,6 +193,9 @@ pub async fn shell(
193 }193 }
194 let section_menu = section.clone();194 let section_menu = section.clone();
195 let theme_attr = crate::theme::data_theme(__cx, viewer.map(|(user, _)| user));195 let theme_attr = crate::theme::data_theme(__cx, viewer.map(|(user, _)| user));
196+ // The relative-time wording and the server's clock, for nav.js to keep `<time data-rel>` labels current.
197+ let rel_words_attr = rel_words(lang);
198+ let rel_now_attr = now_unix().to_string();
196 // Always set, defaults included, so a page never keeps the colours of the one before it.199 // Always set, defaults included, so a page never keeps the colours of the one before it.
197 // Each of the four choices is resolved on its own, so an id that is no longer offered falls200 // Each of the four choices is resolved on its own, so an id that is no longer offered falls
198 // back to its default.201 // back to its default.
@@ -257,7 +260,7 @@ pub async fn shell(
257 let unread_aside = unread_badge.clone();260 let unread_aside = unread_badge.clone();
258 Ok(view! {261 Ok(view! {
259 <!DOCTYPE html>262 <!DOCTYPE html>
260- <html lang=(lang.code()) data-theme=(theme_attr) data-accent-light=(accent_light_id) data-accent-dark=(accent_dark_id) data-base-light=(base_light_id) data-base-dark=(base_dark_id) data-sidebar=(sidebar_side)>263+ <html lang=(lang.code()) data-theme=(theme_attr) data-accent-light=(accent_light_id) data-accent-dark=(accent_dark_id) data-base-light=(base_light_id) data-base-dark=(base_dark_id) data-sidebar=(sidebar_side) data-rel-words=(rel_words_attr.as_str()) data-rel-now=(rel_now_attr.as_str())>
261 <head>264 <head>
262 <meta charset="utf-8">265 <meta charset="utf-8">
263 <meta name="viewport" content="width=device-width, initial-scale=1">266 <meta name="viewport" content="width=device-width, initial-scale=1">
@@ -930,6 +933,26 @@ pub fn relative_time(lang: Lang, unix: i64, now: i64) -> String {
930 i18n::ago(lang, n, unit)933 i18n::ago(lang, n, unit)
931 }934 }
932 935
936+/// The wording `relative_time` uses, for nav.js to re-word a `<time data-rel>` as the clock moves:
937+/// "just now", then the singular and the plural of each unit with `{n}` for the number, joined by `|`.
938+/// The order is fixed: minute, hour, day, month, year.
939+pub fn rel_words(lang: Lang) -> String {
940+ use i18n::TimeUnit;
941+ let mut words = vec![i18n::just_now(lang).to_owned()];
942+ for unit in [
943+ TimeUnit::Minute,
944+ TimeUnit::Hour,
945+ TimeUnit::Day,
946+ TimeUnit::Month,
947+ TimeUnit::Year,
948+ ] {
949+ for n in [1, 2] {
950+ words.push(i18n::ago(lang, n, unit).replacen(&n.to_string(), "{n}", 1));
951+ }
952+ }
953+ words.join("|")
954+}
955+
933 /// First seven characters of an object id.956 /// First seven characters of an object id.
934 pub fn short_oid(oid: &str) -> &str {957 pub fn short_oid(oid: &str) -> &str {
935 oid.get(..7).unwrap_or(oid)958 oid.get(..7).unwrap_or(oid)
@@ -1208,6 +1231,13 @@ mod tests {
1208 assert_eq!(relative_time(Lang::Tr, 0, 3 * 86_400), "3 gün önce");1231 assert_eq!(relative_time(Lang::Tr, 0, 3 * 86_400), "3 gün önce");
1209 assert_eq!(relative_time(Lang::Tr, 0, 2 * 2_592_000), "2 ay önce");1232 assert_eq!(relative_time(Lang::Tr, 0, 2 * 2_592_000), "2 ay önce");
1210 assert_eq!(relative_time(Lang::Tr, 0, 365 * 86_400), "1 yıl önce");1233 assert_eq!(relative_time(Lang::Tr, 0, 365 * 86_400), "1 yıl önce");
1234+ // The client re-words a label from these: the words for the same units, in the same order.
1235+ assert_eq!(
1236+ rel_words(Lang::En),
1237+ "just now|{n} minute ago|{n} minutes ago|{n} hour ago|{n} hours ago|{n} day ago|\
1238+ {n} days ago|{n} month ago|{n} months ago|{n} year ago|{n} years ago"
1239+ );
1240+ assert_eq!(rel_words(Lang::Tr).split('|').nth(4), Some("{n} saat önce"));
1211 }1241 }
1212 1242
1213 #[test]1243 #[test]
crates/forge-web/src/views/repo_list.rsmodified+1 -1
@@ -56,7 +56,7 @@ pub async fn repo_rows(rows: Vec<RepoRow>, lang: Lang) -> Result<impl View> {
56 <p class="muted small repo-stats">56 <p class="muted small repo-stats">
57 "\u{2605} " (row.stars.to_string())57 "\u{2605} " (row.stars.to_string())
58 (before)58 (before)
59- <time datetime=(row.when.iso.as_str()) title=(row.when.absolute.as_str())>(row.when.relative.as_str())</time>59+ <time data-rel="true" datetime=(row.when.iso.as_str()) title=(row.when.absolute.as_str())>(row.when.relative.as_str())</time>
60 (after)60 (after)
61 </p>61 </p>
62 </li>62 </li>
crates/forge-web/src/views/review_thread.rsmodified+1 -1
@@ -413,7 +413,7 @@ async fn thread_comment(
413 <header class="review-comment-head">413 <header class="review-comment-head">
414 <a href=(profile.as_str())><img class="avatar avatar-sm" src=(avatar.as_str()) alt="" width="24" height="24"></a>414 <a href=(profile.as_str())><img class="avatar avatar-sm" src=(avatar.as_str()) alt="" width="24" height="24"></a>
415 <strong>user_link(shown: author.as_str(), login: login.as_str())</strong>415 <strong>user_link(shown: author.as_str(), login: login.as_str())</strong>
416- <time datetime=(when.iso.as_str()) title=(when.absolute.as_str())>(when.relative.as_str())</time>416+ <time data-rel="true" datetime=(when.iso.as_str()) title=(when.absolute.as_str())>(when.relative.as_str())</time>
417 if let Some(href) = history_href {417 if let Some(href) = history_href {
418 <a class="issue-edited" href=(href.as_str())>(edited)</a>418 <a class="issue-edited" href=(href.as_str())>(edited)</a>
419 }419 }