move view icon to beginning of each hCalendar
[HTML5TV.git] / bin / calendar.pl
1 #!/usr/bin/perl
2
3 use warnings;
4 use strict;
5
6 use lib 'lib';
7 use HTML5TV::hCalendar;
8 use File::Slurp;
9 use XML::FeedPP;
10
11 my $url = 'http://html5tv.rot13.org';
12
13 my $html = qq|<!DOCTYPE html>
14 <html>
15
16 <head>
17 <meta charset="utf-8" />
18
19 <link rel="alternate" type="application/rss+xml" title="RSS" href="calendar.xml">
20
21 <link rel="icon" type="image/png" href="media/favicon.png">
22
23 <script src="js/jquery-1.3.2.min.js" type="text/javascript"></script>
24
25 <script src="js/jqueryhcal/jqueryhcal.js" type="text/javascript"></script>
26 <link rel="stylesheet" type="text/css" href="js/jqueryhcal/jqueryhcal.css" />
27
28 <link rel="stylesheet" type="text/css" href="hcalendar.css" />
29 <style type="text/css">
30
31 .watch {
32         margin-right: 0.1em;
33 }
34
35 </style>
36
37 <title>HTML5TV all media available</title>
38
39 </head>
40
41 <body>
42
43 <div id="jhCalendar"></div>
44
45 |;
46
47 my $vevents;
48 my $feed = XML::FeedPP::RSS->new;
49 $feed->title( 'HTML5TV' );
50 $feed->link( $url );
51
52 foreach my $path ( glob 'media/*/hCalendar.html' ) {
53         next if $path =~ m{_editing};
54         warn "+ $path\n";
55
56         my $hcal = HTML5TV::hCalendar->new( $path );
57
58         my $media = (split(/\//, $path))[1];
59
60         if ( ! -e "www/$media.html" ) {
61                 warn "NO www/$media.html $!";
62                 next;
63         }
64
65         my $html = $hcal->as_HTML(
66                 [ 'span', { class => 'watch' },
67                         [ 'a', { href => "$media.html", title => $media, },
68                                 [ 'img', { src => 'media/favicon.png', border => 0 } ],
69                         ]
70                 ]
71         );
72
73         $vevents->{ $hcal->dtstart_iso } = $html;
74
75         my $pubDate = $hcal->dtstart_iso;
76         $pubDate =~ s{^(\d\d\d\d)(\d\d)(\d\d).*$}{$1-$2-$3};
77
78         my $item = $feed->add_item( "$url/$media.html" );
79         $item->title( $hcal->summary );
80         $item->pubDate( $pubDate );
81         $item->description( $html );
82 }
83
84 $feed->to_file( 'www/calendar.xml' );
85
86 $html .= join("\n", map { $vevents->{$_} } sort keys %$vevents );
87
88 $html .= qq|
89
90 <a href="calendar.xml">rss</a>
91
92 </body>
93 </html>
94
95 |;
96
97 write_file 'www/calendar.html', $html;