summaryrefslogtreecommitdiff
path: root/perl/IkiWiki/Plugin
diff options
context:
space:
mode:
Diffstat (limited to 'perl/IkiWiki/Plugin')
-rw-r--r--perl/IkiWiki/Plugin/farbar.pm81
-rw-r--r--perl/IkiWiki/Plugin/topbar.pm81
2 files changed, 138 insertions, 24 deletions
diff --git a/perl/IkiWiki/Plugin/farbar.pm b/perl/IkiWiki/Plugin/farbar.pm
index ab4390a..37f1013 100644
--- a/perl/IkiWiki/Plugin/farbar.pm
+++ b/perl/IkiWiki/Plugin/farbar.pm
@@ -7,15 +7,64 @@ package IkiWiki::Plugin::farbar;
use warnings;
use strict;
-use IkiWiki 2.00;
+use IkiWiki 3.00;
-sub import { #{{{
+sub import {
+ hook(type => "getsetup", id => "farbar", call => \&getsetup);
+ hook(type => "preprocess", id => "farbar", call => \&preprocess);
hook(type => "pagetemplate", id => "farbar", call => \&pagetemplate);
-} # }}}
+}
-sub farbar_content ($) { #{{{
+sub getsetup () {
+ return
+ plugin => {
+ safe => 1,
+ rebuild => 1,
+ },
+ global_farbars => {
+ type => "boolean",
+ example => 1,
+ description => "show farbar page on all pages?",
+ safe => 1,
+ rebuild => 1,
+ },
+}
+
+my %pagefarbar;
+
+sub preprocess (@) {
+ my %params=@_;
+
+ my $page=$params{page};
+ return "" unless $page eq $params{destpage};
+
+ if (! defined $params{content}) {
+ $pagefarbar{$page}=undef;
+ }
+ else {
+ my $file = $pagesources{$page};
+ my $type = pagetype($file);
+
+ $pagefarbar{$page}=
+ IkiWiki::htmlize($page, $page, $type,
+ IkiWiki::linkify($page, $page,
+ IkiWiki::preprocess($page, $page, $params{content})));
+ }
+
+ return "";
+}
+
+my $oldfile;
+my $oldcontent;
+
+sub farbar_content ($) {
my $page=shift;
+ return delete $pagefarbar{$page} if defined $pagefarbar{$page};
+
+ return if ! exists $pagefarbar{$page} &&
+ defined $config{global_farbars} && ! $config{global_farbars};
+
my $farbar_page=bestlink($page, "farbar") || return;
my $farbar_file=$pagesources{$farbar_page} || return;
my $farbar_type=pagetype($farbar_file);
@@ -26,7 +75,16 @@ sub farbar_content ($) { #{{{
# currently requires a wiki rebuild.
add_depends($page, $farbar_page);
- my $content=readfile(srcfile($farbar_file));
+ my $content;
+ if (defined $oldfile && $farbar_file eq $oldfile) {
+ $content=$oldcontent;
+ }
+ else {
+ $content=readfile(srcfile($farbar_file));
+ $oldcontent=$content;
+ $oldfile=$farbar_file;
+ }
+
return unless length $content;
return IkiWiki::htmlize($farbar_page, $page, $farbar_type,
IkiWiki::linkify($farbar_page, $page,
@@ -34,20 +92,19 @@ sub farbar_content ($) { #{{{
IkiWiki::filter($farbar_page, $page, $content))));
}
-} # }}}
+}
-sub pagetemplate (@) { #{{{
+sub pagetemplate (@) {
my %params=@_;
- my $page=$params{page};
my $template=$params{template};
-
- if ($template->query(name => "farbar")) {
- my $content=farbar_content($page);
+ if ($params{destpage} eq $params{page} &&
+ $template->query(name => "farbar")) {
+ my $content=farbar_content($params{destpage});
if (defined $content && length $content) {
$template->param(farbar => $content);
}
}
-} # }}}
+}
1
diff --git a/perl/IkiWiki/Plugin/topbar.pm b/perl/IkiWiki/Plugin/topbar.pm
index aa62a11..2705161 100644
--- a/perl/IkiWiki/Plugin/topbar.pm
+++ b/perl/IkiWiki/Plugin/topbar.pm
@@ -7,15 +7,64 @@ package IkiWiki::Plugin::topbar;
use warnings;
use strict;
-use IkiWiki 2.00;
+use IkiWiki 3.00;
-sub import { #{{{
+sub import {
+ hook(type => "getsetup", id => "topbar", call => \&getsetup);
+ hook(type => "preprocess", id => "topbar", call => \&preprocess);
hook(type => "pagetemplate", id => "topbar", call => \&pagetemplate);
-} # }}}
+}
-sub topbar_content ($) { #{{{
+sub getsetup () {
+ return
+ plugin => {
+ safe => 1,
+ rebuild => 1,
+ },
+ global_topbars => {
+ type => "boolean",
+ example => 1,
+ description => "show topbar page on all pages?",
+ safe => 1,
+ rebuild => 1,
+ },
+}
+
+my %pagetopbar;
+
+sub preprocess (@) {
+ my %params=@_;
+
+ my $page=$params{page};
+ return "" unless $page eq $params{destpage};
+
+ if (! defined $params{content}) {
+ $pagetopbar{$page}=undef;
+ }
+ else {
+ my $file = $pagesources{$page};
+ my $type = pagetype($file);
+
+ $pagetopbar{$page}=
+ IkiWiki::htmlize($page, $page, $type,
+ IkiWiki::linkify($page, $page,
+ IkiWiki::preprocess($page, $page, $params{content})));
+ }
+
+ return "";
+}
+
+my $oldfile;
+my $oldcontent;
+
+sub topbar_content ($) {
my $page=shift;
+ return delete $pagetopbar{$page} if defined $pagetopbar{$page};
+
+ return if ! exists $pagetopbar{$page} &&
+ defined $config{global_topbars} && ! $config{global_topbars};
+
my $topbar_page=bestlink($page, "topbar") || return;
my $topbar_file=$pagesources{$topbar_page} || return;
my $topbar_type=pagetype($topbar_file);
@@ -26,7 +75,16 @@ sub topbar_content ($) { #{{{
# currently requires a wiki rebuild.
add_depends($page, $topbar_page);
- my $content=readfile(srcfile($topbar_file));
+ my $content;
+ if (defined $oldfile && $topbar_file eq $oldfile) {
+ $content=$oldcontent;
+ }
+ else {
+ $content=readfile(srcfile($topbar_file));
+ $oldcontent=$content;
+ $oldfile=$topbar_file;
+ }
+
return unless length $content;
return IkiWiki::htmlize($topbar_page, $page, $topbar_type,
IkiWiki::linkify($topbar_page, $page,
@@ -34,20 +92,19 @@ sub topbar_content ($) { #{{{
IkiWiki::filter($topbar_page, $page, $content))));
}
-} # }}}
+}
-sub pagetemplate (@) { #{{{
+sub pagetemplate (@) {
my %params=@_;
- my $page=$params{page};
my $template=$params{template};
-
- if ($template->query(name => "topbar")) {
- my $content=topbar_content($page);
+ if ($params{destpage} eq $params{page} &&
+ $template->query(name => "topbar")) {
+ my $content=topbar_content($params{destpage});
if (defined $content && length $content) {
$template->param(topbar => $content);
}
}
-} # }}}
+}
1