blob: 24750bfbf60bd3b6efaa9f7891fa6fb9c6928b69 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
document.addEventListener('alpine:init', () => {
Alpine.data('pkgChangelog', (count, i18n) => ({
state: 'loading', // 'loading' | 'loaded' | 'error'
i18n: i18n,
entries: [],
async init() {
try {
const res = await fetch('https://packages.danix.xyz/ChangeLog.txt');
if (!res.ok) throw new Error('HTTP ' + res.status);
const text = await res.text();
this.entries = parseChangelog(text, count);
this.state = 'loaded';
} catch (e) {
console.error('pkg-changelog fetch error:', e);
this.state = 'error';
}
}
}));
});
function parseChangelog(text, maxEntries) {
const SEPARATOR = '+--------------------------+';
const chunks = text.split(SEPARATOR);
const entries = [];
for (const chunk of chunks) {
if (entries.length >= maxEntries) break;
const lines = chunk.split('\n').map(l => l.trimEnd()).filter(l => l.trim() !== '');
if (lines.length < 2) continue;
const timestamp = lines[0].trim();
// Validate it looks like a timestamp (starts with a day name)
if (!/^(Mon|Tue|Wed|Thu|Fri|Sat|Sun)/.test(timestamp)) continue;
const changes = lines.slice(1).join('\n').trim();
entries.push({ timestamp, changes });
}
return entries;
}
|