diff options
-rwxr-xr-x | vienna | 119 |
1 files changed, 92 insertions, 27 deletions
diff --git a/vienna b/vienna index e88941d..c969948 100755 --- a/vienna +++ b/vienna | |||
@@ -24,7 +24,8 @@ OPTIONS: | |||
24 | -o DIR output built site to DIR. default: ./out | 24 | -o DIR output built site to DIR. default: ./out |
25 | 25 | ||
26 | PARAMETERS: | 26 | PARAMETERS: |
27 | clean remove output directory before building | 27 | init initialize a vienna site with default files and exit. |
28 | clean remove output directory before building. | ||
28 | publish publish the site after building. | 29 | publish publish the site after building. |
29 | NOTE: this requires a .vienna.sh file in the site root. | 30 | NOTE: this requires a .vienna.sh file in the site root. |
30 | you'll have to define a \`publish' function there. | 31 | you'll have to define a \`publish' function there. |
@@ -109,18 +110,12 @@ main() { | |||
109 | log config index.tmpl: "$INDEX_TEMPLATE" | 110 | log config index.tmpl: "$INDEX_TEMPLATE" |
110 | log config feed.tmpl: "$FEED_TEMPLATE" | 111 | log config feed.tmpl: "$FEED_TEMPLATE" |
111 | ## Plugins | 112 | ## Plugins |
112 | # Plugins are .*.sh files in build directory. They're sourced here. | 113 | # Plugins are *.sh files in $WORKD/.plugins/. They're sourced here. |
113 | if gencheckglob './.*.sh' ./.*.sh; then | 114 | for plugin in ./.*.sh; do |
114 | for plugin in ./.*.sh; do | 115 | test -f "$plugin" || continue |
115 | case "$plugin" in | 116 | log plugin "$plugin" |
116 | *"$CONFIG"*) continue ;; | 117 | . "$plugin" |
117 | *) | 118 | done |
118 | log plugin "$plugin" | ||
119 | . "$plugin" | ||
120 | ;; | ||
121 | esac | ||
122 | done | ||
123 | fi | ||
124 | mkdir -p "$OUTD" || exit 2 | 119 | mkdir -p "$OUTD" || exit 2 |
125 | mkdir -p "$TMPD" || exit 2 | 120 | mkdir -p "$TMPD" || exit 2 |
126 | # Build pages | 121 | # Build pages |
@@ -148,16 +143,23 @@ preprocess() { | |||
148 | 143 | ||
149 | case "${1:-ok}" in | 144 | case "${1:-ok}" in |
150 | ok) ;; | 145 | ok) ;; |
146 | init) | ||
147 | log vienna initializing... | ||
148 | shift | ||
149 | initialize "$@" | ||
150 | log vienna initialized. | ||
151 | exit | ||
152 | ;; | ||
151 | clean) | 153 | clean) |
152 | log vienna clean | 154 | log vienna clean |
153 | rm -r "$OUTD" | 155 | rm -r "$OUTD" |
154 | cleanup | 156 | cleanup |
155 | if [ $# -eq 0 ]; then | 157 | if [ $# -eq 0 ]; then |
156 | exit # Quit when only cleaning | 158 | exit # Quit when only cleaning |
157 | else | 159 | else |
158 | return 1 # Otherwise, continue processing | 160 | return 1 # Otherwise, continue processing |
159 | fi | 161 | fi |
160 | ;; | 162 | ;; |
161 | esac | 163 | esac |
162 | } | 164 | } |
163 | 165 | ||
@@ -185,30 +187,93 @@ cleanup() { | |||
185 | rm -r "$TMPD" | 187 | rm -r "$TMPD" |
186 | } | 188 | } |
187 | 189 | ||
188 | publish() { | 190 | _publish() { |
189 | cat <<EOF >&2 | 191 | cat <<EOF >&2 |
190 | 192 | ||
191 | I want to publish your website but I don't know how. | 193 | I want to publish your website but I don't know how. |
192 | Make a $CONFIG file in this directory and write a \`publish' | 194 | $(if test -f "$CONFIG"; |
193 | function telling me what to do. I recommend using \`rsync', | 195 | then echo "Edit the"; |
194 | but you live your life." | 196 | else echo "Write a"; |
197 | fi) \`publish' function in the \`$CONFIG' file in this | ||
198 | directory that tells me what to do. | ||
195 | 199 | ||
196 | EOF | 200 | EOF |
197 | exit 3 | 201 | exit 3 |
198 | } | 202 | } |
203 | alias publish=_publish | ||
199 | 204 | ||
200 | preview() { | 205 | _preview() { |
201 | cat <<EOF >&2 | 206 | cat <<EOF >&2 |
202 | 207 | ||
203 | I want to show you a preview of your website but I don't | 208 | I want to show you a preview of your website but I don't |
204 | know how. Make a $CONFIG file in this directory and write | 209 | know how. $(if test -f "$CONFIG"; |
205 | a \`preview' function telling me what to do. I recommend | 210 | then echo "Edit the"; |
206 | using something like \`python -m http.server', but you live | 211 | else echo "Write a"; |
207 | your life." | 212 | fi) \`preview' function in the \`$CONFIG' file |
213 | in this directory that tells me what to do. | ||
208 | 214 | ||
209 | EOF | 215 | EOF |
210 | exit 3 | 216 | exit 3 |
211 | } | 217 | } |
218 | alias preview=_preview | ||
219 | |||
220 | initialize() { # initialize | ||
221 | cat >"$CONFIG" <<EOF | ||
222 | # .vienna.sh | ||
223 | DOMAIN="$DOMAIN" | ||
224 | OUTD="$OUTD" | ||
225 | PAGE_TEMPLATE="$PAGE_TEMPLATE" | ||
226 | INDEX_TEMPLATE="$INDEX_TEMPLATE" | ||
227 | FEED_TEMPLATE="$FEED_TEMPLATE" | ||
228 | |||
229 | # Edit this with your web server's file path | ||
230 | WWW_ROOT= | ||
231 | |||
232 | preview() { | ||
233 | export _PYTHON="$(command -v python3 || command -v python)" | ||
234 | if [ -n "$_PYTHON" ]; then | ||
235 | pkill -x "$_PYTHON" | ||
236 | "$_PYTHON" -m http.server -d "$OUTD" & | ||
237 | export _VIENNA_PID="$!" | ||
238 | find . -type f -not -path "*/$OUTD/*" | | ||
239 | OUTD="$OUTD" entr -rp \ | ||
240 | sh -c 'kill "$_VIENNA_PID" >/dev/null 2>&1; | ||
241 | vienna && "$_PYTHON" -m http.server -d "$OUTD"' | ||
242 | else | ||
243 | log error "\`python' not found." | ||
244 | _preview | ||
245 | fi | ||
246 | } | ||
247 | |||
248 | publish() { | ||
249 | if [ -n "$WWW_ROOT" ]; then | ||
250 | rsync -avzP --delete "$OUTD/" "$WWW_ROOT/" | ||
251 | else | ||
252 | _preview | ||
253 | fi | ||
254 | } | ||
255 | EOF | ||
256 | cat >"$PAGE_TEMPLATE" <<\EOF | ||
257 | <title>$$(title)</title> | ||
258 | $$(body) | ||
259 | EOF | ||
260 | cat >"$INDEX_TEMPLATE" <<\EOF | ||
261 | <title>a home page!</title> | ||
262 | <h1>hey! it's a home page of some sort!</h1> | ||
263 | <ul> | ||
264 | $$(body) | ||
265 | </ul> | ||
266 | EOF | ||
267 | cat >"$FEED_TEMPLATE" <<\EOF | ||
268 | <rss version="2.0"> | ||
269 | <channel> | ||
270 | <title>a feed!</title> | ||
271 | <link>$$BASEURL</link> | ||
272 | $$(body) | ||
273 | </channel> | ||
274 | </rss> | ||
275 | EOF | ||
276 | } | ||
212 | 277 | ||
213 | ### Utility | 278 | ### Utility |
214 | 279 | ||