<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/perl
# Sidebar plugin.
# by Tuomo Valkonen &lt;tuomov at iki dot fi&gt;

package IkiWiki::Plugin::sidebar;

use warnings;
use strict;
use IkiWiki;

sub import { #{{{
	IkiWiki::hook(type =&gt; "pagetemplate", id =&gt; "sidebar", 
		call =&gt; \&amp;pagetemplate);
} # }}}

sub sidebar_content ($) { #{{{
	my $page=shift;
	
	my $sidebar_page=IkiWiki::bestlink($page, "sidebar") || return;
	my $sidebar_file=$IkiWiki::pagesources{$sidebar_page} || return;
	my $sidebar_type=IkiWiki::pagetype($sidebar_file);
	
	if (defined $sidebar_type) {
		# FIXME: This isn't quite right; it won't take into account
		# adding a new sidebar page. So adding such a page
		# currently requires a wiki rebuild.
		IkiWiki::add_depends($page, $sidebar_page);

		my $content=IkiWiki::readfile(IkiWiki::srcfile($sidebar_file));
		return unless length $content;
		return IkiWiki::htmlize($sidebar_type,
		       IkiWiki::linkify($sidebar_page, $page,
		       IkiWiki::preprocess($sidebar_page, $page,
		       IkiWiki::filter($sidebar_page, $content))));
	}

} # }}}

sub pagetemplate (@) { #{{{
	my %params=@_;

	my $page=$params{page};
	my $template=$params{template};
	
	if ($template-&gt;query(name =&gt; "sidebar")) {
		my $content=sidebar_content($page);
		if (defined $content &amp;&amp; length $content) {
		        $template-&gt;param(sidebar =&gt; $content);
		}
	}
} # }}}

1
</pre></body></html>