#!/usr/bin/perl -T # Copyright (C) 2007 王亮 # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public Licence as published by # the Free Software Foundation; either version 2, or (at your option) # any later version. # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public Licence for more details. use strict; use warnings; use CGI; use HTML::Pager; use File::Find; my @reports; find({ wanted => sub { my $name = $File::Find::name; return unless -f $name; if ($name =~ m{^\./(\d{4})/(\d{2})/(\d{2})\.html}) { my ($year, $month, $day) = ($1, $2, $3); my $link = "$year/$month/$day.html"; my $text = "$year年$month月$day日"; push @reports, { text => $text, href => $link }; } }, no_chdir => 1, }, "."); @reports = sort { $b->{text} cmp $a->{text} } @reports; my $num_of_reports = scalar @reports; my $list_reports_callback = sub { my ($offset, $rows) = @_; my @current_reports; for my $r ($offset .. $rows + $offset - 1) { last if $r == $num_of_reports; my $link = $reports[$r]->{href}; my $text = $reports[$r]->{text}; push @current_reports, [ qq($text) ]; } return \@current_reports; }; my $query = CGI->new; my $pager = HTML::Pager->new(query => $query, get_data_callback => $list_reports_callback, rows => $num_of_reports, page_size => 15,); print $query->header(-type=>'text/html', -charset=>'UTF-8'), $query->start_html(-title=>"历史数据", -lang=>'zh-CN'), $query->h1("历史数据"), $pager->output, $query->end_html;