generate.rc (4076B)
1 #!/bin/rc 2 3 cd `$nl{dirname $0} 4 5 fn compile { 6 if (!ldd $1/$1 >/dev/null) { 7 make -C $1 clean && make -C $1 8 } else { 9 make -C $1 10 } 11 } 12 13 compile stagit 14 ./stagit-create.rc 15 16 compile stagit-gopher 17 ./stagit-gopher-create.rc 18 19 notesdir = ../notes/ 20 21 fn atomentry { 22 file=$1 base=$2 atom=$3 title=$4 url=$5 { 23 printf '\t<entry>\n' >> $atom 24 printf '\t\t<title>%s</title>\n' $title >> $atom 25 printf '\t\t<link href="%s" />\n' $url/$base >> $atom 26 27 if (!test -f $f.uuid) { 28 uuid = `{uuidgen | tee $f.uuid} 29 } else { 30 uuid = `{cat $f.uuid} 31 } 32 printf '\t\t<id>urn:uuid:%s</id>\n' $uuid >> $atom 33 34 if (!test -f $f.published) { 35 published = `{date +'%Y-%m-%dT%H:%M:%S' | tee $f.published} 36 } else { 37 published = `{cat $f.published} 38 } 39 printf '\t\t<published>%s</published>\n' $published >> $atom 40 printf '\t\t<updated>%s</updated>\n' `{dateconv -i '%s' `{stat -c '%Y' $f} -f '%Y-%m-%dT%H:%M:%S'} >> $atom 41 printf '\t\t<author>\n' >> $atom 42 printf '\t\t\t<name>hhvn</name>\n' >> $atom 43 printf '\t\t\t<email>hhvn AT hhvn DOT uk</email>\n' >> $atom 44 printf '\t\t</author>\n' >> $atom 45 printf '\t</entry>\n' >> $atom 46 } 47 } 48 49 # Blog generation 50 webatom = ../www/blog/feed.xml 51 blog = ../www/blog/index.html 52 blogdir = ../www/blog 53 54 mkdir -p $blogdir 55 56 rm $blogdir/* 57 for (f in $notesdir/*) { 58 cp $f $blogdir/ ^ `$nl{basename $f} 59 } 60 61 cat > $blog <<'EOF' 62 <!DOCTYPE html> 63 <html> 64 <head> 65 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 66 <meta name="viewport" content="width=device-width, initial-scale=1" /> 67 <title>hhvn's blog</title> 68 <link rel="stylesheet" type="text/css" href="../index.css" /> 69 </head> 70 <body> 71 <h1>hhvn's blog</h1> 72 <hr /> 73 <a href="/">Back to /</a> <span class="vl"> </span><a href="./feed.xml">Atom feed</a> <span class="vl"> </span><a href="gopher://hhvn.uk/phlog">Phlog</a> 74 <hr /> 75 76 EOF 77 78 cat > $webatom <<'EOF' 79 <?xml version="1.0" encoding="utf-8"?> 80 <feed xmlns="http://www.w3.org/2005/Atom"> 81 <title>hhvn's blog</title> 82 <subtitle>Notes and stuff. Also available at gopher://hhvn.uk/1/phlog</subtitle> 83 <link href="http://hhvn.uk/blog/feed.xml" rel="self" /> 84 <link href="gopher://hhvn.uk/phlog/feed.xml" /> 85 <link href="http://hhvn.uk/" /> 86 <link href="gopher://hhvn.uk/" /> 87 EOF 88 89 fn recent { 90 test `{datediff -f '%d' $1 now} -le 5 91 } 92 93 {for (f in $notesdir/*.txt) { 94 base = `$nl{basename $f} 95 title = `$nl{grep '^Title: ' < $f | sed 's/[^ ]* //'} 96 date = `$nl{grep '^Date: ' < $f | sed 's/[^ ]* //'} 97 updated = `$nl{grep '^Upated: ' < $f | sed 's/[^ ]* //;s/ .*//'} 98 99 if (recent $date || {!~ $updated () && recent $updated}) { 100 recent = '<b style="color:#00aa00 !important;">[NEW]</b> ' 101 } else { 102 recent = ' ' 103 } 104 105 atomentry $f $base $webatom $title http://hhvn.uk/blog 106 107 printf '[%s] %s<a href="./%s">%s</a><br />\n' \ 108 $date $recent $base $title 109 }} | sort -r >> $blog 110 111 cat >> $blog <<'EOF' 112 </body> 113 EOF 114 115 cat >> $webatom <<'EOF' 116 </feed> 117 EOF 118 119 # Phlog generation 120 gphatom = ../gopher/phlog/feed.xml 121 phlog = ../gopher/phlog/index.gph 122 phlogdir = ../gopher/phlog 123 124 mkdir -p $phlogdir 125 126 rm $phlogdir/* 127 for (f in $notesdir/*) { 128 cp $f $phlogdir/ ^ `$nl{basename $f} 129 } 130 131 cat > $phlog <<'EOF' 132 Welcome to hhvn's phlog. 133 134 [0|Atom feed|feed.xml|server|port] 135 136 EOF 137 138 cat > $gphatom <<'EOF' 139 <?xml version="1.0" encoding="utf-8"?> 140 <feed xmlns="http://www.w3.org/2005/Atom"> 141 <title>hhvn's phlog</title> 142 <subtitle>(Bank)notes and (food)stuff(s).<subtitle> 143 <link href="gopher://hhvn.uk/phlog/feed.xml" rel="self" /> 144 <link href="gopher://hhvn.uk/" /> 145 EOF 146 147 {for (f in $notesdir/*.txt) { 148 base = `$nl{basename $f} 149 title = `$nl{grep '^Title: ' < $f | sed 's/[^ ]* //'} 150 date = `$nl{grep '^Date: ' < $f | sed 's/[^ ]* //'} 151 updated = `$nl{grep '^Upated: ' < $f | sed 's/[^ ]* //;s/ .*//'} 152 153 if (recent $date || {!~ $updated () && recent $updated}) { 154 recent = '[NEW]' 155 } else { 156 recent = ' ' 157 } 158 159 atomentry $f $base $gphatom $title gopher://hhvn.uk/0/phlog 160 161 printf '[0|[%s] %s %s|/phlog/%s|server|port]\n' \ 162 $date $recent $title $base 163 }} | sort -r >> $phlog 164 165 cat >> $gphatom <<'EOF' 166 </feed> 167 EOF