This repository has been archived by the owner on May 9, 2022. It is now read-only.
forked from kisslinux/kisslinux.github.io
-
Notifications
You must be signed in to change notification settings - Fork 5
/
make
executable file
·113 lines (89 loc) · 3.31 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
#!/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 absolute HTML links.
# Convert @/words to relative HTML links.
# Convert $/words to GitHub URLs.
sed -E "s|(#/)([^ \)]*)|\1<a href=/\2>\2</a>|g" |
sed -E "s|(@/)([^ \)]*)|\1<a href=${pp##.}/\2>\2</a>|g" |
sed -E "s|(\\$/)([^ \)]*)|\1<a href=$repo_url/\2>\2</a>|g" |
# Convert [0] into HTML links.
sed -E "s|^( *)\[([0-9\.]*)\]|\1<span id=\2>[\2]</span>|g" |
sed -E "s|([^\"#])\[([0-9\.]*)\]|\1<a 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%% $title "
}
wiki_nav() {
# Generate the navigation bar and edit information for each Wiki page.
# Split the path on '/'.
# shellcheck disable=2086
{
set -f; IFS=/
set +f ${page##./}
unset IFS
}
# '$nar' contains the generated nav without HTML additions for use in
# length calculations below.
nav="<a href=\"/$1\">$1</a>" nar=$1
[ "$2" ] && nav="$nav / <a href='/$1/$2'>$2</a>" nar="$nar / $2"
[ "${3#index.txt}" ] && nav="$nav / ${3%%.txt}" nar="$nar / ${3%%.txt}"
# Calculate the amount of padding to add. This will right align the
# edit page link. Wiki page length is always 80 columns.
nav="$nav$(printf '%*s' "$((80 - ${#nar} - 14))" "")"
nav="$nav<a href='$wiki_url/edit/master/${page##*wiki/}'>Edit this page</a>"
printf '%s\n\n%s\n\n\n' "$nav" \
"$(git submodule foreach --quiet git log -1 \
--format="Edited (<a href='$wiki_url/commit/%H'>%h</a>) at %as by %an" \
"${page##*wiki/}")"
}
page() {
pp=${page%/*} title=${page##*/} title=${title%%.txt}
mkdir -p "docs/$pp"
# If the title is index.txt, set it to the parent directory name.
# Example: /wiki/index.txt (index) -> (wiki).
case $title in index) title=${pp##*/} ;; esac
case $title in .) title=home ;; esac
# GENERATION STEP.
case $page in
# Generate HTML from Wiki pages.
*/wiki/index.txt)
txt2html < "site/$page" > "docs/${page%%.txt}.html"
;;
*/wiki/*.txt)
wiki_nav | cat - "site/$page" | txt2html > "docs/${page%%.txt}.html"
;;
# Generate HTML from txt files.
*.txt)
txt2html < "site/$page" > "docs/${page%%.txt}.html"
;;
# Copy over any non-txt files.
*)
cp -f "site/$page" "docs/$page"
;;
esac
# POST-GENERATION STEP.
case $page in
# Hardlink all .txt files to the docs/ directory.
*.txt) ln -f "site/$page" "docs/$page" ;;
esac
}
main() {
wiki_url=https://github.com/kiss-community/wiki
repo_url=https://github.com
rm -rf docs
mkdir -p docs
(cd site && find . -type f) | while read -r page; do
printf '%s\n' "CC $page"
page "$page"
done
}
main "$@"