3 # This is a simple script that will produce my blog on repo.or.cz
5 # The idea is to have source-<timestamp>.txt files as input, having the
6 # stories, and this script turning them into nice HTML, committing
7 # everything, and then pushing it to my repository.
9 # The blog will then be served using gitweb.
11 # To make it easier on me, if a file "source.txt" exists, it is
12 # automatically renamed using the current timestamp.
14 # TODO: handle images (git add them and rewrite the URL dynamically)
15 # TODO: generate an RSS feed, too
18 URL
="dscho.git?a=blob_plain;hb=$BRANCH;f="
34 # add illogical suffix
36 *1?|
*[04-9]) echo "$1th";;
43 make_chinese_hour
() {
74 make_roman_number
() {
77 ?
) digit_to_roman
$1 I V X
;;
78 ??
) echo $
(digit_to_roman
${1%?} X L C
)$
(make_roman_number
${1#?});;
79 ???
) echo $
(digit_to_roman
${1%??} C D M
)$
(make_roman_number
${1#?});;
80 ????
) echo $
(digit_to_roman
${1%???} M
)$
(make_roman_number
${1#?});;
85 printf "%s, %s of %s, Anno Domini %s, at the hour of the %s\n" \
87 $
(nth $
(date +%e
-d @
$1)) \
89 $
(make_roman_number $
(date +%Y
-d @
$1)) \
90 $
(make_chinese_hour $
(date +%H
-d @
$1))
93 # make an argument for sed, to replace $1..$1 by <$2>..</$2>
94 markup_substitution
() {
96 ?
) echo "s/$1\\([^$1]*\\)$1/<$2>\\\\1<\/$2>/g";;
99 tmp2
="\\|${1%?}[^${1#?}]$tmp"
100 tmp3
="\\($tmp\\($tmp2\\($tmp2\\($tmp2\\)\\)\\)\\)"
101 echo "s/$1$tmp3$1/<$2>\\\\1<\/$2>/g"
106 # transform markup in stdin to HTML
108 sed -e 's!^$!</p><p>!' \
109 -e 's!IMHO!in my humble opinion!g' \
110 -e 's!repo.or.cz!<a href=http://&>&</a>!g' \
111 -e 's!:-)!\☺!g' \
112 -e "$(markup_substitution "''" i)" \
113 -e "$(markup_substitution "_
" u)"
121 <title>$TITLE</title>
122 <meta http-equiv="Content-Type"
123 content="text/html; charset=UTF-8"/>
124 <link rel="stylesheet" type="text/css" href="$URL$CSS">
131 # timestamps will not need padding to sort correctly, for some time...
132 for file in $
(ls -r source-
*.txt
)
134 basename=${file%.txt}
135 timestamp
=${basename#source-}
136 echo "<h6>$(make_date $timestamp)</h6>"
137 echo "<h2>$(sed 1q < $file | markup)</h2>"
140 sed 1d
< $file | markup
143 sed -e 's/^./\t\t\t&/'
153 # make sure we're in the correct working directory
156 # parse command line option
158 *dry
*) DRYRUN
=1; shift;;
159 *show
*) firefox
"$(pwd)"/$TEST; exit;;
160 *remote
*) firefox http
://repo.or.cz
/w
/git
/$URL$OUTPUT; exit;;
164 die
"Usage: $0 [--dry-run]"
166 # make sure we're on the correct branch
167 test refs
/heads
/$BRANCH = $
(git symbolic-ref HEAD
) ||
168 die
"Not on branch $BRANCH"
170 # make sure there are no uncommitted changes
171 git update-index
--refresh &&
172 git diff-files
--quiet &&
173 git diff-index
--quiet --cached HEAD ||
174 die
"Have uncommitted changes!"
176 # rename the new blog entry if it exists
179 mv -i $NEW source-
$now.txt
&&
180 git add source-
$now.txt
182 die
"Could not rename source.txt"
187 sed -e "s/url(/&$URL/g" < $CSS.
in > $CSS &&
189 die
"Rewriting $CSS failed"
196 make_html
> $OUTPUT || die
"Could not write $OUTPUT"
198 test ! -z "$DRYRUN" && exit
201 git commit
-s -m "Update $(make_date $now)" &&
202 git push origin
+$BRANCH