diff options
| author | Danilo M. <danix@danix.xyz> | 2026-05-14 20:37:33 +0200 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-05-14 20:37:33 +0200 |
| commit | f4700120158c2a4626e0b12956245f5c4bb964e9 (patch) | |
| tree | 36d0696b565d847ce25b953530168412e629fcb6 /assets/js | |
| parent | 9fc726e11fd95926363226d9fbac7cd85355368d (diff) | |
| download | danixxyz-theme-f4700120158c2a4626e0b12956245f5c4bb964e9.tar.gz danixxyz-theme-f4700120158c2a4626e0b12956245f5c4bb964e9.zip | |
feat: add pkg-changelog Alpine component for ChangeLog.txt
Diffstat (limited to 'assets/js')
| -rw-r--r-- | assets/js/pkg-changelog.js | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/assets/js/pkg-changelog.js b/assets/js/pkg-changelog.js new file mode 100644 index 0000000..24750bf --- /dev/null +++ b/assets/js/pkg-changelog.js @@ -0,0 +1,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; +} |
