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 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) (limited to 'IkiWiki/Plugin/sidebar.pm') 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, -- 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 'IkiWiki/Plugin/sidebar.pm') 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 From d63e043f0abf642ff4048cc20c6caf03db3e55fb Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 15 Apr 2010 17:38:13 -0400 Subject: 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 (limited to 'IkiWiki/Plugin/sidebar.pm') 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"]] -- cgit v1.2.3 From 4c6f5a48bcfc2462a915387515bfa39b9239a7da Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 15 Apr 2010 17:50:43 -0400 Subject: fix sidebar directive parameter handling --- IkiWiki/Plugin/sidebar.pm | 6 ++---- doc/ikiwiki/directive/sidebar.mdwn | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) (limited to 'IkiWiki/Plugin/sidebar.pm') diff --git a/IkiWiki/Plugin/sidebar.pm b/IkiWiki/Plugin/sidebar.pm index f706480ca..808f0bed2 100644 --- a/IkiWiki/Plugin/sidebar.pm +++ b/IkiWiki/Plugin/sidebar.pm @@ -33,13 +33,11 @@ my %pagesidebar; sub preprocess (@) { my %params=@_; - my $content=shift; - shift; my $page=$params{page}; return "" unless $page eq $params{destpage}; - if (! defined $content) { + if (! defined $params{content}) { $pagesidebar{$page}=undef; } else { @@ -50,7 +48,7 @@ sub preprocess (@) { IkiWiki::htmlize($page, $page, $type, IkiWiki::linkify($page, $page, IkiWiki::preprocess($page, $page, - IkiWiki::filter($page, $page, $content)))); + IkiWiki::filter($page, $page, $params{content})))); } return ""; diff --git a/doc/ikiwiki/directive/sidebar.mdwn b/doc/ikiwiki/directive/sidebar.mdwn index 401d7c786..599695d22 100644 --- a/doc/ikiwiki/directive/sidebar.mdwn +++ b/doc/ikiwiki/directive/sidebar.mdwn @@ -9,7 +9,7 @@ used to disable use of the sidebar page by default. ## examples - \[[!sidebar """ + \[[!sidebar content=""" This is my custom sidebar for this page. \[[!calendar pages="posts/*"]] -- cgit v1.2.3 From dd64c2a9c0d7a1bfe9d3b89957efe8f045091111 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 15 Apr 2010 22:18:56 -0400 Subject: sidebar plugin optimisations 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. --- IkiWiki/Plugin/sidebar.pm | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'IkiWiki/Plugin/sidebar.pm') diff --git a/IkiWiki/Plugin/sidebar.pm b/IkiWiki/Plugin/sidebar.pm index 808f0bed2..0350f2b71 100644 --- a/IkiWiki/Plugin/sidebar.pm +++ b/IkiWiki/Plugin/sidebar.pm @@ -60,7 +60,7 @@ my $oldcontent; 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}; @@ -97,11 +97,10 @@ sub sidebar_content ($) { sub pagetemplate (@) { my %params=@_; - my $page=$params{page}; 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); } -- cgit v1.2.3 From 8e77dc1c9cda0777158b12025d6123452e090765 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sat, 15 May 2010 23:54:00 -0400 Subject: fix typo --- IkiWiki/Plugin/sidebar.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'IkiWiki/Plugin/sidebar.pm') diff --git a/IkiWiki/Plugin/sidebar.pm b/IkiWiki/Plugin/sidebar.pm index 0350f2b71..2d495db2c 100644 --- a/IkiWiki/Plugin/sidebar.pm +++ b/IkiWiki/Plugin/sidebar.pm @@ -22,7 +22,7 @@ sub getsetup () { }, global_sidebars => { type => "boolean", - examples => 1, + example => 1, description => "show sidebar page on all pages?", safe => 1, rebuild => 1, -- cgit v1.2.3 From 192ce7a238af9021b0fd6dd571f22409af81ebaf Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 4 Jul 2010 15:00:51 -0400 Subject: remove unnecessary and troublesome filter calls This better defines what the filter hook is passed, to only be the raw, complete text of a page. Not some snippet, or data read in from an unrelated template. Several plugins that filtered text that originates from an (already filtered) page were modified not to do that. Note that this was not done very consistently before; other plugins that receive text from a page called preprocess on it w/o first calling filter. The template plugin gets text from elsewhere, and was also changed not to filter it. That leads to one known regression -- the embed plugin cannot be used to embed stuff in templates now. But that plugin is deprecated anyway. Later we may want to increase the coverage of what is filtered. Perhaps a good goal would be to allow writing a filter plugin that filters out unwanted words, from any input. We're not there yet; not only does the template plugin load unfiltered text from its templates now, but so can the table plugin, and other plugins that use templates (like inline!). I think we can cross that bridge when we come to it. If I wanted such a censoring plugin, I'd probably make it use a sanitize hook instead, for the better coverage. For now I am concentrating on the needs of the two non-deprecated users of filter. This should fix bugs/po_vs_templates, and it probably fixes an obscure bug around txt's use of filter for robots.txt. --- IkiWiki/Plugin/color.pm | 11 +++++------ IkiWiki/Plugin/comments.pm | 2 -- IkiWiki/Plugin/conditional.pm | 3 +-- IkiWiki/Plugin/cutpaste.pm | 8 ++++---- IkiWiki/Plugin/more.pm | 6 +++--- IkiWiki/Plugin/sidebar.pm | 3 +-- IkiWiki/Plugin/template.pm | 6 ++---- IkiWiki/Plugin/toggle.pm | 3 +-- doc/plugins/write.mdwn | 4 ++-- 9 files changed, 19 insertions(+), 27 deletions(-) (limited to 'IkiWiki/Plugin/sidebar.pm') diff --git a/IkiWiki/Plugin/color.pm b/IkiWiki/Plugin/color.pm index d550dd9f4..9bb2359ce 100644 --- a/IkiWiki/Plugin/color.pm +++ b/IkiWiki/Plugin/color.pm @@ -61,12 +61,11 @@ sub replace_preserved_style ($) { sub preprocess (@) { my %params = @_; - # Preprocess the text to expand any preprocessor directives - # embedded inside it. - $params{text} = IkiWiki::preprocess($params{page}, $params{destpage}, - IkiWiki::filter($params{page}, $params{destpage}, $params{text})); - - return preserve_style($params{foreground}, $params{background}, $params{text}); + return preserve_style($params{foreground}, $params{background}, + # Preprocess the text to expand any preprocessor directives + # embedded inside it. + IkiWiki::preprocess($params{page}, $params{destpage}, + $params{text})); } sub format (@) { diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm index d34951570..64eb7fb09 100644 --- a/IkiWiki/Plugin/comments.pm +++ b/IkiWiki/Plugin/comments.pm @@ -142,8 +142,6 @@ sub preprocess { } $content =~ s/\\"/"/g; - $content = IkiWiki::filter($page, $params{destpage}, $content); - if ($config{comments_allowdirectives}) { $content = IkiWiki::preprocess($page, $params{destpage}, $content); diff --git a/IkiWiki/Plugin/conditional.pm b/IkiWiki/Plugin/conditional.pm index 8a5796149..026078b3c 100644 --- a/IkiWiki/Plugin/conditional.pm +++ b/IkiWiki/Plugin/conditional.pm @@ -59,8 +59,7 @@ sub preprocess_if (@) { else { $ret=""; } - return IkiWiki::preprocess($params{page}, $params{destpage}, - IkiWiki::filter($params{page}, $params{destpage}, $ret)); + return IkiWiki::preprocess($params{page}, $params{destpage}, $ret); } package IkiWiki::PageSpec; diff --git a/IkiWiki/Plugin/cutpaste.pm b/IkiWiki/Plugin/cutpaste.pm index 01e9ce043..4a8817168 100644 --- a/IkiWiki/Plugin/cutpaste.pm +++ b/IkiWiki/Plugin/cutpaste.pm @@ -50,8 +50,8 @@ sub preprocess_copy (@) { $savedtext{$params{page}} = {} if not exists $savedtext{$params{"page"}}; $savedtext{$params{page}}->{$params{id}} = $params{text}; - return IkiWiki::preprocess($params{page}, $params{destpage}, - IkiWiki::filter($params{page}, $params{destpage}, $params{text})) if defined wantarray; + return IkiWiki::preprocess($params{page}, $params{destpage}, $params{text}) + if defined wantarray; } sub preprocess_paste (@) { @@ -70,8 +70,8 @@ sub preprocess_paste (@) { error sprintf(gettext('no text was copied in this page with id %s'), $params{id}); } - return IkiWiki::preprocess($params{page}, $params{destpage}, - IkiWiki::filter($params{page}, $params{destpage}, $savedtext{$params{page}}->{$params{id}})); + return IkiWiki::preprocess($params{page}, $params{destpage}, + $savedtext{$params{page}}->{$params{id}}); } 1; diff --git a/IkiWiki/Plugin/more.pm b/IkiWiki/Plugin/more.pm index 266c8e1d0..80e339a1b 100644 --- a/IkiWiki/Plugin/more.pm +++ b/IkiWiki/Plugin/more.pm @@ -33,9 +33,9 @@ sub preprocess (@) { anchor => "more"); } else { - $params{text}=IkiWiki::preprocess($params{page}, $params{destpage}, - IkiWiki::filter($params{page}, $params{destpage}, $params{text})); - return "\n\n".$params{text}; + return "\n\n". + IkiWiki::preprocess($params{page}, $params{destpage}, + $params{text}); } } diff --git a/IkiWiki/Plugin/sidebar.pm b/IkiWiki/Plugin/sidebar.pm index 2d495db2c..c1146b7b4 100644 --- a/IkiWiki/Plugin/sidebar.pm +++ b/IkiWiki/Plugin/sidebar.pm @@ -47,8 +47,7 @@ sub preprocess (@) { $pagesidebar{$page}= IkiWiki::htmlize($page, $page, $type, IkiWiki::linkify($page, $page, - IkiWiki::preprocess($page, $page, - IkiWiki::filter($page, $page, $params{content})))); + IkiWiki::preprocess($page, $page, $params{content}))); } return ""; diff --git a/IkiWiki/Plugin/template.pm b/IkiWiki/Plugin/template.pm index b8c2f05b2..db26bfe31 100644 --- a/IkiWiki/Plugin/template.pm +++ b/IkiWiki/Plugin/template.pm @@ -53,8 +53,7 @@ sub preprocess (@) { foreach my $param (keys %params) { my $value=IkiWiki::preprocess($params{page}, $params{destpage}, - IkiWiki::filter($params{page}, $params{destpage}, - $params{$param}), $scan); + $params{$param}, $scan); if ($template->query(name => $param)) { my $htmlvalue=IkiWiki::htmlize($params{page}, $params{destpage}, pagetype($pagesources{$params{page}}), @@ -69,8 +68,7 @@ sub preprocess (@) { } return IkiWiki::preprocess($params{page}, $params{destpage}, - IkiWiki::filter($params{page}, $params{destpage}, - $template->output), $scan); + $template->output, $scan); } 1 diff --git a/IkiWiki/Plugin/toggle.pm b/IkiWiki/Plugin/toggle.pm index 3319421d9..20967d3fd 100644 --- a/IkiWiki/Plugin/toggle.pm +++ b/IkiWiki/Plugin/toggle.pm @@ -50,8 +50,7 @@ sub preprocess_toggleable (@) { # Preprocess the text to expand any preprocessor directives # embedded inside it. - $params{text}=IkiWiki::preprocess($params{page}, $params{destpage}, - IkiWiki::filter($params{page}, $params{destpage}, $params{text})); + $params{text}=IkiWiki::preprocess($params{page}, $params{destpage}, $params{text}); my $id=genid($params{page}, $params{id}); my $class=(lc($params{open}) ne "yes") ? "toggleable" : "toggleable-open"; diff --git a/doc/plugins/write.mdwn b/doc/plugins/write.mdwn index bb8012342..2e3902388 100644 --- a/doc/plugins/write.mdwn +++ b/doc/plugins/write.mdwn @@ -198,8 +198,8 @@ value is ignored. hook(type => "filter", id => "foo", call => \&filter); -Runs on the raw source of a page, before anything else touches it, and can -make arbitrary changes. The function is passed named parameters "page", +Runs on the full raw source of a page, before anything else touches it, and +can make arbitrary changes. The function is passed named parameters "page", "destpage", and "content". It should return the filtered content. ### preprocess -- cgit v1.2.3