diff options
-rwxr-xr-x | vienna | 39 |
1 files changed, 24 insertions, 15 deletions
diff --git a/vienna b/vienna index 3077dcb..578a4b8 100755 --- a/vienna +++ b/vienna | |||
@@ -51,24 +51,23 @@ configure() { | |||
51 | FEED_TEMPLATE="${VIENNA_FEED_TEMPLATE:-.feed.tmpl.xml}" | 51 | FEED_TEMPLATE="${VIENNA_FEED_TEMPLATE:-.feed.tmpl.xml}" |
52 | # File extensions | 52 | # File extensions |
53 | PAGE_RAW_EXT="${VIENNA_PAGE_RAW_EXT:-htm}" | 53 | PAGE_RAW_EXT="${VIENNA_PAGE_RAW_EXT:-htm}" |
54 | ## Source ./.vienna.sh, if it exists. | 54 | # Logging |
55 | # Sourcing it here lets it override any environment variables, and it to | 55 | LOG=true |
56 | # be overridden by command-line flags. | ||
57 | test -f "$CONFIG" && . "$CONFIG" | ||
58 | ## Parse command line arguments | 56 | ## Parse command line arguments |
59 | while getopts d:C:o:h opt; do | 57 | while getopts d:C:o:hq opt; do |
60 | case "$opt" in | 58 | case "$opt" in |
61 | d) DOMAIN="$OPTARG" ;; | 59 | d) DOMAIN="$OPTARG" ;; |
62 | C) WORKD="$OPTARG" ;; | 60 | C) WORKD="$OPTARG" ;; |
63 | o) OUTD="$OPTARG" ;; | 61 | o) OUTD="$OPTARG" ;; |
64 | h) usage 0 ;; | 62 | h) usage 0 ;; |
63 | q) LOG=false ;; | ||
65 | *) exit 1 ;; | 64 | *) exit 1 ;; |
66 | esac | 65 | esac |
67 | done | 66 | done |
68 | ## Log configuration variables | 67 | ## Log configuration variables |
69 | echo >&2 "[config] domain: $DOMAIN" | 68 | log config "domain: $DOMAIN" |
70 | echo >&2 "[config] workdir: $WORKD" | 69 | log config "workdir: $WORKD" |
71 | echo >&2 "[config] output: $OUTD" | 70 | log config "output: $OUTD" |
72 | ## Initialize state | 71 | ## Initialize state |
73 | FILE= | 72 | FILE= |
74 | ## Cleanup after we're done | 73 | ## Cleanup after we're done |
@@ -87,7 +86,7 @@ main() { | |||
87 | case "${1:-ok}" in | 86 | case "${1:-ok}" in |
88 | ok) ;; | 87 | ok) ;; |
89 | clean) | 88 | clean) |
90 | echo >&2 "[vienna] clean" | 89 | log vienna "clean" |
91 | rm -r "$OUTD" | 90 | rm -r "$OUTD" |
92 | exit | 91 | exit |
93 | ;; | 92 | ;; |
@@ -114,15 +113,15 @@ main() { | |||
114 | case "${1:-ok}" in | 113 | case "${1:-ok}" in |
115 | ok) ;; | 114 | ok) ;; |
116 | publish) | 115 | publish) |
117 | echo >&2 "[vienna] publish" | 116 | log vienna "publish" |
118 | publish "$OUTD" | 117 | publish "$OUTD" |
119 | ;; | 118 | ;; |
120 | preview) | 119 | preview) |
121 | echo >&2 "[vienna] preview" | 120 | log vienna "preview" |
122 | preview "$OUTD" | 121 | preview "$OUTD" |
123 | ;; | 122 | ;; |
124 | *) | 123 | *) |
125 | echo >&2 "[vienna] Don't know command \`$1'." | 124 | log vienna "Don't know command \`$1'." |
126 | exit 1 | 125 | exit 1 |
127 | ;; | 126 | ;; |
128 | esac | 127 | esac |
@@ -159,6 +158,16 @@ EOF | |||
159 | exit 3 | 158 | exit 3 |
160 | } | 159 | } |
161 | 160 | ||
161 | ### Utility | ||
162 | |||
163 | log() { | ||
164 | if "$LOG"; then | ||
165 | t="$1" | ||
166 | shift | ||
167 | echo >&2 "[$t]" "$@" | ||
168 | fi | ||
169 | } | ||
170 | |||
162 | ### File processing | 171 | ### File processing |
163 | 172 | ||
164 | ## Building block functions | 173 | ## Building block functions |
@@ -230,7 +239,7 @@ build() { # build PAGE... | |||
230 | # Outputs a file of the format $OUTD/<PAGE>/index.html. | 239 | # Outputs a file of the format $OUTD/<PAGE>/index.html. |
231 | test -f "$PAGE_TEMPLATE" || return 1 | 240 | test -f "$PAGE_TEMPLATE" || return 1 |
232 | for FILE; do | 241 | for FILE; do |
233 | echo >&2 "[build] $FILE" | 242 | log build "$FILE" |
234 | outd="$OUTD/${FILE%.$PAGE_RAW_EXT}" | 243 | outd="$OUTD/${FILE%.$PAGE_RAW_EXT}" |
235 | outf="$outd/index.html" | 244 | outf="$outd/index.html" |
236 | tmpf="$TMPD/$FILE.tmp" | 245 | tmpf="$TMPD/$FILE.tmp" |
@@ -245,7 +254,7 @@ index() { # index PAGE... | |||
245 | # Wraps each PAGE in a <li><a> structure. | 254 | # Wraps each PAGE in a <li><a> structure. |
246 | test -f "$INDEX_TEMPLATE" || return 1 | 255 | test -f "$INDEX_TEMPLATE" || return 1 |
247 | for FILE; do | 256 | for FILE; do |
248 | echo >&2 "[index] $FILE" | 257 | log index "$FILE" |
249 | link="$DOMAIN${DOMAIN:+/}${FILE%.$PAGE_RAW_EXT}" | 258 | link="$DOMAIN${DOMAIN:+/}${FILE%.$PAGE_RAW_EXT}" |
250 | echo "<li><a href=\"$link\">$(meta title "$FILE")</a></li>" | 259 | echo "<li><a href=\"$link\">$(meta title "$FILE")</a></li>" |
251 | done | expand "$INDEX_TEMPLATE" >"$OUTD/index.html" | 260 | done | expand "$INDEX_TEMPLATE" >"$OUTD/index.html" |
@@ -255,7 +264,7 @@ feed() { # feed PAGE... | |||
255 | ## Build an RSS 2.0 feed from PAGE(s). | 264 | ## Build an RSS 2.0 feed from PAGE(s). |
256 | test -f "$FEED_TEMPLATE" || return 1 | 265 | test -f "$FEED_TEMPLATE" || return 1 |
257 | for FILE; do | 266 | for FILE; do |
258 | echo >&2 "[feed] $FILE" | 267 | log feed "$FILE" |
259 | link="$DOMAIN${DOMAIN:+/}${FILE%.$PAGE_RAW_EXT}" | 268 | link="$DOMAIN${DOMAIN:+/}${FILE%.$PAGE_RAW_EXT}" |
260 | date="$(meta pubdate "$FILE")" | 269 | date="$(meta pubdate "$FILE")" |
261 | echo "<item>" | 270 | echo "<item>" |