aboutsummaryrefslogtreecommitdiff
path: root/buildsite.sh
diff options
context:
space:
mode:
Diffstat (limited to 'buildsite.sh')
-rwxr-xr-xbuildsite.sh278
1 files changed, 212 insertions, 66 deletions
diff --git a/buildsite.sh b/buildsite.sh
index 6e24206d..ab604e73 100755
--- a/buildsite.sh
+++ b/buildsite.sh
@@ -23,72 +23,6 @@ port_depends() {
generate_ports_page() {
{
sed "s/@TITLE@/ports/g" files/header
- cat << 'EOF'
-<style>
-.ports-toolbar {
- display: flex;
- flex-wrap: wrap;
- gap: 8px;
- margin-bottom: 12px;
-}
-.ports-toolbar button,
-.ports-toolbar input {
- font: inherit;
- color: #fefefe;
- background: transparent;
- border: 0;
- border-bottom: 1px solid rgba(231, 232, 235, 0.35);
- padding: 6px 0;
-}
-.ports-toolbar button {
- cursor: pointer;
-}
-.ports-toolbar button.active {
- color: #90cbf9;
- border-bottom-color: #90cbf9;
-}
-.ports-toolbar input {
- flex: 1 1 18em;
- min-width: 0;
-}
-.ports-count {
- margin-bottom: 12px;
-}
-#ports-table th,
-#ports-table td {
- border: 0;
- border-bottom: 1px solid rgba(231, 232, 235, 0.28);
- padding: 6px 4px;
-}
-#ports-table {
- border: 0;
- table-layout: auto;
-}
-#ports-table thead th {
- border-bottom-color: rgba(231, 232, 235, 0.55);
-}
-#ports-table th:nth-child(1),
-#ports-table td:nth-child(1) {
- width: 5em;
-}
-#ports-table th:nth-child(2),
-#ports-table td:nth-child(2) {
- width: 16em;
-}
-#ports-table th:nth-child(3),
-#ports-table td:nth-child(3) {
- white-space: nowrap;
- width: 1%;
-}
-#ports-table th:nth-child(4),
-#ports-table td:nth-child(4) {
- width: 100%;
-}
-#ports-table tbody tr:last-child td {
- border-bottom: 0;
-}
-EOF
- echo "</style>"
echo "<p>Package ports generated from <code>repos/core</code>, <code>repos/extra</code>, and <code>repos/community</code>.</p>"
echo "<div class=\"ports-toolbar\">"
echo "<button type=\"button\" class=\"active\" data-repo=\"all\">all</button>"
@@ -187,6 +121,218 @@ done
generate_ports_page
+generate_commits_page() {
+ {
+ sed "s/@TITLE@/commits/g" files/header
+ cat << 'EOF'
+<p>Recent commits from <a href="https://codeberg.org/emmett1/alicelinux">codeberg.org/emmett1/alicelinux</a>.</p>
+<ul id="commits"></ul>
+<div id="commits-loading">loading…</div>
+<div id="commits-error"></div>
+<script>
+(function () {
+ var list = document.getElementById('commits');
+ var loading = document.getElementById('commits-loading');
+ var errEl = document.getElementById('commits-error');
+ var page = 1;
+ var loadingMore = false;
+ var hasMore = true;
+ var PER_PAGE = 30;
+
+ function fmtHash(hash) {
+ return hash.substring(0, 7);
+ }
+
+ function fmtDate(iso) {
+ var d = new Date(iso);
+ var y = d.getFullYear();
+ var m = String(d.getMonth() + 1).padStart(2, '0');
+ var day = String(d.getDate()).padStart(2, '0');
+ var h = String(d.getHours()).padStart(2, '0');
+ var min = String(d.getMinutes()).padStart(2, '0');
+ return y + '-' + m + '-' + day + ' ' + h + ':' + min;
+ }
+
+ function esc(s) {
+ var d = document.createElement('div');
+ d.textContent = s;
+ return d.innerHTML;
+ }
+
+ function loadCommits() {
+ if (!hasMore || loadingMore) return;
+ loadingMore = true;
+ loading.style.display = 'block';
+
+ var url = 'https://codeberg.org/api/v1/repos/emmett1/alicelinux/commits?limit=' + PER_PAGE + '&page=' + page;
+
+ fetch(url)
+ .then(function (r) {
+ if (!r.ok) throw new Error('HTTP ' + r.status);
+ var link = r.headers.get('X-HasMore');
+ if (link === 'false' || link === null) hasMore = false;
+ return r.json();
+ })
+ .then(function (data) {
+ if (!data.length || data.length < PER_PAGE) hasMore = false;
+
+ data.forEach(function (c) {
+ var li = document.createElement('li');
+ var hash = c.sha || '';
+ var msg = c.commit.message.split('\n')[0] || '';
+ var author = c.commit.author.name || 'unknown';
+ var date = c.commit.author.date || '';
+ var url = c.html_url || '#';
+
+ li.innerHTML =
+ '<span class="commit-hash"><a href="' + esc(url) + '">' + esc(fmtHash(hash)) + '</a></span>' +
+ '<span class="commit-msg"><a href="' + esc(url) + '">' + esc(msg) + '</a></span>' +
+ '<span class="commit-meta">' + esc(author) + '<br>' + esc(fmtDate(date)) + '</span>';
+ list.appendChild(li);
+ });
+
+ page++;
+ loadingMore = false;
+ loading.style.display = 'none';
+ })
+ .catch(function (err) {
+ loadingMore = false;
+ loading.style.display = 'none';
+ hasMore = false;
+ errEl.textContent = 'Failed to load commits: ' + err.message;
+ errEl.style.display = 'block';
+ });
+ }
+
+ window.addEventListener('scroll', function () {
+ if (loadingMore || !hasMore) return;
+ var scrollBottom = window.scrollY + window.innerHeight;
+ var threshold = document.body.scrollHeight - 600;
+ if (scrollBottom >= threshold) loadCommits();
+ });
+
+ loadCommits();
+}());
+</script>
+EOF
+ cat files/footer
+ } > public/commits.html
+}
+
+generate_commits_page
+
+generate_download_page() {
+ {
+ sed "s/@TITLE@/download/g" files/header
+
+ listing=$(curl -sL --max-time 10 https://dl.alicelinux.org/ 2>/dev/null || true)
+
+ cat << 'EOF'
+<div id="dl-status" class="dl-empty">loading…</div>
+<table class="dl-table" id="dl-table"><tbody>
+EOF
+
+ if [ -n "$listing" ]; then
+ echo "$listing" | sed -n '/<tbody>/,/<\/tbody>/p' | while IFS= read -r row; do
+ case $row in
+ *'<tr>'*)
+ href=$(printf '%s' "$row" | sed 's/.*<a href="\([^"]*\)">.*/\1/')
+ name=$(printf '%s' "$row" | sed 's/.*<a href="[^"]*">\([^<]*\)<.*/\1/')
+ size=$(printf '%s' "$row" | sed 's/.*<td class="s"[^>]*>\([^<]*\)<.*/\1/')
+ date=$(printf '%s' "$row" | sed 's/.*<td class="m">\([^<]*\)<.*/\1/')
+ type=$(printf '%s' "$row" | sed 's/.*<td class="t">\([^<]*\)<.*/\1/')
+ [ "$name" = "../" ] && continue
+ url="https://dl.alicelinux.org/$href"
+ if [ "$type" = "Directory" ]; then
+ printf '<tr><td><a href="%s">%s/</a></td><td>%s</td><td>%s</td></tr>\n' \
+ "$(printf '%s' "$url" | html_escape)" \
+ "$(printf '%s' "$name" | html_escape)" \
+ "$(printf '%s' "$size" | html_escape)" \
+ "$(printf '%s' "$date" | html_escape)"
+ else
+ printf '<tr><td><a href="%s">%s</a></td><td>%s</td><td>%s</td></tr>\n' \
+ "$(printf '%s' "$url" | html_escape)" \
+ "$(printf '%s' "$name" | html_escape)" \
+ "$(printf '%s' "$size" | html_escape)" \
+ "$(printf '%s' "$date" | html_escape)"
+ fi
+ ;;
+ esac
+ done
+ fi
+
+ cat << 'EOF'
+</tbody></table>
+<script>
+(function () {
+ var table = document.getElementById('dl-table');
+ var tbody = table.querySelector('tbody');
+ var status = document.getElementById('dl-status');
+
+ function esc(s) {
+ var d = document.createElement('div');
+ d.textContent = s;
+ return d.innerHTML;
+ }
+
+ function rowHTML(href, name, size, date, isDir) {
+ var url = 'https://dl.alicelinux.org/' + href;
+ var label = esc(name) + (isDir ? '/' : '');
+ return '<tr><td><a href="' + esc(url) + '">' + label + '</a></td><td>' + esc(size) + '</td><td>' + esc(date) + '</td></tr>';
+ }
+
+ fetch('https://dl.alicelinux.org/')
+ .then(function (r) {
+ if (!r.ok) throw new Error('HTTP ' + r.status);
+ return r.text();
+ })
+ .then(function (html) {
+ var parser = new DOMParser();
+ var doc = parser.parseFromString(html, 'text/html');
+ var rows = doc.querySelectorAll('table tbody tr');
+ var frag = document.createDocumentFragment();
+
+ rows.forEach(function (row) {
+ var cells = row.querySelectorAll('td');
+ if (!cells.length) return;
+ var link = cells[0].querySelector('a');
+ if (!link) return;
+ var href = link.getAttribute('href');
+ var name = link.textContent;
+ if (name === '../') return;
+ var size = cells[2] ? cells[2].textContent.trim() : '';
+ var date = cells[1] ? cells[1].textContent.trim() : '';
+ var isDir = cells[3] && cells[3].textContent.trim() === 'Directory';
+ var tr = document.createElement('tr');
+ tr.innerHTML = rowHTML(href, name, size, date, isDir);
+ frag.appendChild(tr);
+ });
+
+ if (frag.childNodes.length) {
+ tbody.innerHTML = '';
+ tbody.appendChild(frag);
+ }
+ status.textContent = '';
+ status.style.display = 'none';
+ })
+ .catch(function () {
+ var rows = tbody.querySelectorAll('tr');
+ if (rows.length) {
+ status.textContent = '';
+ status.style.display = 'none';
+ } else {
+ status.innerHTML = 'Unable to load. Visit <a href="https://dl.alicelinux.org">dl.alicelinux.org</a> directly.';
+ }
+ });
+}());
+</script>
+EOF
+ cat files/footer
+ } > public/download.html
+}
+
+generate_download_page
+
# docs
cat docs/readme.md > docs/index.md
for f in docs/*.md; do