The pagetemplate hook may be called multiple times, for example when pages
are inlined into a page. Sidebars were being calculated each time that
happened, only to be thrown away when the final pagetemplate hook was
called. Avoid this unnecessary work.
Remove stored sidebar content on use to save some memory.
sub sidebar_content ($) {
my $page=shift;
sub sidebar_content ($) {
my $page=shift;
- return $pagesidebar{$page} if defined $pagesidebar{$page};
+ return delete $pagesidebar{$page} if defined $pagesidebar{$page};
return if ! exists $pagesidebar{$page} &&
defined $config{global_sidebars} && ! $config{global_sidebars};
return if ! exists $pagesidebar{$page} &&
defined $config{global_sidebars} && ! $config{global_sidebars};
sub pagetemplate (@) {
my %params=@_;
sub pagetemplate (@) {
my %params=@_;
- my $page=$params{page};
my $template=$params{template};
my $template=$params{template};
-
- if ($template->query(name => "sidebar")) {
- my $content=sidebar_content($page);
+ if ($params{destpage} eq $params{page} &&
+ $template->query(name => "sidebar")) {
+ my $content=sidebar_content($params{destpage});
if (defined $content && length $content) {
$template->param(sidebar => $content);
}
if (defined $content && length $content) {
$template->param(sidebar => $content);
}