You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by kw...@apache.org on 2021/07/26 14:00:50 UTC
[sling-site] branch master updated: SLING-10659 provide
hierarchical sitemap (#65)
This is an automated email from the ASF dual-hosted git repository.
kwin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-site.git
The following commit(s) were added to refs/heads/master by this push:
new a7ae625 SLING-10659 provide hierarchical sitemap (#65)
a7ae625 is described below
commit a7ae62505841f5e58d30aa82dbbdf20d3c9d35fb
Author: Konrad Windszus <kw...@apache.org>
AuthorDate: Mon Jul 26 16:00:45 2021 +0200
SLING-10659 provide hierarchical sitemap (#65)
Co-authored-by: Bertrand Delacretaz <bd...@apache.org>
---
pom.xml | 5 ++++
src/main/jbake/assets/robots.txt | 4 ++++
src/main/jbake/content/sitemap.md | 2 +-
src/main/jbake/jbake.properties | 10 +++++---
src/main/jbake/templates/htmlsitemap.tpl | 35 ++++++++++++++++++++++++++++
src/main/jbake/templates/includes/Git.groovy | 5 +++-
src/main/jbake/templates/sitemap.tpl | 27 +++++++--------------
7 files changed, 65 insertions(+), 23 deletions(-)
diff --git a/pom.xml b/pom.xml
index 249fe5f..39820fe 100644
--- a/pom.xml
+++ b/pom.xml
@@ -78,6 +78,11 @@
<artifactId>groovy-templates</artifactId>
<version>3.0.2</version>
</dependency>
+ <dependency>
+ <groupId>org.codehaus.groovy</groupId>
+ <artifactId>groovy-dateutil</artifactId>
+ <version>3.0.2</version>
+ </dependency>
</dependencies>
<executions>
diff --git a/src/main/jbake/assets/robots.txt b/src/main/jbake/assets/robots.txt
new file mode 100644
index 0000000..d2fe96c
--- /dev/null
+++ b/src/main/jbake/assets/robots.txt
@@ -0,0 +1,4 @@
+User-agent: *
+Allow: /
+
+Sitemap: https://sling.apache.org/sitemap.xml
\ No newline at end of file
diff --git a/src/main/jbake/content/sitemap.md b/src/main/jbake/content/sitemap.md
index d94f2ff..b2ae4a2 100644
--- a/src/main/jbake/content/sitemap.md
+++ b/src/main/jbake/content/sitemap.md
@@ -1,4 +1,4 @@
title=Sitemap
-type=sitemap
+type=htmlsitemap
status=published
~~~~~~
diff --git a/src/main/jbake/jbake.properties b/src/main/jbake/jbake.properties
index 986b17f..92d0888 100644
--- a/src/main/jbake/jbake.properties
+++ b/src/main/jbake/jbake.properties
@@ -4,22 +4,26 @@ site.contextPath=/
foundation.version=5.5.1
blog.title=Apache Sling
blog.subtitle=framework for RESTful web-applications based on an extensible content tree
-render.tags=true
-render.sitemap=true
template.masterindex.file=index.tpl
template.archive.file=archive.tpl
template.tag.file=tags.tpl
template.sitemap.file=sitemap.tpl
+template.htmlsitemap.file=htmlsitemap.tpl
template.page.file=page.tpl
template.feed.file=feed.tpl
template.project.file=project.tpl
template.repolist.file=repolist.tpl
+template.downloads.file=downloads.tpl
render.index=false
render.feed=false
+render.tags=true
+# render sitemap.xml file?
+render.sitemap=true
+# filename to use for sitemap file
+sitemap.file=sitemap.xml
index.paginate=false
img.path.update=false
markdown.extensions=WIKILINKS,TABLES,ANCHORLINKS
-template.downloads.file=downloads.tpl
sling.lastCommitBaseUrl=https://github.com/apache/sling-site/commit/
# character encoding MIME name used in templates.
# use one of http://www.iana.org/assignments/character-sets/character-sets.xhtml
diff --git a/src/main/jbake/templates/htmlsitemap.tpl b/src/main/jbake/templates/htmlsitemap.tpl
new file mode 100644
index 0000000..70d3836
--- /dev/null
+++ b/src/main/jbake/templates/htmlsitemap.tpl
@@ -0,0 +1,35 @@
+def printSection(def linkPrefix, def sectionFolderUri, def sectionChildren) {
+ if (!sectionChildren) {
+ return
+ }
+ // comment "found ${sectionChildren.size()} children below '${sectionFolderUri}'"
+ ul {
+ // iterate over all direct children of rootUri
+ sectionChildren.findAll( { page -> !page.uri.substring(sectionFolderUri.length()).contains('/') } ).sort( { page -> page.title } ).each { page ->
+ li {
+ a (href:"${linkPrefix}${page.uri}") {
+ yield page.title
+ }
+ newLine()
+ String subsectionFolderUri = page.uri.substring(0, page.uri.length() - '.html'.length()) + '/'
+ // comment "subsectionFolderUri: '${subsectionFolderUri}'"
+ printSection(linkPrefix, subsectionFolderUri, sectionChildren.findAll( child -> child.uri.startsWith(subsectionFolderUri) ))
+ }
+ newLine()
+ }
+ }
+}
+
+layout 'layout/main.tpl', true,
+ projects: projects,
+ bodyContents: contents {
+
+ div(class:"sitemap"){
+ section(class:"wrap"){
+ ul {
+ // 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(config.site_contextPath, '', published_content)
+ }
+ }
+ }
+ }
diff --git a/src/main/jbake/templates/includes/Git.groovy b/src/main/jbake/templates/includes/Git.groovy
index 3916331..17f8fc6 100644
--- a/src/main/jbake/templates/includes/Git.groovy
+++ b/src/main/jbake/templates/includes/Git.groovy
@@ -5,7 +5,10 @@ class Git {
/** Get Git revision info for the specified file */
def static getRevisionInfo(filename) {
- def gitCmd = 'git log -1 --format=%h####%ad####%an####%s ' + filename
+ // the date is used for both the XML sitemap and at the bottom of website pages
+ // YYYY-MM-DD format looks good enough for that, if we need a different format
+ // we probably need to parse that and reformat.
+ def gitCmd = 'git log -1 --date=short --format=%h####%ad####%an####%s ' + filename
def defaultText = "0####0000####<MISSING>####<MISSING>"
def gitInfo = includes.OS.exec(gitCmd, defaultText).split("####")
// For untracked files the command does not return anything
diff --git a/src/main/jbake/templates/sitemap.tpl b/src/main/jbake/templates/sitemap.tpl
index fe217c0..4f718cc 100644
--- a/src/main/jbake/templates/sitemap.tpl
+++ b/src/main/jbake/templates/sitemap.tpl
@@ -1,19 +1,10 @@
-layout 'layout/main.tpl', true,
- projects: projects,
- bodyContents: contents {
-
- 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()
- }
- }
- }
- }
+xmlDeclaration()
+urlset( xmlns:'http://www.sitemaps.org/schemas/sitemap/0.9', 'xmlns:xsi':'http://www.w3.org/2001/XMLSchema-instance', 'xsi:schemaLocation':'http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd'){
+ published_content.each {content ->
+ def info = includes.Git.getRevisionInfo(content.file);
+ url {
+ loc("${config.site_host}${config.site_contextPath}${content.uri}")
+ lastmod("${info.date}")
}
+ }
+}
\ No newline at end of file