aboutsummaryrefslogtreecommitdiff
path: root/doc/patchqueue/atomfeed.mdwn
blob: 4569e30fa27944a3df91627524bc7b8a248465fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
diff -x {arch} -x .arch-ids -Nur ikiwiki--upstream--1.0--patch-26/IkiWiki/Plugin/inline.pm ikiwiki--devo--1.0--patch-9/IkiWiki/Plugin/inline.pm
--- ikiwiki--upstream--1.0--patch-26/IkiWiki/Plugin/inline.pm   2006-09-17 16:08:18.969109484 -0400
+++ ikiwiki--devo--1.0--patch-9/IkiWiki/Plugin/inline.pm        2006-09-16 13:38:36.336193934 -0400
@@ -26,6 +26,7 @@
 
 my %toping;
 my %rsslinks;
+my %atomlinks;
 
 sub yesno ($) { #{{{
        my $val=shift;
@@ -41,6 +42,7 @@
        my $raw=yesno($params{raw});
        my $archive=yesno($params{archive});
        my $rss=exists $params{rss} ? yesno($params{rss}) : 1;
+       my $atom=exists $params{atom} ? yesno($params{atom}) : 1;
        if (! exists $params{show} && ! $archive) {
                $params{show}=10;
        }
@@ -67,6 +69,7 @@
        add_depends($params{page}, $params{pages});
 
        my $rssurl=rsspage(basename($params{page}));
+       my $atomurl=atompage(basename($params{page}));
        my $ret="";
 
        if (exists $params{rootpage} && $config{cgiurl}) {
@@ -77,6 +80,9 @@
                if ($config{rss}) {
                        $formtemplate->param(rssurl => $rssurl);
                }
+               if ($config{atom}) {
+                       $formtemplate->param(atomurl => $atomurl);
+               }
                $ret.=$formtemplate->output;
        }
        elsif ($config{rss} && $rss) {
@@ -85,6 +91,12 @@
                $linktemplate->param(rssurl => $rssurl);
                $ret.=$linktemplate->output;
        }
+       elsif ($config{atom} && $atom) {
+               # Add a Atom link button.
+               my $linktemplate=template("atomlink.tmpl", blind_cache => 1);
+               $linktemplate->param(atomurl => $atomurl);
+               $ret.=$linktemplate->output;
+       }
 
        my $template=template(
                ($archive ? "inlinepagetitle.tmpl" : "inlinepage.tmpl"),
@@ -149,10 +161,16 @@
        # only supports listing one file per page.
        if ($config{rss} && $rss) {
                writefile(rsspage($params{page}), $config{destdir},
-                       genrss($desc, $params{page}, @list));
+                       genfeed("rss", $rssurl, $desc, $params{page}, @list));
                $toping{$params{page}}=1 unless $config{rebuild};
                $rsslinks{$params{destpage}}=qq{<link rel="alternate" type="application/rss+xml" title="RSS" href="$rssurl" />};
        }
+       if ($config{atom} && $atom) {
+               writefile(atompage($params{page}), $config{destdir},
+                       genfeed("atom", $atomurl, $desc, $params{page}, @list));
+               $toping{$params{page}}=1 unless $config{rebuild};
+               $atomlinks{$params{destpage}}=qq{<link rel="alternate" type="application/atom+xml" title="Atom" href="$atomurl" />};
+       }
 
        return $ret;
 } #}}}
@@ -164,6 +182,8 @@
 
        $template->param(rsslink => $rsslinks{$page})
                if exists $rsslinks{$page} && $template->query(name => "rsslink");
+       $template->param(atomlink => $atomlinks{$page})
+               if exists $atomlinks{$page} && $template->query(name => "atomlink");
 } #}}}
 
 sub get_inline_content ($$) { #{{{
@@ -195,6 +215,17 @@
        return $ret;
 } #}}}
 
+sub date_3339 ($) { #{{{
+       my $time=shift;
+
+       eval q{use POSIX};
+       my $lc_time= POSIX::setlocale(&POSIX::LC_TIME);
+       POSIX::setlocale(&POSIX::LC_TIME, "C");
+       my $ret=POSIX::strftime("%Y-%m-%dT%H:%M:%SZ", localtime($time));
+       POSIX::setlocale(&POSIX::LC_TIME, $lc_time);
+       return $ret;
+} #}}}
+
 sub absolute_urls ($$) { #{{{
        # sucky sub because rss sucks
        my $content=shift;
@@ -213,15 +244,24 @@
        return $page.".rss";
 } #}}}
 
-sub genrss ($$@) { #{{{
+sub atompage ($) { #{{{
+       my $page=shift;
+
+       return $page.".atom";
+} #}}}
+
+sub genfeed ($$$$@) { #{{{
+       my $feedtype=shift;
+       my $feedurl=shift;
        my $desc=shift;
        my $page=shift;
        my @pages=@_;
 
        my $url=URI->new(encode_utf8($config{url}."/".htmlpage($page)));
 
-       my $itemtemplate=template("rssitem.tmpl", blind_cache => 1);
+       my $itemtemplate=template($feedtype."item.tmpl", blind_cache => 1);
        my $content="";
+       my $lasttime;
        foreach my $p (@pages) {
                next unless exists $renderedfiles{$p};
 
@@ -232,6 +272,7 @@
                        url => $u,
                        permalink => $u,
                        pubdate => date_822($pagectime{$p}),
+                       atompubdate => date_3339($pagectime{$p}),
                        content => absolute_urls(get_inline_content($p, $page), $url),
                );
                run_hooks(pagetemplate => sub {
@@ -241,15 +282,19 @@
 
                $content.=$itemtemplate->output;
                $itemtemplate->clear_params;
+
+               $lasttime = $pagectime{$p};
        }
 
-       my $template=template("rsspage.tmpl", blind_cache => 1);
+       my $template=template($feedtype."page.tmpl", blind_cache => 1);
        $template->param(
                title => $config{wikiname},
                wikiname => $config{wikiname},
                pageurl => $url,
                content => $content,
                rssdesc => $desc,
+               feeddate => date_3339($lasttime),
+               feedurl => $feedurl,
        );
        run_hooks(pagetemplate => sub {
                shift->(page => $page, destpage => $page,
diff -x {arch} -x .arch-ids -Nur ikiwiki--upstream--1.0--patch-26/templates/atomitem.tmpl ikiwiki--devo--1.0--patch-9/templates/atomitem.tmpl
--- ikiwiki--upstream--1.0--patch-26/templates/atomitem.tmpl    1969-12-31 19:00:00.000000000 -0500
+++ ikiwiki--devo--1.0--patch-9/templates/atomitem.tmpl 2006-09-16 02:56:56.075533012 -0400
@@ -0,0 +1,20 @@
+<entry>
+       <title><TMPL_VAR TITLE ESCAPE=HTML></title>
+       <TMPL_IF NAME="AUTHOR">
+       <author><TMPL_VAR AUTHOR ESCAPE=HTML></author>
+       <TMPL_ELSE>
+       </TMPL_IF>
+       <id><TMPL_VAR URL></id>
+       <link href="<TMPL_VAR PERMALINK>"/>
+       <TMPL_IF NAME="CATEGORIES">
+       <TMPL_LOOP NAME="CATEGORIES">
+       <category><TMPL_VAR CATEGORY></category>
+       </TMPL_LOOP>
+       </TMPL_IF>
+       <updated><TMPL_VAR ATOMPUBDATE></updated>
+       <content type="xhtml" xml:lang="en">
+        <div xmlns="http://www.w3.org/1999/xhtml">
+        ![CDATA[<TMPL_VAR CONTENT>]]
+        </div>
+       </content>
+</entry>
diff -x {arch} -x .arch-ids -Nur ikiwiki--upstream--1.0--patch-26/templates/atomlink.tmpl ikiwiki--devo--1.0--patch-9/templates/atomlink.tmpl
--- ikiwiki--upstream--1.0--patch-26/templates/atomlink.tmpl    1969-12-31 19:00:00.000000000 -0500
+++ ikiwiki--devo--1.0--patch-9/templates/atomlink.tmpl 2006-09-16 02:56:56.079533423 -0400
@@ -0,0 +1,5 @@
+<div id="atomlink">
+<TMPL_IF NAME="ATOMURL">
+<a class="atombutton" type="application/atom+xml" href="<TMPL_VAR NAME=ATOMURL>">Atom</a>
+</TMPL_IF>
+</div>
diff -x {arch} -x .arch-ids -Nur ikiwiki--upstream--1.0--patch-26/templates/atompage.tmpl ikiwiki--devo--1.0--patch-9/templates/atompage.tmpl
--- ikiwiki--upstream--1.0--patch-26/templates/atompage.tmpl    1969-12-31 19:00:00.000000000 -0500
+++ ikiwiki--devo--1.0--patch-9/templates/atompage.tmpl 2006-09-16 02:56:56.079533423 -0400
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<feed xmlns="http://www.w3.org/2005/Atom">
+ <title><TMPL_VAR TITLE ESCAPE=HTML></title>
+ <link href="<TMPL_VAR PAGEURL>"/>
+ <link href="<TMPL_VAR FEEDURL>" rel="self"/>
+ <author> 
+  <name>John Doe</name>
+ </author> 
+ <id><TMPL_VAR PAGEURL></id>
+ <subtitle type="html"><TMPL_VAR RSSDESC ESCAPE=HTML></subtitle>
+ <generator uri="http://ikiwiki.kitenet.net/" version="1.0">ikiwiki</generator>
+ <updated><TMPL_VAR FEEDDATE></updated>
+<TMPL_VAR CONTENT>
+</feed>