<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/perl
#
# Produce a hierarchical map of links.
#
# by Alessandro Dotti Contra &lt;alessandro@hyboria.org&gt;
#
# Revision: 0.2
package IkiWiki::Plugin::map;

use warnings;
use strict;
use IkiWiki;

sub import { #{{{
	hook(type =&gt; "preprocess", id =&gt; "map", call =&gt; \&amp;preprocess);
} # }}}

sub preprocess (@) { #{{{
	my %params=@_;
	$params{pages}="*" unless defined $params{pages};
	
	# Needs to update whenever a page is added or removed, so
	# register a dependency.
	add_depends($params{page}, $params{pages});
	
	# Get all the items to map.
	my @mapitems = ();
	foreach my $page (keys %links) {
		if (pagespec_match($page, $params{pages}, $params{page})) {
			push @mapitems, $page;
		}
	}

	# Create the map.
	my $indent=0;
	my $openli=0;
	my $map = "&lt;div class='map'&gt;\n";
	$map .= "&lt;ul&gt;\n";
	foreach my $item (sort @mapitems) {
		my $depth = ($item =~ tr/\//\//);
		while ($depth &lt; $indent) {
			$indent--;
			$map.="&lt;/li&gt;&lt;/ul&gt;\n";
		}
		while ($depth &gt; $indent) {
			$indent++;
			$map.="&lt;ul&gt;\n";
			$openli=0;
		}
		$map .= "&lt;/li&gt;\n" if $openli;
		$map .= "&lt;li&gt;"
			.htmllink($params{page}, $params{destpage}, $item)
			."\n";
		$openli=1;
	}
	while ($indent &gt; 0) {
		$indent--;
		$map.="&lt;/li&gt;&lt;/ul&gt;\n";
	}
	$map .= "&lt;/li&gt;&lt;/ul&gt;\n";
	$map .= "&lt;/div&gt;\n";
	return $map;
} # }}}

1
</pre></body></html>