fix(web): pin the sidebar highlight to the route, and name the build

The highlight compared hrefs, which a trailing slash or a query string in the
hash was enough to defeat, and it only ran once the view had loaded. Each
link now carries the route it stands for and the highlight is applied as soon
as the sidebar exists.

The footer also states the running version and the date of the newest
interface file. Deployments that ship an archive make it easy to look at a
stale copy and wonder why a fix is missing; the page can now say so.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
nocodeandClaude Opus 5 committed 2026-09-23 20:47:46 +02:00
1 parent 2083133c7a
commit a44ff0cb52
3 files changed
+71 -5

No files matched your search

+41
View File
@@ -1,3 +1,6 @@
import { readFileSync, readdirSync, statSync } from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { ACCESS_LEVELS } from '../../config/constants.js';
import { registerAuthRoutes } from '../auth/routes.js';
import { openEventStream } from '../events.js';
@@ -12,6 +15,42 @@ import { registerReleaseRoutes } from './releases.js';
import { registerRepositoryRoutes } from './repositories.js';
import { registerSettingsRoutes } from './settings.js';
const here = path.dirname(fileURLToPath(import.meta.url));
const VERSION = (() => {
try {
return JSON.parse(readFileSync(path.join(here, '../../../package.json'), 'utf8')).version;
} catch {
return 'inconnue';
}
})();
/**
* Newest file of the served interface.
*
* Deployments that ship an archive make it easy to look at a stale copy and
* wonder why a fix is missing; this gives the page something to state.
*/
const BUILD_AT = (() => {
const root = path.join(here, '../public');
let newest = 0;
const walk = (directory) => {
for (const entry of readdirSync(directory, { withFileTypes: true })) {
const target = path.join(directory, entry.name);
if (entry.isDirectory()) walk(target);
else newest = Math.max(newest, statSync(target).mtimeMs);
}
};
try {
walk(root);
} catch {
return null;
}
return newest > 0 ? new Date(newest).toISOString() : null;
})();
/**
* Route registration order matters only for readability: the router matches on
* the full pattern, not on declaration order.
@@ -25,6 +64,8 @@ export function registerApiRoutes(router, { setupOnly = false } = {}) {
status: context.client?.isReady?.() ? 'ok' : 'starting',
setupOnly: context.setupOnly,
uptimeMs: Date.now() - context.startedAt,
version: VERSION,
buildAt: BUILD_AT,
}),
{ public: true },
);
+24 -5
View File
@@ -139,14 +139,17 @@ const currentRoute = () => {
* Navigation only swaps the main area, so the highlight has to be refreshed on
* its own — otherwise it keeps pointing at the page you arrived on.
*/
function highlightNav() {
function highlightNav(scope = document) {
const { segments } = currentRoute();
const active = segments[0] ?? '';
const route = ROUTES.find((entry) => entry.path === active);
for (const link of document.querySelectorAll('.nav a')) {
link.classList.toggle('active', link.getAttribute('href') === `#/${active}`);
if (link.getAttribute('href') === `#/${active}`) link.setAttribute('aria-current', 'page');
for (const link of scope.querySelectorAll('.nav a')) {
// Compare the route the link carries, not its href: a trailing slash or a
// query string in the hash must not make an entry look inactive.
const current = link.dataset.route === active;
link.classList.toggle('active', current);
if (current) link.setAttribute('aria-current', 'page');
else link.removeAttribute('aria-current');
}
document.title = route ? `${route.label} · FWS-Bot` : 'FWS-Bot';
@@ -209,7 +212,7 @@ function sidebar() {
group.routes.map((route) =>
h(
'a',
{ href: `#/${route.path}` },
{ href: `#/${route.path}`, dataset: { route: route.path } },
h('span', { class: 'nav-icon', text: route.icon }),
h('span', { text: route.label }),
),
@@ -226,6 +229,7 @@ function sidebar() {
button('Avancé', () => setMode('advanced'), {}),
),
liveIndicator(),
h('div', { class: 'build muted', text: '…' }),
h(
'div',
{ class: 'viewer' },
@@ -320,9 +324,23 @@ export function render() {
const shell = h('div', { class: 'shell' }, sidebar(), main);
mount(app, shell);
applyModeButtons(shell);
highlightNav(shell);
renderView(main);
}
/** Names the interface actually being served, archive deployments being easy to get wrong. */
async function showBuild() {
const health = await api.get('/api/health').catch(() => null);
const node = qs('.build');
if (!node || !health) return;
const built = health.buildAt
? new Date(health.buildAt).toLocaleString('fr-FR', { dateStyle: 'short', timeStyle: 'short' })
: 'date inconnue';
node.textContent = `v${health.version} · interface du ${built}`;
node.title = "Date du fichier d'interface le plus récent servi par le bot.";
}
async function boot() {
document.body.dataset.mode = state.mode;
document.documentElement.dataset.theme = state.theme;
@@ -335,6 +353,7 @@ async function boot() {
state.config = config;
startLive();
showBuild();
window.addEventListener('hashchange', () => {
const main = qs('.main');
+6
View File
@@ -690,6 +690,12 @@ pre code {
padding-left: 1.2rem;
}
.build {
font-size: 0.7rem;
padding: 0 0.2rem;
opacity: 0.75;
}
.live {
display: flex;
align-items: center;