diff options
Diffstat (limited to 'changelog/api')
| -rwxr-xr-x | changelog/api/latest.php | 37 | ||||
| -rwxr-xr-x | changelog/api/parser.php | 91 |
2 files changed, 128 insertions, 0 deletions
diff --git a/changelog/api/latest.php b/changelog/api/latest.php new file mode 100755 index 0000000..fe0553b --- /dev/null +++ b/changelog/api/latest.php @@ -0,0 +1,37 @@ +[ + { + "title": "Site update", + "body": "Added more programs to the site and added my own guestbook with captcha :) hope you enjoy this site update.", + "year": 2024, + "month": 9, + "day": 9 + }, + { + "title": "Site update", + "body": "Fixing some links updating the site to work better added a new feature to the site. But it broke the mobile part of it so far. that will be fixed in the future.", + "year": 2024, + "month": 8, + "day": 1 + }, + { + "title": "Site update", + "body": "Going to add some pages like runescape and special force a fps game from south korea. plan on updating more links.", + "year": 2024, + "month": 7, + "day": 24 + }, + { + "title": "Site update", + "body": "successfully changed my host to sdf got secure web permission and ssl. feels good.", + "year": 2024, + "month": 6, + "day": 14 + }, + { + "title": "Site update", + "body": "Changed my host to sdf will update links and so on.", + "year": 2024, + "month": 6, + "day": 11 + } +] diff --git a/changelog/api/parser.php b/changelog/api/parser.php new file mode 100755 index 0000000..fe0dd85 --- /dev/null +++ b/changelog/api/parser.php @@ -0,0 +1,91 @@ +<?php +/** + * Helper to parse changelog TXT files and render them as HTML. + */ + +function get_changelog_entries($limit = null) { + $files = glob(dirname(__DIR__) . '/*-changelog.txt'); + rsort($files); // Newest years first + + $all_entries = []; + foreach ($files as $file) { + $content = file_get_contents($file); + $lines = explode("\n", $content); + + // An entry starts on a "* <date>: ..." line; following lines that do + // not start with "*" are wrapped continuations of that same entry, so + // fold them back in instead of dropping them (which truncated the text). + $current = null; + $flush = function () use (&$current, &$all_entries) { + if ($current === null) return; + $current['text'] = trim(preg_replace('/\s+/', ' ', $current['text'])); + $all_entries[] = $current; + $current = null; + }; + + foreach ($lines as $line) { + $line = rtrim($line); + if (str_starts_with(ltrim($line), '*')) { + $flush(); + // Format: * 9 Sept 2024: Description + if (preg_match('/^\*\s*(\d+\s+\w+\s+(\d{4})):\s*(.*)$/', trim($line), $matches)) { + $date_str = $matches[1]; + $entry_year = (int)$matches[2]; + + $timestamp = strtotime($date_str); + $iso_date = $timestamp ? date('Y-m-d', $timestamp) : ''; + $display_date = $timestamp ? date('Y-m-d', $timestamp) : $date_str; + + $current = [ + 'year' => $entry_year, + 'date' => $iso_date, + 'display_date' => $display_date, + 'text' => $matches[3], + 'raw_date' => $date_str + ]; + } + } elseif ($current !== null && trim($line) !== '') { + $current['text'] .= ' ' . trim($line); + } + } + $flush(); + } + + // Sort by date DESC + usort($all_entries, function($a, $b) { + return strcmp($b['date'], $a['date']); + }); + + if ($limit !== null) { + return array_slice($all_entries, 0, $limit); + } + + return $all_entries; +} + +function get_changelog_by_year() { + $entries = get_changelog_entries(); + $by_year = []; + foreach ($entries as $e) { + $by_year[$e['year']][] = $e; + } + krsort($by_year); + return $by_year; +} + +function render_changelog_list($entries) { + if (empty($entries)) return '<p class="muted">No entries yet.</p>'; + + $html = '<ul class="changelog-list">'; + foreach ($entries as $e) { + $html .= '<li class="changelog-entry">'; + if ($e['date']) { + $html .= '<time datetime="' . htmlspecialchars($e['date']) . '">' . htmlspecialchars($e['display_date']) . '</time>'; + } + $html .= '<div class="text">' . htmlspecialchars($e['text']) . '</div>'; + $html .= '<a class="changelog-more" href="https://www.sillylaird.ca/changelog/#year-' . (int)$e['year'] . '">more (' . (int)$e['year'] . ') →</a>'; + $html .= '</li>'; + } + $html .= '</ul>'; + return $html; +} |
