2 # Page inlining and blogging.
3 package IkiWiki::Plugin::inline;
10 IkiWiki::hook(type => "preprocess", id => "inline",
11 call => \&IkiWiki::preprocess_inline);
14 # Back to ikiwiki namespace for the rest, this code is very much
15 # internal to ikiwiki even though it's separated into a plugin.
18 sub preprocess_inline (@) { #{{{
21 if (! exists $params{pages}) {
24 if (! exists $params{archive}) {
25 $params{archive}="no";
27 if (! exists $params{show} && $params{archive} eq "no") {
30 add_depends($params{page}, $params{pages});
34 if (exists $params{rootpage}) {
35 # Add a blog post form, with a rss link button.
36 my $formtemplate=HTML::Template->new(blind_cache => 1,
37 filename => "$config{templatedir}/blogpost.tmpl");
38 $formtemplate->param(cgiurl => $config{cgiurl});
39 $formtemplate->param(rootpage => $params{rootpage});
41 $formtemplate->param(rssurl => rsspage(basename($params{page})));
43 $ret.=$formtemplate->output;
45 elsif ($config{rss}) {
46 # Add a rss link button.
47 my $linktemplate=HTML::Template->new(blind_cache => 1,
48 filename => "$config{templatedir}/rsslink.tmpl");
49 $linktemplate->param(rssurl => rsspage(basename($params{page})));
50 $ret.=$linktemplate->output;
53 my $template=HTML::Template->new(blind_cache => 1,
54 filename => (($params{archive} eq "no")
55 ? "$config{templatedir}/inlinepage.tmpl"
56 : "$config{templatedir}/inlinepagetitle.tmpl"));
59 foreach my $page (blog_list($params{pages}, $params{show})) {
60 next if $page eq $params{page};
62 $template->param(pagelink => htmllink($params{page}, $params{page}, $page));
63 $template->param(content => get_inline_content($params{page}, $page))
64 if $params{archive} eq "no";
65 $template->param(ctime => displaytime($pagectime{$page}));
66 $ret.=$template->output;
69 # TODO: should really add this to renderedfiles and call
70 # check_overwrite, but currently renderedfiles
71 # only supports listing one file per page.
73 writefile(rsspage($params{page}), $config{destdir},
74 genrss($params{page}, @pages));
80 sub blog_list ($$) { #{{{
85 foreach my $page (keys %pagesources) {
86 if (globlist_match($page, $globlist)) {
91 @list=sort { $pagectime{$b} <=> $pagectime{$a} } @list;
92 return @list if ! $maxitems || @list <= $maxitems;
93 return @list[0..$maxitems - 1];
96 sub get_inline_content ($$) { #{{{
100 my $file=$pagesources{$page};
101 my $type=pagetype($file);
102 if ($type ne 'unknown') {
103 return htmlize($type, preprocess($page, linkify($page, $parentpage, readfile(srcfile($file))), 1));
110 sub date_822 ($) { #{{{
114 return POSIX::strftime("%a, %d %b %Y %H:%M:%S %z", localtime($time));
117 sub absolute_urls ($$) { #{{{
118 # sucky sub because rss sucks
124 $content=~s/<a\s+href="(?!http:\/\/)([^"]+)"/<a href="$url$1"/ig;
125 $content=~s/<img\s+src="(?!http:\/\/)([^"]+)"/<img src="$url$1"/ig;
129 sub rsspage ($) { #{{{
135 sub genrss ($@) { #{{{
139 my $url="$config{url}/".htmlpage($page);
141 my $template=HTML::Template->new(blind_cache => 1,
142 filename => "$config{templatedir}/rsspage.tmpl");
145 foreach my $p (@pages) {
147 itemtitle => pagetitle(basename($p)),
148 itemurl => "$config{url}/$renderedfiles{$p}",
149 itempubdate => date_822($pagectime{$p}),
150 itemcontent => absolute_urls(get_inline_content($page, $p), $url),
151 } if exists $renderedfiles{$p};
155 title => $config{wikiname},
160 return $template->output;