2 # Page inlining and blogging.
3 package IkiWiki::Plugin::inline;
10 IkiWiki::register_plugin("preprocess", "inline", \&IkiWiki::preprocess_inline);
13 # Back to ikiwiki namespace for the rest, this code is very much
14 # internal to ikiwiki even though it's separated into a plugin.
17 sub preprocess_inline (@) { #{{{
20 if (! exists $params{pages}) {
23 if (! exists $params{archive}) {
24 $params{archive}="no";
26 if (! exists $params{show} && $params{archive} eq "no") {
29 add_depends($params{page}, $params{pages});
33 if (exists $params{rootpage}) {
34 # Add a blog post form, with a rss link button.
35 my $formtemplate=HTML::Template->new(blind_cache => 1,
36 filename => "$config{templatedir}/blogpost.tmpl");
37 $formtemplate->param(cgiurl => $config{cgiurl});
38 $formtemplate->param(rootpage => $params{rootpage});
40 $formtemplate->param(rssurl => rsspage(basename($params{page})));
42 $ret.=$formtemplate->output;
44 elsif ($config{rss}) {
45 # Add a rss link button.
46 my $linktemplate=HTML::Template->new(blind_cache => 1,
47 filename => "$config{templatedir}/rsslink.tmpl");
48 $linktemplate->param(rssurl => rsspage(basename($params{page})));
49 $ret.=$linktemplate->output;
52 my $template=HTML::Template->new(blind_cache => 1,
53 filename => (($params{archive} eq "no")
54 ? "$config{templatedir}/inlinepage.tmpl"
55 : "$config{templatedir}/inlinepagetitle.tmpl"));
58 foreach my $page (blog_list($params{pages}, $params{show})) {
59 next if $page eq $params{page};
61 $template->param(pagelink => htmllink($params{page}, $page));
62 $template->param(content => get_inline_content($params{page}, $page))
63 if $params{archive} eq "no";
64 $template->param(ctime => scalar(gmtime($pagectime{$page})));
65 $ret.=$template->output;
68 # TODO: should really add this to renderedfiles and call
69 # check_overwrite, but currently renderedfiles
70 # only supports listing one file per page.
72 writefile(rsspage($params{page}), $config{destdir},
73 genrss($params{page}, @pages));
79 sub blog_list ($$) { #{{{
84 foreach my $page (keys %pagesources) {
85 if (globlist_match($page, $globlist)) {
90 @list=sort { $pagectime{$b} <=> $pagectime{$a} } @list;
91 return @list if ! $maxitems || @list <= $maxitems;
92 return @list[0..$maxitems - 1];
95 sub get_inline_content ($$) { #{{{
99 my $file=$pagesources{$page};
100 my $type=pagetype($file);
101 if ($type ne 'unknown') {
102 return htmlize($type, linkify(readfile(srcfile($file)), $parentpage));
109 sub date_822 ($) { #{{{
113 return POSIX::strftime("%a, %d %b %Y %H:%M:%S %z", localtime($time));
116 sub absolute_urls ($$) { #{{{
117 # sucky sub because rss sucks
123 $content=~s/<a\s+href="(?!http:\/\/)([^"]+)"/<a href="$url$1"/ig;
124 $content=~s/<img\s+src="(?!http:\/\/)([^"]+)"/<img src="$url$1"/ig;
128 sub rsspage ($) { #{{{
134 sub genrss ($@) { #{{{
138 my $url="$config{url}/".htmlpage($page);
140 my $template=HTML::Template->new(blind_cache => 1,
141 filename => "$config{templatedir}/rsspage.tmpl");
144 foreach my $p (@pages) {
146 itemtitle => pagetitle(basename($p)),
147 itemurl => "$config{url}/$renderedfiles{$p}",
148 itempubdate => date_822($pagectime{$p}),
149 itemcontent => absolute_urls(get_inline_content($page, $p), $url),
150 } if exists $renderedfiles{$p};
154 title => $config{wikiname},
159 return $template->output;