From d63e043f0abf642ff4048cc20c6caf03db3e55fb Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 15 Apr 2010 17:38:13 -0400 Subject: [PATCH] allow sidebar directive to enable use of sidebar page This way, the example blog always has a sidebar on the index page, but not the overhead of sidebars on all the other pages. And if a user wants to, they can enable global_sidebars to switch to sidebars on every page. --- IkiWiki/Plugin/sidebar.pm | 33 ++++++++++++++++-------------- doc/examples/blog/index.mdwn | 10 +-------- doc/examples/blog/sidebar.mdwn | 9 ++++++++ doc/ikiwiki/directive/sidebar.mdwn | 8 +++++++- 4 files changed, 35 insertions(+), 25 deletions(-) create mode 100644 doc/examples/blog/sidebar.mdwn diff --git a/IkiWiki/Plugin/sidebar.pm b/IkiWiki/Plugin/sidebar.pm index 1b302dcf9..f706480ca 100644 --- a/IkiWiki/Plugin/sidebar.pm +++ b/IkiWiki/Plugin/sidebar.pm @@ -23,7 +23,7 @@ sub getsetup () { global_sidebars => { type => "boolean", examples => 1, - description => "show sidebar page on all pages?" + description => "show sidebar page on all pages?", safe => 1, rebuild => 1, }, @@ -36,20 +36,22 @@ sub preprocess (@) { 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)))); + + if (! defined $content) { + $pagesidebar{$page}=undef; + } + else { + 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 ""; } @@ -60,9 +62,10 @@ my $oldcontent; sub sidebar_content ($) { my $page=shift; - return $pagesidebar{$page} if exists $pagesidebar{$page}; + return $pagesidebar{$page} if defined $pagesidebar{$page}; - return if defined $config{global_sidebars} && !$config{global_sidebars}; + return if ! exists $pagesidebar{$page} && + defined $config{global_sidebars} && ! $config{global_sidebars}; my $sidebar_page=bestlink($page, "sidebar") || return; my $sidebar_file=$pagesources{$sidebar_page} || return; diff --git a/doc/examples/blog/index.mdwn b/doc/examples/blog/index.mdwn index 062c71f2e..a22c40c72 100644 --- a/doc/examples/blog/index.mdwn +++ b/doc/examples/blog/index.mdwn @@ -1,14 +1,6 @@ [[!inline pages="./posts/* and !*/Discussion" show="10" actions=yes rootpage="posts"]] -[[!sidebar """ -[[Tags]]: [[!pagestats style="list" pages="./tags/*" among="./posts/*"]] - -[[Recent Comments|comments]] - -[[Archives]] - -[[!calendar pages="./posts/* and !*/Discussion"]] -"""]] +[[!sidebar]] This blog is powered by [ikiwiki](http://ikiwiki.info). diff --git a/doc/examples/blog/sidebar.mdwn b/doc/examples/blog/sidebar.mdwn new file mode 100644 index 000000000..f24a8e57a --- /dev/null +++ b/doc/examples/blog/sidebar.mdwn @@ -0,0 +1,9 @@ +[[Tags]]: [[!pagestats style="list" pages="./tags/*" among="./posts/*"]] + +[[Recent Comments|comments]] + +[[Archives]] + +[[!if "enabled(calendar)" then=""" +[[!calendar pages="./posts/* and !*/Discussion"]] +"""]] diff --git a/doc/ikiwiki/directive/sidebar.mdwn b/doc/ikiwiki/directive/sidebar.mdwn index 34f078672..401d7c786 100644 --- a/doc/ikiwiki/directive/sidebar.mdwn +++ b/doc/ikiwiki/directive/sidebar.mdwn @@ -1,8 +1,12 @@ The `sidebar` directive is supplied by the [[!iki plugins/sidebar desc=sidebar]] plugin. -This directive specifies a custom sidebar to display on the page, +This directive can specify a custom sidebar to display on the page, overriding any sidebar that is displayed globally. +If no custom sidebar content is specified, it forces the sidebar page to +be used as the sidebar, even if the `global_sidebars` setting has been +used to disable use of the sidebar page by default. + ## examples \[[!sidebar """ @@ -11,4 +15,6 @@ overriding any sidebar that is displayed globally. \[[!calendar pages="posts/*"]] """]] + \[[!sidebar]] + [[!meta robots="noindex, follow"]] -- 2.32.0.93.g670b81a890