1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
|
#!/bin/sh -e
rm -rf public
mkdir -p public
html_escape() {
sed 's/\&/\&/g;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
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>"
echo "<button type=\"button\" data-repo=\"core\">core</button>"
echo "<button type=\"button\" data-repo=\"extra\">extra</button>"
echo "<button type=\"button\" data-repo=\"community\">community</button>"
echo "<input id=\"ports-search\" type=\"search\" placeholder=\"filter ports\" autocomplete=\"off\">"
echo "</div>"
echo "<div class=\"ports-count\"><span id=\"ports-visible\">0</span> / <span id=\"ports-total\">0</span> ports</div>"
echo "<table id=\"ports-table\">"
echo "<thead><tr><th>repo</th><th>name</th><th>version</th><th>dependencies</th></tr></thead>"
echo "<tbody>"
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
printf '<tr data-repo="%s"><td>%s</td><td><a href="https://codeberg.org/emmett1/alicelinux/src/branch/main/repos/%s/%s">%s</a></td><td>%s</td><td>%s</td></tr>\n' \
"$(printf '%s' "$repo" | html_escape)" \
"$(printf '%s' "$repo" | html_escape)" \
"$(printf '%s' "$repo" | html_escape)" \
"$(printf '%s' "$name" | html_escape)" \
"$(printf '%s' "$name" | html_escape)" \
"$(printf '%s' "$version" | html_escape)" \
"$(printf '%s' "$depends" | html_escape)"
done
done
echo "</tbody>"
echo "</table>"
cat << 'EOF'
<script>
(function () {
var table = document.getElementById('ports-table');
var rows = Array.prototype.slice.call(table.querySelectorAll('tbody tr'));
var search = document.getElementById('ports-search');
var visible = document.getElementById('ports-visible');
var total = document.getElementById('ports-total');
var buttons = Array.prototype.slice.call(document.querySelectorAll('.ports-toolbar button'));
var repo = 'all';
total.textContent = rows.length;
function filterPorts() {
var query = search.value.trim().toLowerCase();
var count = 0;
rows.forEach(function (row) {
var repoMatch = repo === 'all' || row.dataset.repo === repo;
var textMatch = !query || row.textContent.toLowerCase().indexOf(query) !== -1;
var show = repoMatch && textMatch;
row.style.display = show ? '' : 'none';
if (show) count++;
});
visible.textContent = count;
}
buttons.forEach(function (button) {
button.addEventListener('click', function () {
repo = button.dataset.repo;
buttons.forEach(function (b) { b.classList.remove('active'); });
button.classList.add('active');
filterPorts();
});
});
search.addEventListener('input', filterPorts);
filterPorts();
}());
</script>
EOF
cat files/footer
} > public/ports.html
}
for i in $(find . -type f -name "*.html" | sed 's|^\./||'); do
dir=${i%/*}
file=${i##*/}
title=${dir##*/}
[ "$dir" = "$file" ] && {
title=home; dir=
}
mkdir -p public/$dir
echo "copy html for $i..."
{
sed "s/@TITLE@/$title/g" files/header
cat $i
cat files/footer
} > public/$dir/$file
done
generate_ports_page
# docs
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)
file=${f##*/}
echo "- [$title](./${file%.md}.html)" >> docs/index.md
done
for i in $(find . -type f -name "*.md" | sed 's|^\./||'); do
dir=${i%/*}
file=${i##*/}
title=${dir##*/}
[ "$dir" = "$file" ] && {
title=home; dir=
}
mkdir -p public/$dir
echo "generating html for $i..."
{
sed "s/@TITLE@/$title/g" files/header
cmark $i
cat files/footer
} > public/${i%.md}.html
done
# mv readme.html to index.html
for i in $(find public -type f -name "readme.html" | sed 's|^\./||'); 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
|