-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathretejo.sh
More file actions
109 lines (96 loc) · 2.56 KB
/
Copy pathretejo.sh
File metadata and controls
109 lines (96 loc) · 2.56 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
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
#!/bin/sh
#@(#) a simple static website generator, written in plain POSIX shell
#@(#) probably needs some love to add some functions and such, but generally
#@(#) relatively simple and easy to use.
#@(#) [EO] simpla statika retejo generato, skribita en simpla POSIX-sxelo.
#@(#) probable bezonas amon por aldoni funkciojn, sed gxenerale simpla kaj
#@(#) facile uzebla
set -euf
# probably could set a `-o pipefail` as well, but thats
# bash-only
arg=$1
base=' '
target=' '
type=md
# grab a base and a target here; we could also note if
# we even *have* a target or if we also want to generate
# a directory listing...
if [ -d "$arg" ]
then
base=$arg
if [ -f "$base/index.txt" ]
then
target="$base/index.txt"
elif [ -f "$base/README.md" ]
then
target="$base/README.md"
elif [ -f "$base/README.adoc" ]
then
target="$base/README.adoc"
type=adoc
fi
elif [ -f "$arg" ]
then
target=$arg
base=`dirname $arg`
if [ "${target#*.}" = "adoc" ]; then
type=adoc
fi
fi
# generate the header
cat header.html
# generate the side bar
echo ' <div id="side-bar">'
echo ' <div>'
echo ' <ul>'
for i in `find . -type d -depth 1`
do
i=`echo $i | sed -e 's/\.\///'`
if [ "$i" = ".git" ]; then
continue
elif [ "$i" = "$base" ]; then
# TODO (lojikil) currently only matches on depth
# we need to check prefixes...
echo ' <li> <a href="/'$i'">› ' $i '</a></li>'
echo ' <li>'
echo ' <ul>'
for d in `find $i -type d -depth 1`
do
d=`echo $d | sed -e 's/\.\///'`
echo ' <li><a href="/'$d'">›' $d '</a></li>'
done
echo ' </ul>'
echo ' </li>'
else
echo ' <li> <a href="/'$i'">›' $i '</a></li>'
fi
done
echo ' </ul>'
echo ' </div>'
echo ' </div>'
echo
echo
echo ' <div id="main-copy">'
if [ -f "$target" ]
then
if [ "$type" = "adoc" ]
then
asciidoctor -b docbook $target -o - | pandoc -f docbook -t html
else
pandoc -f markdown -t html $target
fi
else
# should probably support doing this regardless, so that you
# can have an index.txt as well as a directory content dump
# additionally, can be used for Gopher/Gemini as well...
# lastly, should support symlinking index.txt to README.md
echo '<h1>Directory Contents</h1>'
echo '<ul>'
for g in `find $base -depth 1`
do
echo '<li><a href="/'$g'">'$g'</a></li>'
done
echo '</ul>'
fi
echo ' </div>'
cat footer.html