/[suikacvs]/markup/h2h/implementation/classic/generate-atom-feed.pl
Suika

Contents of /markup/h2h/implementation/classic/generate-atom-feed.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2.2.1 - (hide annotations) (download)
Sun Jan 29 12:38:51 2012 UTC (12 years, 10 months ago) by wakaba
Branch: norakuro-d
Changes since 1.2: +22 -34 lines
File MIME type: text/plain
Norakuro Diary customization

1 wakaba 1.2.2.1 #!/usr/bin/perl5.8.7
2 wakaba 1.1 use strict;
3     use utf8;
4    
5 wakaba 1.2.2.1 use lib qw</home/wakaba/work/manakai2/lib
6     /home/httpd/html/www/markup/html/whatpm>;
7 wakaba 1.1
8 wakaba 1.2.2.1 require Encode;
9    
10     our $REPOSITORY_PATH = q</home/wakaba/pub/kkd/>;
11     our $FEED_NAME = q<フログに対抗するために書いてる日記!>;
12     our $FEED_TAG = q<tag:2006-05-07,suika.fam.cx:norakuro/d/>;
13     our $BASE_URI = q<http://suika.fam.cx/norakuro/d/>;
14 wakaba 1.1 our $BASE_LANG = 'ja';
15     our $FEED_CURRENT_PATH = $REPOSITORY_PATH.'current.'.$BASE_LANG.'.atom';
16 wakaba 1.2.2.1 our $AUTHOR_NAME = q<のらくろ>;
17     our $AUTHOR_URI = undef;
18     our $AUTHOR_MAIL = q<norakuro->.q<comment>.q<@>.q<suika>.q<.fam.cx>;
19    
20     use Message::DOM::DOMImplementation;
21 wakaba 1.1
22     my ($year, $month) = @ARGV;
23     $year += 0;
24     $month += 0;
25    
26     my $atom = q<http://www.w3.org/2005/Atom>;
27     my $fe = q<http://suika.fam.cx/www/2006/feature/>;
28     my $cfg = q<http://suika.fam.cx/www/2006/dom-config/>;
29     my $html = q<http://www.w3.org/1999/xhtml>;
30     my $xml = q<http://www.w3.org/XML/1998/namespace>;
31     my $xhtml2 = q<http://www.w3.org/2002/06/xhtml2/>;
32     my $h2h = q<http://suika.fam.cx/~wakaba/archive/2005/manakai/Markup/H2H/>;
33    
34 wakaba 1.2.2.1 my $impl = Message::DOM::DOMImplementation->new;
35 wakaba 1.1
36 wakaba 1.2.2.1 my $feed_doc = $impl->create_atom_feed_document
37 wakaba 1.1 ($FEED_TAG.$year.':'.$month.':');
38     $feed_doc->dom_config->set_parameter ($cfg.'create-child-element' => 1);
39    
40     my $atom_feed = $feed_doc->document_element;
41     $atom_feed->set_attribute_ns ($xml, 'xml:base', $BASE_URI);
42     $atom_feed->set_attribute_ns ($xml, 'xml:lang', $BASE_LANG);
43     $atom_feed->title_element->text_content ($FEED_NAME);
44    
45    
46     for my $author_el ($atom_feed->append_child
47     ($feed_doc->create_element_ns ($atom, 'author'))) {
48     $author_el->name ($AUTHOR_NAME);
49     $author_el->uri ($AUTHOR_URI) if defined $AUTHOR_URI;
50     $author_el->email ($AUTHOR_MAIL) if defined $AUTHOR_MAIL;
51     }
52    
53     for my $link_el ($atom_feed->append_child
54     ($feed_doc->create_element_ns ($atom, 'link'))) {
55     $link_el->rel ('alternate');
56     $link_el->href (sprintf 'd%04d%02d.%s.html', $year, $month, $BASE_LANG);
57     $link_el->type ('text/html');
58     $link_el->hreflang ($BASE_LANG);
59     }
60    
61     for my $link_el ($atom_feed->append_child
62     ($feed_doc->create_element_ns ($atom, 'link'))) {
63     $link_el->rel ('self');
64     $link_el->href (sprintf 'd%04d%02d.%s.atom', $year, $month, $BASE_LANG);
65     $link_el->type ('application/atom+xml');
66     $link_el->hreflang ($BASE_LANG);
67     }
68 wakaba 1.2
69     my $dir_name = $REPOSITORY_PATH.sprintf ('%04d', $year);
70     my $dym = sprintf 'd%04d%02d', $year, $month;
71     opendir my $dir, $dir_name or die "$0: $dir_name: $!";
72     for my $file_name (sort {$a cmp $b}
73     grep {substr ($_, 0, 7) eq $dym and
74     substr ($_, -(6 + length ($BASE_LANG)))
75     eq '.'.$BASE_LANG.'.atom'}
76     readdir $dir) {
77 wakaba 1.2.2.1 open my $entry_file, '<:utf8', $dir_name.'/'.$file_name
78 wakaba 1.2 or die "$0: $dir_name/$file_name: $!";
79 wakaba 1.2.2.1 local $/ = undef;
80     my $entry_text = <$entry_file>;
81     my $entry_doc = $impl->create_document;
82     $entry_doc->inner_html ($entry_text);
83 wakaba 1.2 $atom_feed->append_child
84     ($feed_doc->adopt_node ($entry_doc->document_element));
85     }
86     close $dir;
87 wakaba 1.1
88     my $feed_file_name = $REPOSITORY_PATH.sprintf ('d%04d%02d', $year, $month)
89     . '.'.$BASE_LANG.'.atom';
90    
91     open my $feed_file, '>', $feed_file_name
92     or die "$0: $feed_file_name: $!";
93    
94 wakaba 1.2.2.1 my $data = Encode::encode ('utf-8', $feed_doc->inner_html);
95 wakaba 1.1 warn qq<Write to "$feed_file_name"\n>;
96     print $feed_file $data;
97     close $feed_file;
98     system 'chmod', 'go+r', $feed_file_name;
99     $? == -1 and die "$0: chmod $feed_file_name: $!";
100    
101     open my $feed_file, '>', $FEED_CURRENT_PATH
102     or die "$0: $FEED_CURRENT_PATH: $!";
103     warn qq<Write to "$FEED_CURRENT_PATH"\n>;
104     print $feed_file $data;
105     close $feed_file;
106    
107    
108    
109    

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24