Projekt-Seite erstellt: Velocity-Template - Extrainfo aus site.xml eingelesen
authorKai Moritz <kai@juplo.de>
Fri, 8 Jul 2016 08:58:01 +0000 (10:58 +0200)
committerKai Moritz <kai@juplo.de>
Mon, 11 Jul 2016 16:55:59 +0000 (18:55 +0200)
Für <menu>- und <item>-Tags in der site.xml können die Attribute "title",
"alt" und "img" angegeben werden. Diese Daten werden jetzt zusätzlich in
dem generierten JSON verfügbar gemacht. Für <item> als Einträge unterhalb
der Seite. Für das selbstdefinierte Menü (das unbenannte!) als
Top-Level-Variablen "site_title", "site_alt" und "site_img".

src/site/template.vm

index 27ecbdf..6a5b765 100644 (file)
   #set ( $sinkhole = $page.put("childs", $project.getClass().forName('java.util.LinkedHashMap').newInstance()) )
   #set ( $sinkhole = $stack.push( $page ) )
 
+  #if ($menu.title)
+    #set( $sinkhole = $page.put("title", $menu.title) )
+  #end
+  #if ($menu.alt)
+    #set( $sinkhole = $page.put("alt", $menu.alt) )
+  #end
+  #if ($menu.img)
+    #set( $sinkhole = $page.put("img", $menu.img) )
+  #end
+
   #foreach ( $item in $menu.items )
     #buildPages ( $item )
   #end
 
   #else
 
-    <!-- DONE WITH MENUE ---- #if($page.name)$page.name#else(no name)#end -->
+    <!-- DONE WITH MENUE ---- #if($page.name)$page.name-->#else(no name)-->
+      #set( $siteTitle = $menu.title )
+      #set( $siteAlt = $menu.alt )
+      #set( $siteImg = $menu.img )
+    #end
+
   #end
 #end
 
     <link rel="canonical" href="$project.url/$alignedFileName"/>
   </head>
   <body>
-    <article class="main" layout:fragment="maincontent" juplo:variables='merge:{"pages":{#set($sep = "")#foreach($page in $pages)$sep"$page.uri":{"name":"$page.name",#if(!$page.childs.isEmpty())"childs":{#set($csep = "")#foreach($child in $page.childs.entrySet())$csep"$child.key":"$child.value"#set($csep = ",")#end},#end"crumbs":[#set($csep = "")#foreach($crumb in $page.crumbs)$csep{"uri":"$crumb.uri","name":"$crumb.name"}#set($csep = ",")#end]}#set($sep = ",")#end}}'>
+    <article class="main" layout:fragment="maincontent" juplo:variables='merge:{"pages":{#set($sep = "")#foreach($page in $pages)$sep"$page.uri":{"name":"$page.name",#if(!$page.childs.isEmpty())"childs":{#set($csep = "")#foreach($child in $page.childs.entrySet())$csep"$child.key":"$child.value"#set($csep = ",")#end},#end"crumbs":[#set($csep = "")#foreach($crumb in $page.crumbs)$csep{"uri":"$crumb.uri","name":"$crumb.name"}#set($csep = ",")#end]#if($page.title),"title":"$page.title"#end#if($page.alt),"alt":"$page.alt"#end#if($page.img),"img":"$page.img"#end}#set($sep = ",")#end}#if($siteTitle),"site_title":"$siteTitle"#end#if($siteAlt),"site_alt":"$siteAlt"#end#if($siteImg),"site_img":"$siteImg"#end}'>
       <header><h1>$shortTitle</h1></header>
       $bodyContent
     </article>