summaryrefslogtreecommitdiff
path: root/doc/bugs/Building_a_sidebar_does_not_regenerate_the_subpages.mdwn
blob: 93aafc2c00a961a45d7815f07ee9f06f01d46b79 (plain)

If sandbox/page.mdwn has been generated and sandbox/sidebar.mdwn is created, the sidebar is only added to sandbox and none of the subpages. --[[TaylorKillian]]

Yes, a known bug. As noted in the code: --[[Joey]]

# FIXME: This isn't quite right; it won't take into account
# adding a new sidebar page. So adding such a page
# currently requires a wiki rebuild.
add_depends($page, $sidebar_page);

Below is a patch for the bug. It's inspired by trying to solve [[todo/Post-compilation inclusion of the sidebar]]. What do you think about it? I have a concern though. If a sidebar is removed, it takes two refreshes to update the affected pages. Is this a feature or a bug? --[[harishcm]]

--- sidebar.pm.orig	2009-11-21 17:40:02.000000000 +0800
+++ sidebar_bugfix.pm	2009-11-21 18:16:11.000000000 +0800
@@ -10,6 +10,7 @@
 
 sub import {
 	hook(type => "getsetup", id => "sidebar", call => \&getsetup);
+	hook(type => "needsbuild", id => "sidebar", call => \&needsbuild);
 	hook(type => "pagetemplate", id => "sidebar", call => \&pagetemplate);
 }
 
@@ -21,6 +22,22 @@
 		},
 }
 
+sub needsbuild (@) {
+	my $needsbuild=shift;
+
+	# Determine every pages' sidebar page
+	foreach my $page (keys %pagesources) {
+		my $sidebar_page='';
+		$sidebar_page=bestlink($page, "sidebar");
+		
+		# If a page's sidebar has changed, force rebuild
+		if (!exists $pagestate{$page}{sidebar}{sidebar_page} || $pagestate{$page}{sidebar}{sidebar_page} ne $sidebar_page) {
+			$pagestate{$page}{sidebar}{sidebar_page} = $sidebar_page;
+			push @$needsbuild, $pagesources{$page};
+		}
+	}
+}
+
 sub sidebar_content ($) {
 	my $page=shift;
 	
@@ -29,9 +46,9 @@
 	my $sidebar_type=pagetype($sidebar_file);
 	
 	if (defined $sidebar_type) {
-		# FIXME: This isn't quite right; it won't take into account
-		# adding a new sidebar page. So adding such a page
-		# currently requires a wiki rebuild.
+		# Record current sidebar page for rechecking bestlink 
+		# during wiki refresh. Also add depends on the sidebar page.
+		$pagestate{$page}{sidebar}{sidebar_page}=$sidebar_page;
 		add_depends($page, $sidebar_page);
 
 		my $content=readfile(srcfile($sidebar_file));