Skip to content

Commit bddf347

Browse files
author
ttasc
committed
feat: migrate to minimalist SSG architecture
1 parent c848190 commit bddf347

4 files changed

Lines changed: 484 additions & 0 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: Auto Update README & Deploy Web
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- 'games.list'
9+
- 'web/template.html'
10+
- 'web.sh'
11+
- 'readme.sh'
12+
- 'Makefile'
13+
schedule:
14+
- cron: '0 0 * * 0' # automatic run at 00:00 every Sunday
15+
workflow_dispatch:
16+
17+
jobs:
18+
build-and-deploy:
19+
runs-on: ubuntu-latest
20+
21+
permissions:
22+
contents: write
23+
24+
steps:
25+
- name: Checkout repository
26+
uses: actions/checkout@v4
27+
with:
28+
fetch-depth: 0
29+
30+
- name: Grant execute permission for scripts
31+
run: |
32+
chmod +x web.sh
33+
chmod +x readme.sh
34+
35+
- name: Make readme
36+
run: make readme
37+
38+
- name: Commit and Push README to main
39+
run: |
40+
git config --global user.name "github-actions[bot]"
41+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
42+
43+
git add README.md
44+
45+
if ! git diff-index --quiet HEAD; then
46+
git commit -m "docs: auto-update README.md [skip ci]"
47+
git push origin main
48+
echo "=> Automatic commit and push README.md to main."
49+
else
50+
echo "=> README.md no changes, skip commiting."
51+
fi
52+
53+
- name: Build static HTML
54+
run: make web
55+
56+
- name: Create Deploy directory
57+
run: |
58+
mkdir -p deploy_dist
59+
mv index.html deploy_dist/
60+
61+
- name: Deploying Website to gh-pages branch
62+
uses: peaceiris/actions-gh-pages@v4
63+
with:
64+
github_token: ${{ secrets.GITHUB_TOKEN }}
65+
publish_dir: ./deploy_dist
66+
publish_branch: gh-pages
67+
force_orphan: true

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,7 @@ clean:
5555
readme:
5656
./readme.sh
5757

58+
web:
59+
./web.sh
60+
5861
.PHONY: help install uninstall build release test clean readme

web.sh

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
#!/bin/sh
2+
3+
ORG="ttasc"
4+
HUB_REPO="gameforlinux"
5+
BASE_RAW_URL="https://raw.githubusercontent.com"
6+
7+
TEMPLATE="web/template.html"
8+
OUTPUT="index.html"
9+
GAMES_LIST="games.list"
10+
11+
if [ ! -f "$TEMPLATE" ] || [ ! -f "$GAMES_LIST" ]; then
12+
echo "[ERROR] $TEMPLATE or $GAMES_LIST not found!"
13+
exit 1
14+
fi
15+
16+
TMP_CARDS=$(mktemp)
17+
18+
echo "=> [1/3] Reading game list $GAMES_LIST..."
19+
20+
grep -v '^#' "$GAMES_LIST" | grep -v '^[[:space:]]*$' | while IFS= read -r entry; do
21+
22+
if echo "$entry" | grep -q "/"; then
23+
OWNER=$(echo "$entry" | cut -d'/' -f1)
24+
REPO=$(echo "$entry" | cut -d'/' -f2)
25+
else
26+
OWNER="$ORG"
27+
REPO="$entry"
28+
fi
29+
30+
echo " -> Fetching $OWNER/$REPO..."
31+
32+
README_URL="$BASE_RAW_URL/$OWNER/$REPO/main/README.md"
33+
HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" "$README_URL")
34+
35+
if [ "$HTTP_STATUS" != "200" ]; then
36+
README_URL="$BASE_RAW_URL/$OWNER/$REPO/master/README.md"
37+
fi
38+
39+
TMP_README=$(mktemp)
40+
curl -sL "$README_URL" > "$TMP_README"
41+
42+
TITLE="$REPO"
43+
DESC="A minimal terminal application."
44+
FEATURES_HTML=""
45+
FEATURES_SEARCH=""
46+
47+
if [ -s "$TMP_README" ]; then
48+
PARSED_TITLE=$(grep -m 1 '^# ' "$TMP_README" | sed 's/^# //; s/^[[:space:]]*//; s/[[:space:]]*$//')
49+
[ -n "$PARSED_TITLE" ] && TITLE="$PARSED_TITLE"
50+
51+
PARSED_DESC=$(awk '/^#/ || /^!/ || /^\[/ { next } NF > 0 { print; exit }' "$TMP_README" | sed 's/"/\&quot;/g; s/</\&lt;/g; s/>/\&gt;/g')
52+
[ -n "$PARSED_DESC" ] && DESC="$PARSED_DESC"
53+
54+
FEATURES=$(awk '/^## Features/{flag=1; next} /^## /{flag=0} flag {print}' "$TMP_README" | grep -o '\*\*[^*]*\*\*' | sed 's/\*\*//g' | sed 's/://g')
55+
56+
echo "$FEATURES" | while IFS= read -r f; do
57+
if [ -n "$f" ]; then
58+
SAFE_F=$(echo "$f" | sed 's/"/\&quot;/g; s/</\&lt;/g; s/>/\&gt;/g')
59+
FEATURES_HTML="$FEATURES_HTML<span class=\"tag\">$SAFE_F</span>"
60+
FEATURES_SEARCH="$FEATURES_SEARCH $SAFE_F"
61+
fi
62+
done
63+
64+
if [ -n "$FEATURES" ]; then
65+
FEATURES_HTML=$(echo "$FEATURES" | awk 'NF' | while read -r f; do echo "<span class=\"tag\">$f</span>"; done | tr -d '\n')
66+
FEATURES_HTML="<div class=\"tags\">$FEATURES_HTML</div>"
67+
68+
FEATURES_SEARCH=$(echo "$FEATURES" | tr '\n' ' ')
69+
fi
70+
fi
71+
rm -f "$TMP_README"
72+
73+
DEMO_URL="$BASE_RAW_URL/$OWNER/$REPO/refs/heads/master/demo.gif"
74+
SEARCH_STRING=$(echo "$TITLE $DESC $FEATURES_SEARCH" | tr '[:upper:]' '[:lower:]' | sed 's/"/\&quot;/g')
75+
76+
cat <<EOF >> "$TMP_CARDS"
77+
<article class="game-card" data-search="${SEARCH_STRING}">
78+
<div class="game-desc">
79+
<h3 class="game-title">
80+
<span>${TITLE}</span>
81+
<a href="https://github.com/${OWNER}/${REPO}" target="_blank" rel="noopener noreferrer" aria-label="View source code for ${TITLE}">View Source ↗</a>
82+
</h3>
83+
<p>${DESC}</p>
84+
${FEATURES_HTML}
85+
</div>
86+
<div class="game-footer">
87+
<p class="text-comment font-sm" style="margin-bottom: 0.5rem;">// Install standalone:</p>
88+
<div class="cmd" aria-label="Copy install command for ${TITLE}">curl -fsSL ${BASE_RAW_URL}/${ORG}/${HUB_REPO}/main/install.sh | sh -s -- ${REPO}</div>
89+
<button class="btn btn-demo" data-demo-url="${DEMO_URL}" aria-label="Watch gameplay demo for ${TITLE}">Watch Demo</button>
90+
</div>
91+
</article>
92+
EOF
93+
done
94+
95+
echo "=> [2/3] Data compilation successful."
96+
97+
GAME_COUNT=$(grep -c 'class="game-card"' "$TMP_CARDS")
98+
99+
echo "=> [3/3] Rendering HTML..."
100+
101+
awk -v cards_file="$TMP_CARDS" -v count="$GAME_COUNT" '
102+
/id="available-games-title"/ {
103+
sub("Available Games", "Available Games (" count ")")
104+
}
105+
/\{\{GAMES_LIST\}\}/ {
106+
while ((getline line < cards_file) > 0)
107+
print line
108+
next
109+
}
110+
{print}
111+
' "$TEMPLATE" > "$OUTPUT"
112+
113+
rm -f "$TMP_CARDS"
114+
115+
echo
116+
echo "Done."

0 commit comments

Comments
 (0)