+ # Check for a common prefix.
+ if (! defined $common_prefix) {
+ $common_prefix=$page;
+ }
+ elsif (length $common_prefix &&
+ $page !~ /^\Q$common_prefix\E(\/|$)/) {
+ my @a=split(/\//, $page);
+ my @b=split(/\//, $common_prefix);
+ $common_prefix="";
+ while (@a && @b && $a[0] eq $b[0]) {
+ if (length $common_prefix) {
+ $common_prefix.="/";
+ }
+ $common_prefix.=shift(@a);
+ shift @b;
+ }
+ }
+ }
+
+ # Common prefix should not be a page in the map.
+ while (defined $common_prefix && length $common_prefix &&
+ exists $mapitems{$common_prefix}) {
+ $common_prefix=IkiWiki::dirname($common_prefix);
+ }
+
+ # Needs to update whenever a page is added or removed (or in some
+ # cases, when its content changes, if show= is specified), so
+ # register a dependency.
+ add_depends($params{page}, $params{pages}, presence => ! exists $params{show});
+ # Explicitly add all currently shown pages, to detect when pages
+ # are removed.
+ foreach my $item (keys %mapitems) {
+ add_depends($params{page}, $item, presence => ! exists $params{show});