Add WikiLog page and nav link showing last 50 content changes

This commit is contained in:
Davide Scaini
2026-05-08 08:50:31 +02:00
parent 476f605a4a
commit dfce744001
2 changed files with 44 additions and 4 deletions
+7 -4
View File
@@ -141,6 +141,7 @@ const { title = 'BincioWiki', description = 'La memoria collettiva del gruppo Bi
)}
<div class="ml-auto shrink-0 flex items-center gap-2">
<span id="nav-handle" class="text-xs text-zinc-500" style="display:none"></span>
<a id="nav-wikilog" href="/log/" class="text-xs text-zinc-500 hover:text-white transition-colors px-1" style="display:none">WikiLog</a>
<button id="nav-logout" class="text-xs text-zinc-500 hover:text-white transition-colors px-1" style="display:none">Log out</button>
<button
id="theme-toggle"
@@ -172,10 +173,12 @@ const { title = 'BincioWiki', description = 'La memoria collettiva del gruppo Bi
document.body.removeAttribute('data-auth-pending');
const user = await r.json().catch(() => null);
if (user) {
const handleEl = document.getElementById('nav-handle');
const logoutEl = document.getElementById('nav-logout');
if (handleEl) { handleEl.textContent = '@' + user.handle; handleEl.style.display = ''; }
if (logoutEl) logoutEl.style.display = '';
const handleEl = document.getElementById('nav-handle');
const wikilogEl = document.getElementById('nav-wikilog');
const logoutEl = document.getElementById('nav-logout');
if (handleEl) { handleEl.textContent = '@' + user.handle; handleEl.style.display = ''; }
if (wikilogEl) wikilogEl.style.display = '';
if (logoutEl) logoutEl.style.display = '';
}
})
.catch(() => { document.body.removeAttribute('data-auth-pending'); });
+37
View File
@@ -0,0 +1,37 @@
---
import Base from '../../layouts/Base.astro';
import { SITE_TITLE } from '../../consts';
---
<Base title={`WikiLog — ${SITE_TITLE}`} description="Ultime modifiche al wiki">
<div class="max-w-3xl mx-auto">
<h1 class="text-3xl font-bold mb-8" style="color: var(--text-primary)">WikiLog</h1>
<div id="log-list" class="space-y-2">
<p class="text-sm" style="color: var(--text-4)">Caricamento…</p>
</div>
</div>
</Base>
<script>
fetch('/api/log', { credentials: 'include' })
.then(r => r.json())
.then(({ log }) => {
const el = document.getElementById('log-list');
if (!el) return;
if (!log?.length) { el.innerHTML = '<p class="text-sm" style="color:var(--text-4)">Nessuna modifica ancora.</p>'; return; }
el.innerHTML = log.map((e: any) => {
const [author, rest] = e.message.includes(': ') ? e.message.split(': ', 2) : ['', e.message];
return `
<div class="flex items-baseline gap-3 px-3 py-2 rounded-lg text-sm" style="background:var(--bg-card)">
<span class="font-mono text-xs shrink-0" style="color:var(--text-5)">${e.hash}</span>
<span class="shrink-0" style="color:var(--accent)">${author || e.author}</span>
<span class="flex-1 truncate" style="color:var(--text-2)">${rest || e.message}</span>
<span class="shrink-0 text-xs" style="color:var(--text-5)">${e.date}</span>
</div>`;
}).join('');
})
.catch(() => {
const el = document.getElementById('log-list');
if (el) el.innerHTML = '<p class="text-sm" style="color:#f87171">Errore nel caricamento.</p>';
});
</script>