From a8af271e5aed1c4aef3f66cee0847d609aedc705 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 4 Oct 2009 16:28:14 -0400 Subject: document effect of contentless dependencies on sidebar efficiency --- doc/plugins/sidebar.mdwn | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'doc/plugins/sidebar.mdwn') diff --git a/doc/plugins/sidebar.mdwn b/doc/plugins/sidebar.mdwn index 36982eff3..4e356d65a 100644 --- a/doc/plugins/sidebar.mdwn +++ b/doc/plugins/sidebar.mdwn @@ -16,6 +16,10 @@ will turn off the sidebar altogether. Warning: Any change to the sidebar will cause a rebuild of the whole wiki, since every page includes a copy that has to be updated. This can -especially be a problem if the sidebar includes [[inline]] or [[map]] -directives, since any changes to pages inlined or mapped onto the sidebar +especially be a problem if the sidebar includes an [[ikiwiki/directive/inline]] +directive, since any changes to pages inlined into the sidebar will change the sidebar and cause a full wiki rebuild. + +Instead, if you include a [[ikiwiki/directive/map]] directive on the sidebar, +and it does not use the `show` parameter, only adding or removing pages +included in the map will cause a full rebuild. Modifying pages will not. -- cgit v1.2.3 From 358fa953e189d6f8a7925be8533fe7b7c5699503 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 15 Apr 2010 16:40:01 -0400 Subject: sidebar: Now a sidebar directive can be used to override the sidebar shown on a page. --- IkiWiki/Plugin/sidebar.pm | 42 +++++++++++++++++++++++++++++++++++++- debian/changelog | 2 ++ doc/ikiwiki/directive/sidebar.mdwn | 14 +++++++++++++ doc/plugins/sidebar.mdwn | 17 +++++++-------- 4 files changed, 66 insertions(+), 9 deletions(-) create mode 100644 doc/ikiwiki/directive/sidebar.mdwn (limited to 'doc/plugins/sidebar.mdwn') diff --git a/IkiWiki/Plugin/sidebar.pm b/IkiWiki/Plugin/sidebar.pm index 41812e1c1..d63cb5246 100644 --- a/IkiWiki/Plugin/sidebar.pm +++ b/IkiWiki/Plugin/sidebar.pm @@ -10,6 +10,7 @@ use IkiWiki 3.00; sub import { hook(type => "getsetup", id => "sidebar", call => \&getsetup); + hook(type => "preprocess", id => "sidebar", call => \&preprocess); hook(type => "pagetemplate", id => "sidebar", call => \&pagetemplate); } @@ -21,9 +22,39 @@ sub getsetup () { }, } +my %pagesidebar; + +sub preprocess (@) { + my %params=@_; + my $content=shift; + shift; + + if (! defined $content) { + error(gettext("sidebar content not specified")); + } + + my $page=$params{page}; + return "" unless $page eq $params{destpage}; + my $file = $pagesources{$page}; + my $type = pagetype($file); + + $pagesidebar{$page}= + IkiWiki::htmlize($page, $page, $type, + IkiWiki::linkify($page, $page, + IkiWiki::preprocess($page, $page, + IkiWiki::filter($page, $page, $content)))); + + return ""; +} + +my $oldfile; +my $oldcontent; + sub sidebar_content ($) { my $page=shift; + return $pagesidebar{$page} if exists $pagesidebar{$page}; + my $sidebar_page=bestlink($page, "sidebar") || return; my $sidebar_file=$pagesources{$sidebar_page} || return; my $sidebar_type=pagetype($sidebar_file); @@ -34,7 +65,16 @@ sub sidebar_content ($) { # currently requires a wiki rebuild. add_depends($page, $sidebar_page); - my $content=readfile(srcfile($sidebar_file)); + my $content; + if (defined $oldfile && $sidebar_file eq $oldfile) { + $content=$oldcontent; + } + else { + $content=readfile(srcfile($sidebar_file)); + $oldcontent=$content; + $oldfile=$sidebar_file; + } + return unless length $content; return IkiWiki::htmlize($sidebar_page, $page, $sidebar_type, IkiWiki::linkify($sidebar_page, $page, diff --git a/debian/changelog b/debian/changelog index 03361e6a0..267a2fd7a 100644 --- a/debian/changelog +++ b/debian/changelog @@ -37,6 +37,8 @@ ikiwiki (3.20100415) UNRELEASED; urgency=low in a tag cloud. This is useful to put in a sidebar. * Rework example blog front page. * CSS and templates for sidebar changed to use a class, not an id. + * sidebar: Now a sidebar directive can be used to override the sidebar + shown on a page. -- Joey Hess Sun, 04 Apr 2010 12:17:11 -0400 diff --git a/doc/ikiwiki/directive/sidebar.mdwn b/doc/ikiwiki/directive/sidebar.mdwn new file mode 100644 index 000000000..46f016747 --- /dev/null +++ b/doc/ikiwiki/directive/sidebar.mdwn @@ -0,0 +1,14 @@ +The `sidebar` directive is supplied by the [[!iki plugins/sidebar desc=sidebar]] plugin. + +This directive specifies a custom sidebar to display on the page, instead +of any sidebar that is displayed globally. + +## examples + + \[[!sidebar """ + This is my custom sidebar for this page. + + \[[!calendar pages="posts/*"]] + """]] + +[[!meta robots="noindex, follow"]] diff --git a/doc/plugins/sidebar.mdwn b/doc/plugins/sidebar.mdwn index 4e356d65a..cd0f0ecf1 100644 --- a/doc/plugins/sidebar.mdwn +++ b/doc/plugins/sidebar.mdwn @@ -10,15 +10,16 @@ Typically this will be a page in the root of the wiki, but it can also be a [[plugins/sidebar|plugins/sidebar]], will be treated as a sidebar for the [[plugins]] page, and of all of its SubPages, if the plugin is enabled. -Note that to disable a sidebar for a [[ikiwiki/SubPage]] of a page that has -a sidebar, you can create a sidebar page that is completely empty. This -will turn off the sidebar altogether. +There is also a [[ikiwiki/directive/sidebar]] directive that can be used +to provide a custom sidebar content for a page. -Warning: Any change to the sidebar will cause a rebuild of the whole wiki, -since every page includes a copy that has to be updated. This can -especially be a problem if the sidebar includes an [[ikiwiki/directive/inline]] -directive, since any changes to pages inlined into the sidebar -will change the sidebar and cause a full wiki rebuild. +---- + +Warning: Any change to the sidebar page will cause a rebuild of the whole +wiki, since every page includes a copy that has to be updated. This can +especially be a problem if the sidebar includes an +[[ikiwiki/directive/inline]] directive, since any changes to pages inlined +into the sidebar will change the sidebar and cause a full wiki rebuild. Instead, if you include a [[ikiwiki/directive/map]] directive on the sidebar, and it does not use the `show` parameter, only adding or removing pages -- cgit v1.2.3 From 1f7175e891f87c350decc1ec821bebb5adc22c2a Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 15 Apr 2010 17:31:50 -0400 Subject: sidebar: Add global_sidebars setting. --- IkiWiki/Plugin/sidebar.pm | 9 +++++++++ debian/changelog | 1 + doc/ikiwiki/directive/sidebar.mdwn | 4 ++-- doc/plugins/sidebar.mdwn | 8 +++++--- 4 files changed, 17 insertions(+), 5 deletions(-) (limited to 'doc/plugins/sidebar.mdwn') diff --git a/IkiWiki/Plugin/sidebar.pm b/IkiWiki/Plugin/sidebar.pm index d63cb5246..1b302dcf9 100644 --- a/IkiWiki/Plugin/sidebar.pm +++ b/IkiWiki/Plugin/sidebar.pm @@ -20,6 +20,13 @@ sub getsetup () { safe => 1, rebuild => 1, }, + global_sidebars => { + type => "boolean", + examples => 1, + description => "show sidebar page on all pages?" + safe => 1, + rebuild => 1, + }, } my %pagesidebar; @@ -55,6 +62,8 @@ sub sidebar_content ($) { return $pagesidebar{$page} if exists $pagesidebar{$page}; + return if defined $config{global_sidebars} && !$config{global_sidebars}; + my $sidebar_page=bestlink($page, "sidebar") || return; my $sidebar_file=$pagesources{$sidebar_page} || return; my $sidebar_type=pagetype($sidebar_file); diff --git a/debian/changelog b/debian/changelog index af19f4a00..c379253d7 100644 --- a/debian/changelog +++ b/debian/changelog @@ -40,6 +40,7 @@ ikiwiki (3.20100415) UNRELEASED; urgency=low * sidebar: Now a sidebar directive can be used to override the sidebar shown on a page. * Enable calendar and sidebar in auto-blog.setup. + * sidebar: Add global_sidebars setting. -- Joey Hess Sun, 04 Apr 2010 12:17:11 -0400 diff --git a/doc/ikiwiki/directive/sidebar.mdwn b/doc/ikiwiki/directive/sidebar.mdwn index 46f016747..34f078672 100644 --- a/doc/ikiwiki/directive/sidebar.mdwn +++ b/doc/ikiwiki/directive/sidebar.mdwn @@ -1,7 +1,7 @@ The `sidebar` directive is supplied by the [[!iki plugins/sidebar desc=sidebar]] plugin. -This directive specifies a custom sidebar to display on the page, instead -of any sidebar that is displayed globally. +This directive specifies a custom sidebar to display on the page, +overriding any sidebar that is displayed globally. ## examples diff --git a/doc/plugins/sidebar.mdwn b/doc/plugins/sidebar.mdwn index cd0f0ecf1..012733456 100644 --- a/doc/plugins/sidebar.mdwn +++ b/doc/plugins/sidebar.mdwn @@ -1,9 +1,11 @@ [[!template id=plugin name=sidebar author="Tuomo Valkonen"]] [[!tag type/chrome]] -If this plugin is enabled, then a sidebar is added to pages in the wiki. -The content of the sidebar is simply the content of a page named -"sidebar" (ie, create a "sidebar.mdwn"). +This plugin allows adding a sidebar to pages in the wiki. + +By default, and unless the `global_sidebars` setting is turned off, +a sidebar is added to all pages in the wiki. The content of the sidebar +is simply the content of a page named "sidebar" (ie, create a "sidebar.mdwn"). Typically this will be a page in the root of the wiki, but it can also be a [[ikiwiki/SubPage]]. In fact, this page, -- cgit v1.2.3