/[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.1 - (hide annotations) (download)
Sat May 6 15:23:26 2006 UTC (18 years, 6 months ago) by wakaba
Branch: MAIN
File MIME type: text/plain
Atom implemented

1 wakaba 1.1 #!/usr/bin/perl
2     use strict;
3     use utf8;
4    
5     use lib q</home/wakaba/work/manakai/lib>;
6    
7     our $REPOSITORY_PATH = q</home/wakaba/public_html/d/>;
8     our $FEED_NAME = q<冬様もすなる☆日記というもの>;
9     our $FEED_TAG = q<urn:x-suika-fam-cx:fuyubi:>;
10     our $BASE_URI = q<http://suika.fam.cx/~wakaba/d/>;
11     our $BASE_LANG = 'ja';
12     our $FEED_CURRENT_PATH = $REPOSITORY_PATH.'current.'.$BASE_LANG.'.atom';
13     our $AUTHOR_NAME = q<わかば>;
14     our $AUTHOR_URI = q<http://suika.fam.cx/~wakaba/who?>;
15     our $AUTHOR_MAIL = q<w@suika.fam.cx>;
16    
17     use Message::Markup::Atom;
18     use Message::DOM::DOMFeature;
19     use Message::DOM::GenericLS;
20     use Message::DOM::XMLParser;
21     use Message::DOM::SimpleLS;
22     use Encode::EUCJP1997;
23    
24     my ($year, $month) = @ARGV;
25     $year += 0;
26     $month += 0;
27    
28     my $atom = q<http://www.w3.org/2005/Atom>;
29     my $fe = q<http://suika.fam.cx/www/2006/feature/>;
30     my $cfg = q<http://suika.fam.cx/www/2006/dom-config/>;
31     my $html = q<http://www.w3.org/1999/xhtml>;
32     my $xml = q<http://www.w3.org/XML/1998/namespace>;
33     my $xhtml2 = q<http://www.w3.org/2002/06/xhtml2/>;
34     my $h2h = q<http://suika.fam.cx/~wakaba/archive/2005/manakai/Markup/H2H/>;
35    
36     my $gls = $Message::DOM::ImplementationRegistry->get_implementation
37     ({
38     $fe.'GenericLS' => '3.0',
39     });
40     my $aimpl = $gls->get_feature ($fe.'Atom' => '1.0');
41    
42     my $xp = $gls->create_gls_parser ({
43     LS => '3.0',
44     });
45    
46     my $feed_doc = $aimpl->create_atom_feed_document
47     ($FEED_TAG.$year.':'.$month.':');
48     $feed_doc->dom_config->set_parameter ($cfg.'create-child-element' => 1);
49    
50     my $atom_feed = $feed_doc->document_element;
51     $atom_feed->set_attribute_ns ($xml, 'xml:base', $BASE_URI);
52     $atom_feed->set_attribute_ns ($xml, 'xml:lang', $BASE_LANG);
53     $atom_feed->title_element->text_content ($FEED_NAME);
54    
55     my $dir_name = $REPOSITORY_PATH.sprintf ('%04d', $year);
56     my $dym = sprintf 'd%04d%02d', $year, $month;
57     opendir my $dir, $dir_name or die "$0: $dir_name: $!";
58     for my $file_name (sort {$a cmp $b}
59     grep {substr ($_, 0, 7) eq $dym and
60     substr ($_, -(6 + length ($BASE_LANG)))
61     eq '.'.$BASE_LANG.'.atom'}
62     readdir $dir) {
63     open my $entry_file, '<', $dir_name.'/'.$file_name
64     or die "$0: $dir_name/$file_name: $!";
65     my $entry_doc = $xp->parse ({byte_stream => $entry_file,
66     encoding => 'utf-8'});
67     $atom_feed->append_child
68     ($feed_doc->adopt_node ($entry_doc->document_element));
69     }
70     close $dir;
71    
72     for my $author_el ($atom_feed->append_child
73     ($feed_doc->create_element_ns ($atom, 'author'))) {
74     $author_el->name ($AUTHOR_NAME);
75     $author_el->uri ($AUTHOR_URI) if defined $AUTHOR_URI;
76     $author_el->email ($AUTHOR_MAIL) if defined $AUTHOR_MAIL;
77     }
78    
79     for my $link_el ($atom_feed->append_child
80     ($feed_doc->create_element_ns ($atom, 'link'))) {
81     $link_el->rel ('alternate');
82     $link_el->href (sprintf 'd%04d%02d.%s.html', $year, $month, $BASE_LANG);
83     $link_el->type ('text/html');
84     $link_el->hreflang ($BASE_LANG);
85     }
86    
87     for my $link_el ($atom_feed->append_child
88     ($feed_doc->create_element_ns ($atom, 'link'))) {
89     $link_el->rel ('self');
90     $link_el->href (sprintf 'd%04d%02d.%s.atom', $year, $month, $BASE_LANG);
91     $link_el->type ('application/atom+xml');
92     $link_el->hreflang ($BASE_LANG);
93     }
94    
95     my $feed_file_name = $REPOSITORY_PATH.sprintf ('d%04d%02d', $year, $month)
96     . '.'.$BASE_LANG.'.atom';
97    
98     my $ls = $gls->create_gls_serializer ({
99     $fe.'SerializeDocumentInstance' => '1.0',
100     });
101    
102     open my $feed_file, '>', $feed_file_name
103     or die "$0: $feed_file_name: $!";
104    
105     my $data = Encode::encode ('utf-8', $ls->write_to_string ($feed_doc));
106     warn qq<Write to "$feed_file_name"\n>;
107     print $feed_file $data;
108     close $feed_file;
109     system 'chmod', 'go+r', $feed_file_name;
110     $? == -1 and die "$0: chmod $feed_file_name: $!";
111    
112     open my $feed_file, '>', $FEED_CURRENT_PATH
113     or die "$0: $FEED_CURRENT_PATH: $!";
114     warn qq<Write to "$FEED_CURRENT_PATH"\n>;
115     print $feed_file $data;
116     close $feed_file;
117    
118    
119    
120    

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24