about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rwxr-xr-xvienna119
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
26PARAMETERS: 26PARAMETERS:
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
188publish() { 190_publish() {
189 cat <<EOF >&2 191 cat <<EOF >&2
190 192
191I want to publish your website but I don't know how. 193I want to publish your website but I don't know how.
192Make a $CONFIG file in this directory and write a \`publish' 194$(if test -f "$CONFIG";
193function telling me what to do. I recommend using \`rsync', 195then echo "Edit the";
194but you live your life." 196else echo "Write a";
197fi) \`publish' function in the \`$CONFIG' file in this
198directory that tells me what to do.
195 199
196EOF 200EOF
197 exit 3 201 exit 3
198} 202}
203alias publish=_publish
199 204
200preview() { 205_preview() {
201 cat <<EOF >&2 206 cat <<EOF >&2
202 207
203I want to show you a preview of your website but I don't 208I want to show you a preview of your website but I don't
204know how. Make a $CONFIG file in this directory and write 209know how. $(if test -f "$CONFIG";
205a \`preview' function telling me what to do. I recommend 210then echo "Edit the";
206using something like \`python -m http.server', but you live 211else echo "Write a";
207your life." 212fi) \`preview' function in the \`$CONFIG' file
213in this directory that tells me what to do.
208 214
209EOF 215EOF
210 exit 3 216 exit 3
211} 217}
218alias preview=_preview
219
220initialize() { # initialize
221 cat >"$CONFIG" <<EOF
222# .vienna.sh
223DOMAIN="$DOMAIN"
224OUTD="$OUTD"
225PAGE_TEMPLATE="$PAGE_TEMPLATE"
226INDEX_TEMPLATE="$INDEX_TEMPLATE"
227FEED_TEMPLATE="$FEED_TEMPLATE"
228
229# Edit this with your web server's file path
230WWW_ROOT=
231
232preview() {
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
248publish() {
249 if [ -n "$WWW_ROOT" ]; then
250 rsync -avzP --delete "$OUTD/" "$WWW_ROOT/"
251 else
252 _preview
253 fi
254}
255EOF
256 cat >"$PAGE_TEMPLATE" <<\EOF
257<title>$$(title)</title>
258$$(body)
259EOF
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>
266EOF
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>
275EOF
276}
212 277
213### Utility 278### Utility
214 279