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