From 355a930843afbbb7317bb0da4885cdbda72b36a7 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Fri, 8 Jul 2016 09:04:46 +0200 Subject: [PATCH] Reworked the processing of the page-data Automatically generated pages can be overwriten in the manually defined menu. Overwriting a URI will result in the changing of the name of the page. Child-pages be kept in place, if present. If an automatically generated page is overwriten in the manually defined menu, it will not be removed form the original menu, but its breadcrumb-data will reflect the position of the manually defined entry. Implementation: The data is read into a map. The unnamed menus will be read in last, because this are usually the manually defined menus. If an URI is encountered again, the last read version of the defined page will win and overwrite the previously read definition, but the defined child-pages will not be touched. --- src/main/resources/META-INF/maven/site.vm | 60 +++++++++++++++++++---- 1 file changed, 51 insertions(+), 9 deletions(-) diff --git a/src/main/resources/META-INF/maven/site.vm b/src/main/resources/META-INF/maven/site.vm index 4fda7f5..c91a1b2 100644 --- a/src/main/resources/META-INF/maven/site.vm +++ b/src/main/resources/META-INF/maven/site.vm @@ -2,26 +2,68 @@ -## Automatisch generierte Seiten einlesen #set ( $pages = $project.getClass().forName('java.util.LinkedHashMap').newInstance() ) -#macro ( buildPages $items ) - #foreach ( $item in $items ) - #set ( $currentItemHref = $PathTool.calculateLink( $item.href, $relativePath ) ) - #set ( $currentItemHref = $currentItemHref.replaceAll( '\\', '/' ) ) - #set ( $sinkhole = $pages.put( $item.name, $currentItemHref ) ) - #if ( !$item.items.empty ) - #buildPages ( $item.items ) +#set ( $stack = $project.getClass().forName('java.util.LinkedList').newInstance() ) +#macro ( buildPages $menu ) + + #set ( $currentItemHref = $PathTool.calculateLink( $item.href, $relativePath ) ) + #set ( $currentItemHref = $currentItemHref.replaceAll( '\\', '/' ) ) + + #if ($currentItemHref) + #set( $sinkhole = $stack.peek().childs.put($currentItemHref, $menu.name) ) + #end + + #set ( $page = $project.getClass().forName('java.util.LinkedHashMap').newInstance() ) + #set ( $sinkhole = $page.put("name", $menu.name) ) + #set ( $sinkhole = $page.put("uri", $currentItemHref) ) + #set ( $sinkhole = $page.put("childs", $project.getClass().forName('java.util.LinkedHashMap').newInstance()) ) + #set ( $sinkhole = $stack.push( $page ) ) + + #foreach ( $item in $menu.items ) + #buildPages ( $item ) + #end + + #set ( $page = $stack.pop() ) + #if ( $page.uri != "" ) + + #if ( $pages.containsKey($page.uri) ) + #set ( $childs = $pages.get($page.uri).childs ) + #set ( $sinkhole = $page.put("childs", $childs) ) + + + #else + + #end + + #set ( $sinkhole = $pages.put($page.uri, $page) ) + #set ( $sinkhole = $page.remove("uri") ) + + #else + + #end #end + + +## Seiten einlesen #foreach ( $menu in $decoration.body.menus ) ## Nur benannte Menüs werden berücksichtigt #if ($menu.name) - #buildPages ( $menu.items ) + #buildPages ( $menu ) #end #end +#foreach ( $menu in $decoration.body.menus ) + ## Nur unbenannte Menüs werden berücksichtigt + #if (!($menu.name)) + #buildPages ( $menu ) + #end +#end + + + #set ( $crumbs = $project.getClass().forName('java.util.LinkedHashMap').newInstance() ) #macro ( searchBreadcrumbTrail $items ) #set ( $sep = '' ) -- 2.20.1