Skip to content

Commit cb817ef

Browse files
authored
Merge pull request #45 from AtomGraph/develop
Add last-modified meta tag and sitemap.xml to docs HTML generation
2 parents 03f266d + 5226346 commit cb817ef

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

docs/ttl-to-html.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@ find . -name "*.ttl" -exec sh -c '
1313
riot --output=RDF/XML --base="$base" "$1" > "$out"
1414
' sh {} \;
1515

16+
# Generate timestamps.xml (doc path → source .ttl modification time)
17+
echo '<?xml version="1.0" encoding="UTF-8"?>' > timestamps.xml
18+
echo '<map xmlns="http://www.w3.org/2005/xpath-functions">' >> timestamps.xml
19+
find . -name "*.ttl" -exec sh -c '
20+
rel=$(echo "$1" | sed "s|^\./||")
21+
path="/${rel%.ttl}/"
22+
mtime=$(date -u -r "$1" +%Y-%m-%dT%H:%M:%SZ)
23+
echo " <string key=\"$path\">$mtime</string>"
24+
' sh {} \; >> timestamps.xml
25+
echo '</map>' >> timestamps.xml
26+
1627
# Clear output folder first, so files.xml does not pick up stale html/files/ contents
1728
rm -rf "$OUTPUT_FOLDER"
1829
mkdir -p "$OUTPUT_FOLDER"

docs/ttl-to-html.xsl

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<xsl:param name="docs-dir" as="xs:string" select="'/docs'"/>
1919
<xsl:param name="rdf-dir" as="xs:string" select="'/rdf'"/>
2020
<xsl:param name="output-folder" as="xs:string" select="'/output'"/>
21+
<xsl:param name="site-base-url" as="xs:string" select="'https://atomgraph.github.io/LinkedDataHub/linkeddatahub/docs/'"/>
2122

2223
<!-- all RDF/XML documents — sidecar for nav and child discovery only -->
2324
<xsl:variable name="all-docs" select="collection('file://' || $rdf-dir || '?select=*.rdf;recurse=yes;content-type=application/xml')"/>
@@ -29,6 +30,11 @@
2930
match="json:map/json:array[@key='files']/json:map"
3031
use="json:string[@key='sha1']"/>
3132

33+
<!-- doc path → source .ttl modification time -->
34+
<xsl:variable name="timestamps-xml" select="document('file://' || $docs-dir || '/timestamps.xml')"/>
35+
36+
<xsl:key name="timestamp-by-path" match="json:string" use="@key"/>
37+
3238
<!--
3339
Derive the logical resource URI from a node's document base URI.
3440
riot outputs the main resource as rdf:about="" (relative to base), so we cannot
@@ -84,6 +90,22 @@
8490
</body>
8591
</html>
8692
</xsl:result-document>
93+
94+
<!-- sitemap.xml -->
95+
<xsl:result-document href="{$output-folder}/sitemap.xml" method="xml" indent="yes">
96+
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
97+
<url>
98+
<loc><xsl:value-of select="$site-base-url"/></loc>
99+
</url>
100+
<xsl:for-each select="$timestamps-xml/json:map/json:string">
101+
<xsl:sort select="@key"/>
102+
<url>
103+
<loc><xsl:value-of select="$site-base-url || substring-after(@key, '/')"/></loc>
104+
<lastmod><xsl:value-of select="."/></lastmod>
105+
</url>
106+
</xsl:for-each>
107+
</urlset>
108+
</xsl:result-document>
87109
</xsl:template>
88110

89111
<!-- ==================== ONE PAGE PER RDF DOCUMENT ==================== -->
@@ -98,6 +120,7 @@
98120
<xsl:call-template name="html-head">
99121
<xsl:with-param name="title" select="$resource/dct:title"/>
100122
<xsl:with-param name="description" select="$resource/dct:description"/>
123+
<xsl:with-param name="doc-path" select="$base-path"/>
101124
</xsl:call-template>
102125
<body>
103126
<xsl:call-template name="navbar">
@@ -262,11 +285,16 @@
262285
<xsl:template name="html-head">
263286
<xsl:param name="title" as="xs:string"/>
264287
<xsl:param name="description" as="xs:string?"/>
288+
<xsl:param name="doc-path" as="xs:string?"/>
265289
<head>
266290
<title>LinkedDataHub v5 — <xsl:value-of select="$title"/></title>
267291
<xsl:if test="$description">
268292
<meta name="description" content="{$description}"/>
269293
</xsl:if>
294+
<xsl:variable name="modified" select="key('timestamp-by-path', $doc-path, $timestamps-xml)"/>
295+
<xsl:if test="$modified">
296+
<meta name="last-modified" content="{$modified}"/>
297+
</xsl:if>
270298
<link href="https://atomgraph.github.io/LinkedDataHub/linkeddatahub/docs/files/css/bootstrap.css" rel="stylesheet" type="text/css"/>
271299
<link href="https://atomgraph.github.io/LinkedDataHub/linkeddatahub/docs/files/css/bootstrap-responsive.css" rel="stylesheet" type="text/css"/>
272300
<link href="https://atomgraph.github.io/LinkedDataHub/linkeddatahub/docs/files/css/linkeddatahub-bootstrap.css" rel="stylesheet" type="text/css"/>

0 commit comments

Comments
 (0)