From 6f5b531f9e2acd182039a2664e318808953774a8 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Sat, 7 Jan 2023 20:32:54 -0600 Subject: Add `init' command Initializes the current directory with some vienna stuff --- vienna | 119 ++++++++++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 92 insertions(+), 27 deletions(-) diff --git a/vienna b/vienna index e88941d..c969948 100755 --- a/vienna +++ b/vienna @@ -24,7 +24,8 @@ OPTIONS: -o DIR output built site to DIR. default: ./out PARAMETERS: - clean remove output directory before building + init initialize a vienna site with default files and exit. + clean remove output directory before building. publish publish the site after building. NOTE: this requires a .vienna.sh file in the site root. you'll have to define a \`publish' function there. @@ -109,18 +110,12 @@ main() { log config index.tmpl: "$INDEX_TEMPLATE" log config feed.tmpl: "$FEED_TEMPLATE" ## Plugins - # Plugins are .*.sh files in build directory. They're sourced here. - if gencheckglob './.*.sh' ./.*.sh; then - for plugin in ./.*.sh; do - case "$plugin" in - *"$CONFIG"*) continue ;; - *) - log plugin "$plugin" - . "$plugin" - ;; - esac - done - fi + # Plugins are *.sh files in $WORKD/.plugins/. They're sourced here. + for plugin in ./.*.sh; do + test -f "$plugin" || continue + log plugin "$plugin" + . "$plugin" + done mkdir -p "$OUTD" || exit 2 mkdir -p "$TMPD" || exit 2 # Build pages @@ -148,16 +143,23 @@ preprocess() { case "${1:-ok}" in ok) ;; + init) + log vienna initializing... + shift + initialize "$@" + log vienna initialized. + exit + ;; clean) - log vienna clean - rm -r "$OUTD" - cleanup - if [ $# -eq 0 ]; then + log vienna clean + rm -r "$OUTD" + cleanup + if [ $# -eq 0 ]; then exit # Quit when only cleaning else return 1 # Otherwise, continue processing fi - ;; + ;; esac } @@ -185,30 +187,93 @@ cleanup() { rm -r "$TMPD" } -publish() { +_publish() { cat <&2 I want to publish your website but I don't know how. -Make a $CONFIG file in this directory and write a \`publish' -function telling me what to do. I recommend using \`rsync', -but you live your life." +$(if test -f "$CONFIG"; +then echo "Edit the"; +else echo "Write a"; +fi) \`publish' function in the \`$CONFIG' file in this +directory that tells me what to do. EOF exit 3 } +alias publish=_publish -preview() { +_preview() { cat <&2 I want to show you a preview of your website but I don't -know how. Make a $CONFIG file in this directory and write -a \`preview' function telling me what to do. I recommend -using something like \`python -m http.server', but you live -your life." +know how. $(if test -f "$CONFIG"; +then echo "Edit the"; +else echo "Write a"; +fi) \`preview' function in the \`$CONFIG' file +in this directory that tells me what to do. EOF exit 3 } +alias preview=_preview + +initialize() { # initialize + cat >"$CONFIG" </dev/null 2>&1; + vienna && "$_PYTHON" -m http.server -d "$OUTD"' + else + log error "\`python' not found." + _preview + fi +} + +publish() { + if [ -n "$WWW_ROOT" ]; then + rsync -avzP --delete "$OUTD/" "$WWW_ROOT/" + else + _preview + fi +} +EOF + cat >"$PAGE_TEMPLATE" <<\EOF +$$(title) +$$(body) +EOF + cat >"$INDEX_TEMPLATE" <<\EOF +a home page! +

hey! it's a home page of some sort!

+
    +$$(body) +
+EOF + cat >"$FEED_TEMPLATE" <<\EOF + + + a feed! + $$BASEURL + $$(body) + + +EOF +} ### Utility -- cgit 1.4.1-21-gabe81