~darklands/teal

ref: 120c95060836fef7e32c7ec5139bf9b231653c6f teal/teal -rwxr-xr-x 2.1 KiB
120c9506 — Ben O'Neill update license 4 months ago
                                                                                
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
#!/bin/sh

teal_compile() { \
	cat >> $2 << EOF
<div id="main">
EOF
	$MDC $1 >> $2
cat >> $2 << EOF
</div>
EOF

	echo "MDC $1 >> $2"
}

teal_head() { \
	. $2
	[ "$1" = "$TARGET/index.html" ] && NAME="$TITLE"
	cat > $1 << EOF
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/png" href="/favicon.png" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="Content-Language" content="en" />
<meta content="width=device-width" name="viewport" />
<meta content="$KEYWORDS" name="keywords" />
<meta content="$DESCRIPTION" name="description" />
<title>$NAME</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
EOF
	echo "HTMLINFO $1"
}

teal_sidebar() { \
	cat >> $1 << EOF
<div id="side-bar">
<span>
EOF
	[ ! -z "$SIDEBAR_SOURCES" ] && for file in $(echo $SIDEBAR_SOURCES | tr ' ' '\n' | sed "s|^|$SRC/|"); do
		. $(echo $file | sed 's/md$/sh/')
		cat >> $1 << EOF
<a href="$(echo $file | sed "s,$SRC/,,;s/\.md/\.html/")">$NAME</a>
EOF
	done
	for ep in $EXTRA_PAGES; do
		cat >> $1 << EOF
<a href="$(echo $ep | sed 's/,.*$//')">$(echo $ep | sed 's/.*,//')</a>
EOF
	done
	cat >> $1 << EOF
</span>
</div>
</span>
</div>
EOF
}

teal_header() { \
	cat >> $1 << EOF
<div id="header">
<span>
<img src="banner.png" />
EOF
}

teal_footer() { \
	cat >> $1 << EOF
<div id="footer">
<p>$FOOTER</p>
</div>
EOF
}

teal_end() { \
	cat >> $1 << EOF
</body>
</html>
EOF
}

teal_loop() { \
	# copy all necessary files from source dir to target dir
	mkdir -p $TARGET
	cp -rf $SRC/* $TARGET
	cp -f style.css $TARGET

	# remove the source files
	for f in $(find $TARGET | egrep '(md)|(sh)$'); do
		rm -f $f
	done

	for f in $SOURCES; do
		settings="$SRC/$(echo $f | sed "s/\.md/\.sh/;/^$/d")"
		out="$TARGET/$(echo $f | sed "s/\.md/\.html/;/^$/d")"
		teal_head $out $settings
		teal_header $out
		teal_sidebar $out
		teal_compile "$SRC/$f" $out
		[ ! -z "$FOOTER" ] && teal_footer $out
		teal_end $out $settings
	done
}


[ ! -f "teal.conf" ] && echo "no teal.conf found! must abort." && exit 1
[ ! -f "style.css" ] && echo "no style.css found! must abort." && exit 1

. ./teal.conf
teal_loop