%#
%# crumbs - generate breadcrumbs with optional links
%# example: <& gallery/m/crumbs, '/pics/photos/people', 1 &>
%#
<%perl>
    my ($path, $link) = @_;
    my (@crumbs, $root, $n);

    $root = $m->top_comp->dir_path;
    $path =~ s|^$root/?||;
    @crumbs = ($m->comp('config')->{gallery_name}, split(/\//, $path));
    $n = $#crumbs - (($path =~ /\/$/) ? 1 : 2);

    if ($link && @crumbs > 1) {
	for (0..$n) {
	    $crumbs[$_] = '<a href="' . '../' x ($n + 1 - $_) . "\">$crumbs[$_]</a>";
	}

	$crumbs[-2] = qq(<a href="./">$crumbs[-2]</a>)
	    unless $path =~ /\/$/;
    }
</%perl>
<% join(':&nbsp;', @crumbs) %>\
