12 "\u0414\u0435\u043a\u0430\u0431\u0440\u044f"
}
-proc year_header {year items} {
- return "<h2>$year \u0433\u043e\u0434</h2><ul>"
-# return "<table border=1 width=\"100%\" cellspacing=0><tr><td align=\"center\" colspan=\"$items\"><b><font size=+2>$year \u0433\u043e\u0434</font></td></tr>\n<tr>"
-}
+proc try_save { data filename } {
-proc year_footer {year} {
- return "</ul>"
-# return "</tr></table><p> </p>"
-}
+ if {[catch {
+ set f [open $filename "r"]
+ set d [read $f]
+ close $f
+ }]} {
+ set d ""
+ }
+ if {![string equal $data $d]} {
+ puts stderr "Writing $filename"
+ set f [open $filename "w"]
+ puts -nonewline $f $data
+ close $f
+ }
+}
proc out_item { month day place dir} {
global monName
- return "<li><a href=\"$dir\">$day $monName($month)</a> $place</li>"
-# return "<td align=center><a href=\"$dir\">$day $monName($month)<br>$place</a></td>"
+ return "<li><a href=\"$month.$day-$place\">$day $monName($month)</a> $place</li>\n"
}
-set f [open "index.html" w]
-puts $f "<HTML><HEAD><TITLE>\u0410\u0440\u0445\u0438\u0432 \u0444\u043e\u0442\u043e\u0433\u0440\u0430\u0444\u0438\u0439</TITLE></HEAD><BODY>
-<H1>\u0410\u0440\u0445\u0438\u0432 \u0444\u043e\u0442\u043e\u0433\u0440\u0430\u0444\u0438\u0439</H1>"
-foreach dirname [lsort -decreasing [glob *]] {
- if {![regexp {^(\d{4})\.(\d{2})\.(\d{2}(-\d{2})?)-(.*)$} $dirname \
+proc nextyearlink {year} {
+ if {![string length $year]} {
+ return " "
+ } else {
+ return "<a href=\"$year\">$year</a>"
+ }
+}
+set years "<HTML><HEAD><TITLE>\u0410\u0440\u0445\u0438\u0432 \u0444\u043e\u0442\u043e\u0433\u0440\u0430\u0444\u0438\u0439</TITLE></HEAD><BODY>
+<H1>\u0410\u0440\u0445\u0438\u0432
+\u0444\u043e\u0442\u043e\u0433\u0440\u0430\u0444\u0438\u0439</H1>\n<ul>\n"
+foreach dirname [lsort -decreasing [glob */*]] {
+ if {![regexp {^(\d{4})/(\d{2})\.(\d{2}(-\d{2})?)-(.*)$} $dirname \
match year month day xxx place]} {
continue
}
- lappend a($year) [list $month $day $place $dirname]
+ lappend a($year) [list $month $day $place [llength [glob $dirname/*.html]]]
}
-foreach y [lsort -decreasing [array names a]] {
- puts $f [year_header $y [llength $a($y)]]
+set html_finish "</ul>\n<hr><font size=\"-2\">Copyright © Vitus Wagner</font>\n</body></html>\n"
+set yearlist [lsort -decreasing [array names a]]
+for {set i 0} {$i<[llength $yearlist]} {incr i} {
+ set y [lindex $yearlist $i]
+ set title "\u0424\u043e\u0442\u043e\u0430\u0440\u0445\u0438\u0432 $y \u0433\u043e\u0434"
+ set yearindex "<HTML><HEAD><TITLE>$title</TITLE><HEAD>"
+ append yearindex "<table border=0><tr><td align=left>"
+ append yearindex [nextyearlink [lindex $yearlist [expr $i+1]]]
+ append yearindex "</td><td align=\"right\">"
+ append yearindex [nextyearlink [lindex $yearlist [expr $i-1]]]
+ append yearindex "</td><tr></table\n><h1>$title</h1>\n<ul>"
+ set dircount [llength $a($y)]
+ set count 0
foreach item $a($y) {
- puts $f [eval out_item $item]
- }
- puts $f [year_footer $y]
+ incr count [expr {[lindex $item 3]-1}]
+ append yearindex [eval out_item $item]
+ }
+ append yearindex $html_finish
+ try_save $yearindex "$y/index.html"
+ append years "<li><a href=\"$y\">$y</a> ($dircount \u0434\u043d\u0435\u0439, $count \u0444\u043e\u0442\u043e)\n"
}
-
-puts $f "</BODY></HTML>"
-close $f
+append years $html_finish
+try_save $years "index.html"