/[suikacvs]/markup/html/whatpm/mkcommitfeed.pl
Suika

Contents of /markup/html/whatpm/mkcommitfeed.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (hide annotations) (download)
Tue Oct 21 05:17:48 2008 UTC (16 years, 6 months ago) by wakaba
Branch: MAIN
Changes since 1.1: +25 -1 lines
File MIME type: text/plain
++ ChangeLog	21 Oct 2008 05:17:37 -0000
	* cvscommit.sh: Set |--feed-title|, |--feed-related-url|,
	|--feed-license-url|, and |-feed-rights| options to the
	|mkcommitfeed.pl| call.

	* mkcommitfeed.pl: New options |--feed-license-url|,
	|--feed-related-url|, and |--feed-rights| implemented.

2008-10-21  Wakaba  <wakaba@suika.fam.cx>

1 wakaba 1.1 #!/usr/bin/perl
2     use strict;
3    
4     use Getopt::Long;
5     use Pod::Usage;
6     use Time::Local;
7    
8     my $file_name;
9     my $feed_url;
10     my $feed_title = 'ChangeLog';
11     my $feed_author_name;
12     my $feed_author_mail;
13     my $feed_author_url;
14     my $feed_lang = 'i-default';
15 wakaba 1.2 my $feed_realated_url;
16     my $feed_license_url;
17     my $feed_rights;
18 wakaba 1.1 my $entry_content;
19     my $entry_author_name;
20     my $entry_author_mail;
21     my $entry_date;
22     my $entry_title;
23    
24     GetOptions (
25     'entry-author-mail=s' => \$entry_author_mail,
26     'entry-author-name=s' => \$entry_author_name,
27     'entry-content=s' => \$entry_content,
28     'entry-title=s' => \$entry_title,
29     'feed-author-mail=s' => \$feed_author_mail,
30     'feed-author-name=s' => \$feed_author_name,
31     'feed-author-url=s' => \$feed_author_url,
32     'feed-lang=s' => \$feed_lang,
33 wakaba 1.2 'feed-license-url=s' => \$feed_license_url,
34     'feed-related-url=s' => \$feed_related_url,
35     'feed-rights=s' => \$feed_rights,
36 wakaba 1.1 'feed-title=s' => \$feed_title,
37     'feed-url=s' => \$feed_url,
38     'file-name=s' => \$file_name,
39     'help' => sub {
40     pod2usage (-exitval => 0, -verbose => 2);
41     },
42     ) or pod2usage (-exitval => 1, -verbose => 1);
43     pod2usage (-exitval => 1, -verbose => 1,
44     -msg => "Required argument --file-name is not specified.\n")
45     unless defined $file_name;
46     pod2usage (-exitval => 1, -verbose => 1,
47     -msg => "Required argument --feed-url is not specified.\n")
48     unless defined $feed_url;
49    
50     unless (defined $entry_content) {
51     $entry_content = '';
52     $entry_content .= $_ while <>;
53     }
54    
55     if ($entry_content =~ /^(\d+)-(\d+)-(\d+)\s+(.+)<([^<>]+)>/m) {
56     $entry_date //= timegm (0, 0, 0, $3, $2-1, $1);
57     $entry_author_name //= $4;
58     $entry_author_mail //= $5;
59     $entry_author_name =~ s/\s+$//;
60     }
61     $entry_date //= time;
62    
63     pod2usage (-exitval => 1, -verbose => 1,
64     -msg => "Required argument --entry-author-name is not specified.\n")
65     unless defined $entry_author_name;
66    
67     unless (defined $entry_title) {
68     my $time = [gmtime $entry_date];
69     $entry_title = sprintf '%04d-%02d-%02d %s', 1900+$time->[5], 1+$time->[4],
70     $time->[3], $entry_author_name;
71     }
72    
73     require Message::DOM::DOMImplementation;
74     my $dom = Message::DOM::DOMImplementation->new;
75     my $doc;
76    
77     {
78     if (-f $file_name) {
79     open my $file, '<:encoding(utf8)', $file_name or die "$0: $file_name: $!";
80     local $/ = undef;
81     $doc = $dom->create_document;
82     $doc->inner_html (<$file>);
83     } else {
84     $doc = $dom->create_atom_feed_document
85     ($feed_url, $feed_title, $feed_lang);
86     }
87     }
88    
89     $doc->dom_config
90     ->{q<http://suika.fam.cx/www/2006/dom-config/create-child-element>} = 1;
91     my $feed = $doc->document_element;
92     unless ($feed) {
93     $feed = $doc->create_element_ns ('http://www.w3.org/2005/Atom', 'feed');
94     $doc->append_child ($feed);
95     }
96    
97     unless (@{$feed->author_elements}) {
98     if (defined $feed_author_name) {
99     my $author = $doc->create_element_ns ($feed->namespace_uri, 'author');
100     $author->name ($feed_author_name);
101     $author->email ($feed_author_mail) if defined $feed_author_mail;
102     $author->uri ($feed_author_url) if defined $feed_author_url;
103     $feed->append_child ($author);
104     }
105     }
106     unless (@{$feed->link_elements}) {
107     my $link_self = $doc->create_element_ns ($feed->namespace_uri, 'link');
108     $link_self->rel ('self');
109     $link_self->type ('application/atom+xml');
110     $link_self->hreflang ($feed_lang);
111     $link_self->href ($feed_url);
112     $feed->append_child ($link_self);
113 wakaba 1.2
114     if (defined $feed_related_url) {
115     my $link = $doc->create_element_ns ($feed->namespace_uri, 'link');
116     $link->rel ('related');
117     $link->href ($feed_related_url);
118     $feed->append_child ($link);
119     }
120    
121     if (defined $feed_license_url) {
122     my $link = $doc->create_element_ns ($feed->namespace_uri, 'link');
123     $link->rel ('license');
124     $link->href ($feed_license_url);
125     $feed->append_child ($link);
126     }
127     }
128    
129     if (defined $feed_rights) {
130     $feed->rights_element->text_content ($feed_rights);
131 wakaba 1.1 }
132    
133     my $entry_id = 'entry-' . time;
134     my $entry = $feed->add_new_entry ($feed_url . '#' . $entry_id,
135     $entry_title);
136     $entry->set_attribute_ns ('http://www.w3.org/XML/1998/namespace',
137     'xml:id' => $entry_id);
138     if (defined $entry_author_name) {
139     my $author = $doc->create_element_ns ($feed->namespace_uri, 'author');
140     $author->name ($entry_author_name);
141     $author->email ($entry_author_mail) if defined $entry_author_mail;
142     $entry->append_child ($author);
143     }
144     $entry->updated_element->value ($entry_date);
145     my $content = $entry->content_element;
146     $content->type ('text');
147     $content->text_content ($entry_content);
148    
149     {
150     open my $file, '>:utf8', $file_name or die "$0: $file_name: $!";
151     print $file $doc->inner_html;
152     }
153    
154 wakaba 1.2 ## $Date: 2008/10/21 05:03:24 $

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24