Repository navigation
Expand file tree
/
Copy pathsync.sh
More file actions
executable file
·52 lines (47 loc) · 1.65 KB
/
Copy pathsync.sh
File metadata and controls
executable file
·52 lines (47 loc) · 1.65 KB
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
#!/usr/bin/env bash
# Mirror pages from the CSIE wiki data repo into Jekyll pages.
set -euo pipefail
cd -- "$(dirname -- "${BASH_SOURCE[0]}")"
RAW=https://raw.githubusercontent.com/NCKUCSIE-Wiki/csiewiki-wikidata/refs/heads/main
WIKI=https://wiki.csie.ncku.edu.tw
INTRO='https://docs.google.com/presentation/d/1RwBZQDAgg0DRADH1lk06y4LEMcB1d_uYni_g2hK9mEA/edit?usp=sharing'
# mirror <wiki path> <output file> <permalink>
mirror() (
local tmp
tmp=$(mktemp "$2.XXXXXX")
trap 'rm -f "$tmp"' EXIT
curl -fsSL --retry 3 --connect-timeout 15 --max-time 120 "$RAW/$1.page" |
# The wiki closes its front matter with "..."; Jekyll insists on "---".
awk -v source="$1.page" -v wiki="/$1" -v link="$3" '
NR == 1 && $0 != "---" {
print source ": missing YAML front-matter opener" > "/dev/stderr"
exit 1
}
NR > 1 && !done && /^\.\.\.$/ {
print "layout: default"
print "permalink: " link
print "wiki: " wiki
print "---"
done = 1
next
}
{ print }
END {
if (!done) {
print source ": missing YAML front-matter terminator" > "/dev/stderr"
exit 1
}
}' |
sed \
-e "s#\(\[Course Introduction\](\)[^)]*#\1$INTRO#" \
-e 's#](/User/jserv)#]({{ site.baseurl }}/User/jserv)#g' \
-e 's#](/arch/schedule)#]({{ site.baseurl }}/)#g' \
-e "s#\](/#]($WIKI/#g" \
-e 's#\$\\to\$#\→#g' \
> "$tmp"
chmod 644 "$tmp"
mv "$tmp" "$2"
)
mkdir -p User
mirror arch/schedule index.md /
mirror User/jserv User/jserv.md /User/jserv/