This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
/
make
executable file
·115 lines (91 loc) · 3.38 KB
/
make
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
#!/bin/sh -e
#
# Simple static site builder.
txt2html() {
# Transform plain-text input into HTML and insert it into the template.
# Right now this only does some URL transformations.
# Convert all plain-text links to HTML links (<a href="X">X</a>).
sed -E "s|([^\"\'\>=])(http[s]?://[^[:space:]]*)|\1<a href=\2>\2</a>|g" |
sed -E "s|^(http[s]?://[^[:space:]]*)|<a href=\1>\1</a>|g" |
# Convert @/words to relative HTML links.
# Convert %/words to absolute wiki links (packages).
# Convert #/words to absolute HTML links.
# Convert $/words to GitHub URLs.
sed -E "s|(@/)([^ \)]*)|\1<a href=$1/\2>\2</a>|g" |
sed -E "s|(%/)([^ \)]*)|\1<a href=/wiki/pkg/\2>\2</a>|g" |
sed -E "s|(\\#/)([^ \)]*)|\1<a href=/\2>\2</a>|g" |
sed -E "s|(\\$/)([^ \)]*)|\1<a href=https://github.com/\2>\2</a>|g" |
# Convert [0-9] into HTML links.
sed -E "s|^([ -]*)\[([0-9\.]*)\]|\1<span id=\2>[\2]</span>|g" |
sed -E "s|([^\"#])\[([0-9\.]*)\]|\1[<a class=t href=#\2>\2</a>]|g" |
# Insert the page into the template.
sed -E '/%%CONTENT%%/r /dev/stdin' template.html |
sed -E '/%%CONTENT%%/d' |
# Insert the page path into the source URL.
sed -E "s %%TITLE%% ${2:-home} "
}
page() {
pp=${1%/*}
title=${1##*/}
title=${title%%.txt}
title=${title##index}
mkdir -p "docs/$pp"
# Generate HTML from txt files.
case $1 in *.txt)
txt2html "${pp#.}" "$title" < "site/$1" > "docs/${1%%.txt}.html"
esac
cp -Lf "site/$1" "docs/$1"
}
pkg() {
rm -rf site/wiki/pkg
mkdir -p site/wiki/pkg
# Get git log of all packages.
git -C "$KISS_REPO" log \
--date=short \
--pretty="format:%cd <a href=\"$url/commit/%H\">%h</a> %s" \
> .log
for pkg in "$KISS_REPO"/*/*/; do
pkg=${pkg%%/}
rep=${pkg%/*}
rep=${rep##*/}
while IFS= read -r line || [ "$line" ]; do case $line in
# Insert package version.
"${pkg##*/}")
read -r ver _ < "$pkg/version"
printf "%s%$((80 - ${#line}))s\\n" "$line" "version $ver" |
sed "s $ver <a href=$url/tree/master/$rep/$line>$ver</a> "
;;
# Insert new entries into index.
"* References"*)
_i=${line##*\[0}
_i=${_i#0}
_i=${_i%%']'}
printf '* History ................................................................ [%03d]\n' "$_i"
printf '%s[%03d]\n' "${line%'['*}" "$((_i + 1))"
;;
# Insert new entries into page.
"["???"] References"*)
printf '[%03d] History\n' "$_i"
printf '________________________________________________________________________________\n\n'
printf '<span style="display:block;max-height:177px;overflow:hidden scroll">'
grep -F "${pkg##*/}: " .log
printf '</span>\n\n[%03d] References\n' "$((_i + 1))"
;;
*)
printf '%s\n' "$line"
;;
esac done < "$pkg/README" > "site/wiki/pkg/${pkg##*/}.txt" || :
done
rm -f .log
}
main() {
rm -rf docs && mkdir -p docs
url=https://github.com/kisslinux/repo
[ -z "$KISS_REPO" ] || pkg
(cd site && find . ! -type d) |
while read -r page; do
printf '%s\n' "CC $page"
page "$page"
done
}
main "$@"