2 # Page inlining and blogging.
3 package IkiWiki::Plugin::inline;
9 IkiWiki::register_plugin("preprocess", "inline", \&IkiWiki::preprocess_inline);
12 # Back to ikiwiki namespace for the rest, this code is very much
13 # internal to ikiwiki even though it's separated into a plugin.
16 sub preprocess_inline (@) { #{{{
19 if (! exists $params{pages}) {
22 if (! exists $params{archive}) {
23 $params{archive}="no";
25 if (! exists $params{show} && $params{archive} eq "no") {
28 add_depends($params{page}, $params{pages});
32 if (exists $params{rootpage}) {
33 # Add a blog post form, with a rss link button.
34 my $formtemplate=HTML::Template->new(blind_cache => 1,
35 filename => "$config{templatedir}/blogpost.tmpl");
36 $formtemplate->param(cgiurl => $config{cgiurl});
37 $formtemplate->param(rootpage => $params{rootpage});
39 $formtemplate->param(rssurl => rsspage(basename($params{page})));
41 $ret.=$formtemplate->output;
43 elsif ($config{rss}) {
44 # Add a rss link button.
45 my $linktemplate=HTML::Template->new(blind_cache => 1,
46 filename => "$config{templatedir}/rsslink.tmpl");
47 $linktemplate->param(rssurl => rsspage(basename($params{page})));
48 $ret.=$linktemplate->output;
51 my $template=HTML::Template->new(blind_cache => 1,
52 filename => (($params{archive} eq "no")
53 ? "$config{templatedir}/inlinepage.tmpl"
54 : "$config{templatedir}/inlinepagetitle.tmpl"));
57 foreach my $page (blog_list($params{pages}, $params{show})) {
58 next if $page eq $params{page};
60 $template->param(pagelink => htmllink($params{page}, $page));
61 $template->param(content => get_inline_content($params{page}, $page))
62 if $params{archive} eq "no";
63 $template->param(ctime => scalar(gmtime($pagectime{$page})));
64 $ret.=$template->output;
67 # TODO: should really add this to renderedfiles and call
68 # check_overwrite, but currently renderedfiles
69 # only supports listing one file per page.
71 writefile(rsspage($params{page}), $config{destdir},
72 genrss($params{page}, @pages));
78 sub blog_list ($$) { #{{{
83 foreach my $page (keys %pagesources) {
84 if (globlist_match($page, $globlist)) {
89 @list=sort { $pagectime{$b} <=> $pagectime{$a} } @list;
90 return @list if ! $maxitems || @list <= $maxitems;
91 return @list[0..$maxitems - 1];
94 sub get_inline_content ($$) { #{{{
98 my $file=$pagesources{$page};
99 my $type=pagetype($file);
100 if ($type ne 'unknown') {
101 return htmlize($type, linkify(readfile(srcfile($file)), $parentpage));
108 sub date_822 ($) { #{{{
112 return POSIX::strftime("%a, %d %b %Y %H:%M:%S %z", localtime($time));
115 sub absolute_urls ($$) { #{{{
116 # sucky sub because rss sucks
122 $content=~s/<a\s+href="(?!http:\/\/)([^"]+)"/<a href="$url$1"/ig;
123 $content=~s/<img\s+src="(?!http:\/\/)([^"]+)"/<img src="$url$1"/ig;
127 sub rsspage ($) { #{{{
133 sub genrss ($@) { #{{{
137 my $url="$config{url}/".htmlpage($page);
139 my $template=HTML::Template->new(blind_cache => 1,
140 filename => "$config{templatedir}/rsspage.tmpl");
143 foreach my $p (@pages) {
145 itemtitle => pagetitle(basename($p)),
146 itemurl => "$config{url}/$renderedfiles{$p}",
147 itempubdate => date_822($pagectime{$p}),
148 itemcontent => absolute_urls(get_inline_content($page, $p), $url),
149 } if exists $renderedfiles{$p};
153 title => $config{wikiname},
158 return $template->output;