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