-
Notifications
You must be signed in to change notification settings - Fork 6
/
ss
executable file
·123 lines (106 loc) · 3.08 KB
/
ss
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
116
117
118
119
120
121
122
123
#!/usr/bin/env bash
# simple-static site generator
# Blacklist filter (BLACKLIST in the config file)
ss_filter() {
for b in $BLACKLIST; do
[ "$b" = "$1" ] && return 0
done
}
ss_menu() {
echo "<ul>"
# For conditional directory navigation
# [ -z "`echo $1 | grep index.md`" ] && echo "<li><a href=\"index.html\">.</a></li>"
# [ "`dirname $1`" != "." ] && echo "<li><a href=\"../index.html\">..</a></li>"
echo "<li><a href=\"index.html\">.</a></li>"
echo "<li><a href=\"../index.html\">..</a></li>"
FILES=`ls \`dirname $1\` | sed -e 's/\.md$/.html/g'`
for i in $FILES ; do
ss_filter $i && continue
NAME=`echo $i | sed -e 's/\..*$//'`
[ -z "`echo $i | grep '\..*$'`" ] && i="$i/index.html"
echo "<li><a href=\"$i\">$NAME</a></li>"
done
echo "</ul>"
}
ss_page() {
# Header
cat << _header_
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8" lang="en"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9" lang="en"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
<head>
<title>${TITLE}</title>
<!-- <link rel="icon" href="/favicon.png" type="image/png"> -->
<meta charset="utf-8">
_header_
# Stylesheet
ss_style
cat << _header_
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet">
<script type="text/javascript" async src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML"></script>
</head>
<body>
<header>
<h1>
<a href="`echo $1 | sed -e 's|[^/]*/|../|g' -e 's|[^/]*\.md$|index.html|g'`">${TITLE}</a> <span>${SUBTITLE}</span>
</h1>
_header_
# Menu
echo " <nav>"
ss_menu $1
echo " </nav>"
echo " </header>"
# Body
echo "<div id=\"main\">"
$MDHANDLER $1
echo "</div>"
# Footer
cat << _footer_
<footer>
<div class="right"><a href="http://github.com/wlangstroth/simple-static">Powered by simple-static</a></div>
</footer>
</body>
</html>
_footer_
}
ss_style() {
if [ -f $WORKING_DIR/style.css ]; then
echo '<style>'
cat $WORKING_DIR/style.css
echo '</style>'
fi
}
# ------------------------------------------------------------------------------
# Moin routine
# ------------------------------------------------------------------------------
INPUT_DIR="`echo $1 | sed -e 's|/*$||'`"
if [ -z "$INPUT_DIR" ] || [ ! -d $INPUT_DIR ]; then
echo "Usage: ss [dir]"
exit 1
fi
# Load config file
if [ ! -f ss.conf ]; then
echo "Cannot find ss.conf in current directory"
exit 1
fi
. ss.conf
WORKING_DIR=$PWD
OUTPUT_DIR="$WORKING_DIR/`basename $INPUT_DIR`.static"
rm -rf $OUTPUT_DIR
mkdir -p $OUTPUT_DIR
cp -rf $INPUT_DIR/* $OUTPUT_DIR
rm -f `find $OUTPUT_DIR -type f -iname '*.md'`
# Parse and generate
cd $INPUT_DIR
FILES=`find . -iname '*.md' | sed -e 's|^\./||'`
for a in $FILES; do
b="$OUTPUT_DIR/`echo $a | sed -e 's|\.md$|.html|g'`"
echo "* $a"
ss_page $a > $b;
done
exit 0