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 |
wakaba |
1.3 |
my $gls = $Message::DOM::ImplementationRegistry->get_dom_implementation |
37 |
wakaba |
1.1 |
({ |
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 |
|
|
|
56 |
|
|
for my $author_el ($atom_feed->append_child |
57 |
|
|
($feed_doc->create_element_ns ($atom, 'author'))) { |
58 |
|
|
$author_el->name ($AUTHOR_NAME); |
59 |
|
|
$author_el->uri ($AUTHOR_URI) if defined $AUTHOR_URI; |
60 |
|
|
$author_el->email ($AUTHOR_MAIL) if defined $AUTHOR_MAIL; |
61 |
|
|
} |
62 |
|
|
|
63 |
|
|
for my $link_el ($atom_feed->append_child |
64 |
|
|
($feed_doc->create_element_ns ($atom, 'link'))) { |
65 |
|
|
$link_el->rel ('alternate'); |
66 |
|
|
$link_el->href (sprintf 'd%04d%02d.%s.html', $year, $month, $BASE_LANG); |
67 |
|
|
$link_el->type ('text/html'); |
68 |
|
|
$link_el->hreflang ($BASE_LANG); |
69 |
|
|
} |
70 |
|
|
|
71 |
|
|
for my $link_el ($atom_feed->append_child |
72 |
|
|
($feed_doc->create_element_ns ($atom, 'link'))) { |
73 |
|
|
$link_el->rel ('self'); |
74 |
|
|
$link_el->href (sprintf 'd%04d%02d.%s.atom', $year, $month, $BASE_LANG); |
75 |
|
|
$link_el->type ('application/atom+xml'); |
76 |
|
|
$link_el->hreflang ($BASE_LANG); |
77 |
|
|
} |
78 |
wakaba |
1.2 |
|
79 |
|
|
my $dir_name = $REPOSITORY_PATH.sprintf ('%04d', $year); |
80 |
|
|
my $dym = sprintf 'd%04d%02d', $year, $month; |
81 |
|
|
opendir my $dir, $dir_name or die "$0: $dir_name: $!"; |
82 |
|
|
for my $file_name (sort {$a cmp $b} |
83 |
|
|
grep {substr ($_, 0, 7) eq $dym and |
84 |
|
|
substr ($_, -(6 + length ($BASE_LANG))) |
85 |
|
|
eq '.'.$BASE_LANG.'.atom'} |
86 |
|
|
readdir $dir) { |
87 |
|
|
open my $entry_file, '<', $dir_name.'/'.$file_name |
88 |
|
|
or die "$0: $dir_name/$file_name: $!"; |
89 |
|
|
my $entry_doc = $xp->parse ({byte_stream => $entry_file, |
90 |
|
|
encoding => 'utf-8'}); |
91 |
|
|
$atom_feed->append_child |
92 |
|
|
($feed_doc->adopt_node ($entry_doc->document_element)); |
93 |
|
|
} |
94 |
|
|
close $dir; |
95 |
wakaba |
1.1 |
|
96 |
|
|
my $feed_file_name = $REPOSITORY_PATH.sprintf ('d%04d%02d', $year, $month) |
97 |
|
|
. '.'.$BASE_LANG.'.atom'; |
98 |
|
|
|
99 |
|
|
my $ls = $gls->create_gls_serializer ({ |
100 |
|
|
$fe.'SerializeDocumentInstance' => '1.0', |
101 |
|
|
}); |
102 |
|
|
|
103 |
|
|
open my $feed_file, '>', $feed_file_name |
104 |
|
|
or die "$0: $feed_file_name: $!"; |
105 |
|
|
|
106 |
|
|
my $data = Encode::encode ('utf-8', $ls->write_to_string ($feed_doc)); |
107 |
|
|
warn qq<Write to "$feed_file_name"\n>; |
108 |
|
|
print $feed_file $data; |
109 |
|
|
close $feed_file; |
110 |
|
|
system 'chmod', 'go+r', $feed_file_name; |
111 |
|
|
$? == -1 and die "$0: chmod $feed_file_name: $!"; |
112 |
|
|
|
113 |
|
|
open my $feed_file, '>', $FEED_CURRENT_PATH |
114 |
|
|
or die "$0: $FEED_CURRENT_PATH: $!"; |
115 |
|
|
warn qq<Write to "$FEED_CURRENT_PATH"\n>; |
116 |
|
|
print $feed_file $data; |
117 |
|
|
close $feed_file; |
118 |
|
|
|
119 |
|
|
|
120 |
|
|
|
121 |
|
|
|