Skip to content
This repository was archived by the owner on Apr 22, 2020. It is now read-only.

Commit 3613ce1

Browse files
Maria Scharinmneedham
authored andcommitted
Add sitemap generation (#810)
1 parent eb10516 commit 3613ce1

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

doc/build.gradle

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ buildscript {
2020
classpath 'net.sf.docbook:docbook-xsl:1.79.1:ns-resources@zip'
2121
classpath fileTree(dir: "${rootProject.projectDir}/lib", include: '*.jar')
2222
classpath files(catalogDir)
23+
classpath "org.dom4j:dom4j:2.1.1"
24+
classpath "jaxen:jaxen:1.1.6"
2325
}
2426
}
2527

@@ -158,6 +160,32 @@ task makeToc(type: XsltTask, dependsOn: docbook) {
158160
])
159161
}
160162

163+
task sitemap() {
164+
ext.contentMapXml = file("${projectDir}/docbook/content-map.xml")
165+
def siteMapDir = "$buildDir/sitemap/$versions.graphAlgoDocs"
166+
outputs.dir siteMapDir
167+
168+
doLast {
169+
def siteMap = org.dom4j.DocumentHelper.createDocument()
170+
def urlset = siteMap.addElement("urlset", "http://www.sitemaps.org/schemas/sitemap/0.9")
171+
def contentMap = new org.dom4j.io.SAXReader().read(contentMapXml)
172+
contentMap.selectNodes('//processing-instruction("dbhtml")')
173+
.collect { pi ->
174+
pi.getText() // filename="installation/index.html"
175+
.replaceAll("filename=|\"", "") // installation/index.html
176+
}.each { filename ->
177+
def url = "${docsBaseUri}/graph-algorithms/current" + "/" + filename
178+
urlset.addElement("url").addElement("loc").addText(url)
179+
}
180+
mkdir(siteMapDir)
181+
new org.dom4j.io.XMLWriter(
182+
new FileOutputStream(file("$siteMapDir/sitemap.xml")),
183+
org.dom4j.io.OutputFormat.createPrettyPrint()
184+
).write(siteMap)
185+
}
186+
}
187+
188+
161189
html {
162190
dependsOn docbook
163191
ext.sourceDir = docbook.outputDir
@@ -262,13 +290,14 @@ task asciidoctorHtml {
262290
}
263291
}
264292

265-
task packageHtml(type: Tar, dependsOn: html) {
266-
description 'Package HTML for distribution.'
293+
task packageHtml(type: Tar, dependsOn: [html, sitemap]) {
294+
description 'Package HTML for distribution, including sitemap.'
267295
baseName 'graph-algorithms'
268296
extension 'tar.gz'
269297
version versions.graphAlgoDocs
270298
compression = Compression.GZIP
271299
from { html }
300+
from { sitemap }
272301
into "$baseName/$version"
273302
destinationDir file(distDir)
274303
}

0 commit comments

Comments
 (0)