This is an automated email from the ASF dual-hosted git repository.

kwin pushed a commit to branch feature/hierarchical-sitemap
in repository https://gitbox.apache.org/repos/asf/sling-site.git

commit 7de3f51527b75f5358c5c96ba58204ad797d7492
Author: Konrad Windszus <[email protected]>
AuthorDate: Fri Jul 23 23:50:16 2021 +0200

    SLING-10659 provide hierarchical sitemap
---
 src/main/jbake/templates/sitemap.tpl | 35 +++++++++++++++++++++++++++--------
 1 file changed, 27 insertions(+), 8 deletions(-)

diff --git a/src/main/jbake/templates/sitemap.tpl 
b/src/main/jbake/templates/sitemap.tpl
index fe217c0..0311385 100644
--- a/src/main/jbake/templates/sitemap.tpl
+++ b/src/main/jbake/templates/sitemap.tpl
@@ -1,3 +1,28 @@
+def printSection(DocumentModel sectionRootDocument, Collection<DocumentModel> 
documents) {
+    // iterate over all direct children of rootUri
+    final String rootUri
+    if (sectionRootDocument != null) {
+        rootUri = sectionRootDocument.uri.take('.html'.length)
+    } else {
+        rootUri = '/'
+    }
+    Collection<DocumentModel> directChildren = documents.findAll( page -> 
page.uri.startsWith(rootUri + "/") )
+    if (directChildren) { // if there are some children found
+        ul {
+            directChildren.filter(sort({ page -> page.title }).each { page -> 
+                li {
+                    a (href:"${config.site_contextPath}${page.uri}") {
+                      yield page.title
+                    }
+                    newLine()
+                    printSection(page, documents)
+                }
+                newLine()
+            }
+        }
+    }
+}
+
 layout 'layout/main.tpl', true,
         projects: projects,
         bodyContents: contents {
@@ -5,14 +30,8 @@ layout 'layout/main.tpl', true,
             div(class:"sitemap"){
                 section(class:"wrap"){
                                        ul {
-                                               published_content.sort({ e -> 
e.title }).each {content ->
-                                                       li {
-                                                               a 
(href:"${config.site_contextPath}${content.uri}") {
-                                                                       yield 
content.title
-                                                               }
-                                                       }
-                                                       newLine()
-                                               }
+                                           // published_content is just a list 
of 
https://github.com/jbake-org/jbake/blob/master/jbake-core/src/main/java/org/jbake/model/DocumentModel.java
 items
+                                               printSection(null, 
published_content)
                                        }
                 }
             }

Reply via email to