lib/breadcrumbs.tmpl
author Frank-Rainer Grahl <frgrahl@gmx.net>
Tue, 15 Jun 2021 15:01:50 +0200
changeset 1474 b3692a058babb8132ade0c0f0e6b74dad03bb21b
parent 19 8377697a39a79152ca24ddf5d813578109efe349
permissions -rw-r--r--
Bug 1716547 - Switch to libera chat for irc support. rs=me

[%
   # Load the sitemap once per build and cache it for reuse on each page.
   IF !global.cached.xpath;
     USE xpath = XML.XPath("lib/sitemap.xml");
     global.cached.xpath = xpath;
   END;

   BLOCK breadcrumbs;
     my_path = "${template.name}"|replace('/index.html|/index.en.html','/')|replace('.html|.en.html','');
     nodes = [global.cached.xpath.findnodes("//page[@url='$my_path']")];
     UNLESS nodes;
       my_id = "${template.name}"|replace('/index.html|/index.en.html|.html|.en.html','')|replace('^.+/','');
       nodes = [global.cached.xpath.findnodes("//page[@id='$my_id']")];
     END;

     PROCESS crumb crumbs=[] node=nodes.0;

     u = "";
     FOREACH crumb IN crumbs.reverse;
       IF loop.first;
         "<a href=\"$toplink\">Home</a> ";
       END;

       " &#187; ";

       IF loop.last;
         "<span>$crumb.title</span>";
       ELSE;
         IF crumb.url;
           u = "$crumb.url";
         ELSE;
           u = "$u/$crumb.id";
         END;
         "<a href=\"$toplink$u\">$crumb.title</a>";
       END;
     END;
   END;

   BLOCK crumb;
     IF node && node.getName() == "page";
       crumbs.push({ title => node.getAttribute("title"),
                     id    => node.getAttribute("id"),
                     url    => node.getAttribute("url") });
       PROCESS crumb node=node.getParentNode();
     END;
   END;
%]