]> sipb.mit.edu Git - ikiwiki.git/commitdiff
allow sidebar directive to enable use of sidebar page
authorJoey Hess <joey@gnu.kitenet.net>
Thu, 15 Apr 2010 21:38:13 +0000 (17:38 -0400)
committerJoey Hess <joey@gnu.kitenet.net>
Thu, 15 Apr 2010 21:38:13 +0000 (17:38 -0400)
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
doc/examples/blog/index.mdwn
doc/examples/blog/sidebar.mdwn [new file with mode: 0644]
doc/ikiwiki/directive/sidebar.mdwn

index 1b302dcf9f80dde6a6f1a6ba6e5620a34e7af593..f706480caabaf3f39855e03ec26f6ee627fcd226 100644 (file)
@@ -23,7 +23,7 @@ sub getsetup () {
                global_sidebars => {
                        type => "boolean",
                        examples => 1,
                global_sidebars => {
                        type => "boolean",
                        examples => 1,
-                       description => "show sidebar page on all pages?"
+                       description => "show sidebar page on all pages?",
                        safe => 1,
                        rebuild => 1,
                },
                        safe => 1,
                        rebuild => 1,
                },
@@ -36,20 +36,22 @@ sub preprocess (@) {
        my $content=shift;
        shift;
 
        my $content=shift;
        shift;
 
-       if (! defined $content) {
-               error(gettext("sidebar content not specified"));
-       }
-
        my $page=$params{page};
        return "" unless $page eq $params{destpage};
        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 "";
 }
 
        return "";
 }
@@ -60,9 +62,10 @@ my $oldcontent;
 sub sidebar_content ($) {
        my $page=shift;
        
 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;
 
        my $sidebar_page=bestlink($page, "sidebar") || return;
        my $sidebar_file=$pagesources{$sidebar_page} || return;
index 062c71f2e68e303e8379456db649720ff34f7c1a..a22c40c72049c39eae000c03563f99e60a104780 100644 (file)
@@ -1,14 +1,6 @@
 [[!inline pages="./posts/* and !*/Discussion" show="10"
 actions=yes rootpage="posts"]]
 
 [[!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).
 
 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 (file)
index 0000000..f24a8e5
--- /dev/null
@@ -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"]]
+"""]]
index 34f078672e4a60b5cf0e778b3aa24f2819206fc2..401d7c786c7ceb8e5bfcce270cb0e131ecab944c 100644 (file)
@@ -1,8 +1,12 @@
 The `sidebar` directive is supplied by the [[!iki plugins/sidebar desc=sidebar]] plugin.
 
 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.
 
 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 """
 ## examples
 
        \[[!sidebar """
@@ -11,4 +15,6 @@ overriding any sidebar that is displayed globally.
        \[[!calendar pages="posts/*"]]
        """]]
 
        \[[!calendar pages="posts/*"]]
        """]]
 
+       \[[!sidebar]]
+
 [[!meta robots="noindex, follow"]]
 [[!meta robots="noindex, follow"]]