#!/bin/sh -e # # Build the Alice Linux static website into public/. # Run from the project root. # # Dependencies: cmark, curl cd "$(dirname "$0")/.." for dep in cmark curl; do command -v "$dep" >/dev/null 2>&1 || { printf 'Error: "%s" is required but not found in PATH.\n' "$dep" >&2 exit 1 } done rm -rf public mkdir -p public html_escape() { # takes a single string argument, prints escaped to stdout printf '%s' "$1" | sed 's/\&/\&/g;s//\>/g;s/"/\"/g' } port_version() { grep '^version=' "$1/abuild" | cut -d = -f2- || true } port_release() { grep '^release=' "$1/abuild" | cut -d = -f2- || true } port_depends() { [ -f "$1/depends" ] || return 0 grep -Ev '^(#|$)' "$1/depends" | tr '\n' ' ' | sed 's/[[:space:]]*$//' || true } generate_ports_page() { { sed "s/@TITLE@/ports/g" files/header echo "

Package ports generated from repos/core, repos/extra, and repos/community.

" echo "
" echo "" echo "" echo "" echo "" echo "" echo "
" echo "
0 / 0 ports
" echo "" echo "" echo "" for repo in core extra community; do for port in repos/$repo/*; do [ -f "$port/abuild" ] || continue name=${port##*/} version=$(port_version "$port") release=$(port_release "$port") depends=$(port_depends "$port") [ "$release" ] && version=$version-$release e_repo=$(html_escape "$repo") e_name=$(html_escape "$name") e_version=$(html_escape "$version") e_depends=$(html_escape "$depends") printf '\n' \ "$e_repo" \ "$e_repo" \ "$e_repo" \ "$e_name" \ "$e_name" \ "$e_version" \ "$e_depends" done done echo "" echo "
reponameversiondependencies
%s%s%s%s
" cat << 'EOF' EOF cat files/footer } > public/ports.html } # copy static .html files (from repo root, readme, etc.) into public/ find . -type f -name "*.html" ! -path './public/*' | sed 's|^\./||' | while IFS= read -r i; do dir=${i%/*} file=${i##*/} title=${dir##*/} [ "$dir" = "$file" ] && { title=home; dir= } mkdir -p "public/$dir" printf 'copy html for %s...\n' "$i" { sed "s/@TITLE@/$title/g" files/header cat "$i" cat files/footer } > "public/$dir/$file" done generate_ports_page generate_commits_page() { { sed "s/@TITLE@/commits/g" files/header cat << 'EOF'

Recent commits from codeberg.org/emmett1/alicelinux.

loading…
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'

Download

Alice Linux installation images and rootfs tarballs. See the installation guide for setup instructions.

loading…
EOF if [ -n "$listing" ]; then echo "$listing" | sed -n '//,/<\/tbody>/p' | while IFS= read -r row; do case $row in *''*) href=$(printf '%s' "$row" | sed 's/.*.*/\1/') name=$(printf '%s' "$row" | sed 's/.*\([^<]*\)<.*/\1/') size=$(printf '%s' "$row" | sed 's/.*\n' \ "$e_url" "$e_name" "$e_size" "$e_date" else printf '\n' \ "$e_url" "$e_name" "$e_size" "$e_date" fi ;; esac done fi cat << 'EOF'
]*>\([^<]*\)<.*/\1/') date=$(printf '%s' "$row" | sed 's/.*\([^<]*\)<.*/\1/') type=$(printf '%s' "$row" | sed 's/.*\([^<]*\)<.*/\1/') [ "$name" = "../" ] && continue url="https://dl.alicelinux.org/$href" e_url=$(html_escape "$url") e_name=$(html_escape "$name") e_size=$(html_escape "$size") e_date=$(html_escape "$date") if [ "$type" = "Directory" ]; then printf '
%s/%s%s
%s%s%s
EOF cat files/footer } > public/download.html } generate_download_page # build docs index cat docs/readme.md > docs/index.md for f in docs/*.md; do case $f in */readme.md|*/index.md) continue;; esac title=$(head -n1 "$f" | sed "s/^#* *//") file=${f##*/} echo "- [$title](./${file%.md}.html)" >> docs/index.md done # convert markdown to html find . -type f -name "*.md" ! -path './public/*' | sed 's|^\./||' | while IFS= read -r i; do dir=${i%/*} file=${i##*/} title=${dir##*/} [ "$dir" = "$file" ] && { title=home; dir= } mkdir -p "public/$dir" printf 'generating html for %s...\n' "$i" { sed "s/@TITLE@/$title/g" files/header case $i in docs/readme.md|docs/index.md) ;; *) case $i in docs/*) printf '<- back to docs\n\n';; esac; esac cmark "$i" case $i in docs/readme.md|docs/index.md) ;; *) case $i in docs/*) printf '\n<- back to docs\n';; esac; esac cat files/footer } > "public/${i%.md}.html" done # move readme.html to index.html find public -type f -name "readme.html" | while IFS= read -r i; do mv -n "$i" "${i%/*}/index.html" done rm -f docs/index.md if [ -d files ]; then cp -ra files public/ fi echo alicelinux.org > public/.domains echo alicelinux.emmett1.my >> public/.domains exit 0