diff options
Replaced function-like data resolution with template applications
* e.g. article and tag support data is now fetched through direct _XPath_ template applications
** this required the introduction of a special `resolve` mode to prevent interaction between support and main content resolution
** in most cases arguments had to be wrapped inside helper constants to enable selection of e.g. article support data via the `@handle` attribute using the current elements `@handle` attribute
* analogously to the recent changes in _StaticXSLT_ this commit aims to improve the XSLT code style used in generating this static website
-rw-r--r-- | source/01_data/articles.xsl | 20 | ||||
-rw-r--r-- | source/02_meta/articles.xsl | 34 | ||||
-rw-r--r-- | source/02_meta/categories.xsl | 20 | ||||
-rw-r--r-- | source/02_meta/tags.xsl | 28 | ||||
-rw-r--r-- | source/99_result/archive.xsl | 2 | ||||
-rw-r--r-- | source/99_result/article/article.xsl | 2 | ||||
-rw-r--r-- | source/99_result/atom.xsl | 2 | ||||
-rw-r--r-- | source/99_result/stream.xsl | 28 | ||||
-rw-r--r-- | utility/master.xsl | 18 |
9 files changed, 67 insertions, 87 deletions
diff --git a/source/01_data/articles.xsl b/source/01_data/articles.xsl index e207117..c25fe2a 100644 --- a/source/01_data/articles.xsl +++ b/source/01_data/articles.xsl @@ -12,17 +12,13 @@ <xsl:variable name="meta"> <datasource type="main" mode="xpath" source="$source_tree/directory[@name = '00_content']/directory" target="files"/> - <target mode="plain" value="articles.xml"/> + <target mode="plain" value="articles.xml"/> </xsl:variable> -<xsl:template name="list_tags"> - <xsl:param name="path"/> - - <xsl:for-each select="$root/files/directory[@name = 'tags']/*[./file/full = $path]"> - <tag> - <xsl:value-of select="@name"/> - </tag> - </xsl:for-each> +<xsl:template match="files/directory[@name = 'tags']/*" mode="resolve"> + <tag> + <xsl:value-of select="@name"/> + </tag> </xsl:template> <xsl:template match="files/directory[@name = 'articles']"> @@ -51,9 +47,9 @@ </year> </date> <tags> - <xsl:call-template name="list_tags"> - <xsl:with-param name="path" select="./full"/> - </xsl:call-template> + <xsl:variable name="self" select="."/> + + <xsl:apply-templates select="$root/files/directory[@name = 'tags']/*[./file/full = $self/full]" mode="resolve"/> </tags> <content> <xsl:copy-of select="xalan:nodeset($content)/*[name() != 'h1']"/> diff --git a/source/02_meta/articles.xsl b/source/02_meta/articles.xsl index 1a8b8fa..f91ff1e 100644 --- a/source/02_meta/articles.xsl +++ b/source/02_meta/articles.xsl @@ -11,31 +11,27 @@ <target mode="plain" value="articles.xml"/> </xsl:variable> -<xsl:key name="years" match="datasource/articles/entry/date/year/text()" use="." /> +<xsl:key name="years" match="datasource/articles/entry/date/year/text()" use="."/> + +<xsl:template match="articles/entry" mode="resolve"> + <article handle="{@handle}"> + <title> + <xsl:value-of select="title"/> + </title> + <date> + <xsl:value-of select="date/full"/> + </date> + </article> +</xsl:template> <xsl:template match="articles"> <xsl:for-each select="entry/date/year/text()[generate-id() = generate-id(key('years',.)[1])]"> + <xsl:variable name="year" select="."/> + <entry handle="{.}"> - <xsl:call-template name="get_articles"> - <xsl:with-param name="year" select="."/> - </xsl:call-template> + <xsl:apply-templates select="$root/articles/entry[./date/year = $year]" mode="resolve"/> </entry> </xsl:for-each> </xsl:template> -<xsl:template name="get_articles"> - <xsl:param name="year"/> - - <xsl:for-each select="/datasource/articles/entry[date/year = $year]"> - <article handle="{@handle}"> - <title> - <xsl:value-of select="title"/> - </title> - <date> - <xsl:value-of select="date/full"/> - </date> - </article> - </xsl:for-each> -</xsl:template> - </xsl:stylesheet> diff --git a/source/02_meta/categories.xsl b/source/02_meta/categories.xsl index 1a06aa1..ea8593b 100644 --- a/source/02_meta/categories.xsl +++ b/source/02_meta/categories.xsl @@ -15,17 +15,13 @@ <target mode="plain" value="categories.xml"/> </xsl:variable> -<xsl:template name="get_page_data"> - <xsl:param name="handle"/> - - <xsl:variable name="page" select="$root/pages/entry[@handle = $handle]"/> - - <page handle="{$handle}"> +<xsl:template match="pages/entry" mode="resolve"> + <page handle="{@handle}"> <title> - <xsl:value-of select="$page/title"/> + <xsl:value-of select="title"/> </title> - <digest size="{string-length($page/content/p[1])}"> - <xsl:copy-of select="$page/content/p[1]/node()"/> + <digest size="{string-length(content/p[1])}"> + <xsl:copy-of select="content/p[1]/node()"/> </digest> </page> </xsl:template> @@ -37,9 +33,9 @@ </xsl:template> <xsl:template match="files/directory[@name = 'pages']/*/file[@extension = '.md']"> - <xsl:call-template name="get_page_data"> - <xsl:with-param name="handle" select="@name"/> - </xsl:call-template> + <xsl:variable name="handle" select="@name"/> + + <xsl:apply-templates select="$root/pages/entry[@handle = $handle]" mode="resolve"/> </xsl:template> </xsl:stylesheet> diff --git a/source/02_meta/tags.xsl b/source/02_meta/tags.xsl index 20b1f10..3c95932 100644 --- a/source/02_meta/tags.xsl +++ b/source/02_meta/tags.xsl @@ -12,17 +12,15 @@ <target mode="plain" value="tags.xml"/> </xsl:variable> -<xsl:template name="get_article_data"> - <xsl:param name="handle"/> - - <xsl:variable name="article" select="$root/articles/entry[@handle = $handle]/*[self::title | self::date]"/> - - <title> - <xsl:value-of select="$article/self::title"/> - </title> - <date> - <xsl:value-of select="$article/self::date/full"/> - </date> +<xsl:template match="articles/entry" mode="resolve"> + <article handle="{@handle}"> + <title> + <xsl:value-of select="title"/> + </title> + <date> + <xsl:value-of select="date/full"/> + </date> + </article> </xsl:template> <xsl:template match="tags/entry"> @@ -32,11 +30,9 @@ </xsl:template> <xsl:template match="tags/*/article"> - <article handle="{@handle}"> - <xsl:call-template name="get_article_data"> - <xsl:with-param name="handle" select="@handle"/> - </xsl:call-template> - </article> + <xsl:variable name="handle" select="@handle"/> + + <xsl:apply-templates select="$root/articles/entry[@handle = $handle]" mode="resolve"/> </xsl:template> </xsl:stylesheet> diff --git a/source/99_result/archive.xsl b/source/99_result/archive.xsl index 31d8354..8ef7d9a 100644 --- a/source/99_result/archive.xsl +++ b/source/99_result/archive.xsl @@ -11,7 +11,7 @@ <datasource type="main" mode="full" source="02_meta/articles.xml" target="articles"/> <datasource type="support" mode="full" source="02_meta/meta.xml" target="meta"/> <datasource type="support" mode="full" source="00_content/microblog.xml" target="microblog"/> - <target mode="plain" value="archive/index.html"/> + <target mode="plain" value="archive/index.html"/> </xsl:variable> <xsl:template name="title-text">Archive</xsl:template> diff --git a/source/99_result/article/article.xsl b/source/99_result/article/article.xsl index 37e2fda..d34df77 100644 --- a/source/99_result/article/article.xsl +++ b/source/99_result/article/article.xsl @@ -31,7 +31,7 @@ <xsl:call-template name="format-date"> <xsl:with-param name="date" select="date/full"/> <xsl:with-param name="format" select="'M x, Y'"/> - </xsl:call-template> + </xsl:call-template> <xsl:text> | </xsl:text> <xsl:for-each select="tags/tag"> <a href="/tag/{.}"> diff --git a/source/99_result/atom.xsl b/source/99_result/atom.xsl index b5fffdd..4972bb8 100644 --- a/source/99_result/atom.xsl +++ b/source/99_result/atom.xsl @@ -17,7 +17,7 @@ <xsl:variable name="meta"> <datasource type="main" mode="full" source="01_data/articles.xml" target="articles"/> <datasource type="support" mode="full" source="02_meta/meta.xml" target="meta"/> - <target mode="plain" value="atom.xml"/> + <target mode="plain" value="atom.xml"/> </xsl:variable> <xsl:variable name="url" select="datasource/meta/url"/> diff --git a/source/99_result/stream.xsl b/source/99_result/stream.xsl index 5d2218c..d71b094 100644 --- a/source/99_result/stream.xsl +++ b/source/99_result/stream.xsl @@ -28,24 +28,20 @@ </xsl:choose> </xsl:template> -<xsl:template name="get_article"> - <xsl:param name="handle"/> - - <xsl:variable name="article" select="$root/articles/entry[@handle = $handle]"/> - +<xsl:template match="articles/entry" mode="resolve"> <h2> <xsl:text>ยป </xsl:text> - <a href="/article/{$handle}"> - <xsl:value-of select="$article/title"/> + <a href="/article/{@handle}"> + <xsl:value-of select="title"/> </a> </h2> <p class="info"> <xsl:call-template name="format-date"> - <xsl:with-param name="date" select="$article/date/full"/> + <xsl:with-param name="date" select="date/full"/> <xsl:with-param name="format" select="'M x, Y'"/> - </xsl:call-template> + </xsl:call-template> <xsl:text> | </xsl:text> - <xsl:for-each select="$article/tags/tag"> + <xsl:for-each select="tags/tag"> <a href="/tag/{.}"> <xsl:value-of select="."/> </a> @@ -55,7 +51,7 @@ <xsl:value-of select="$root/meta/author"/> </p> - <xsl:apply-templates select="$article/content/node()" mode="xhtml"/> + <xsl:apply-templates select="content/node()" mode="xhtml"/> </xsl:template> <xsl:template match="page/entry"> @@ -80,19 +76,17 @@ </xsl:template> <xsl:template match="page/entry/article"> + <xsl:variable name="handle" select="@handle"/> + <xsl:choose> <xsl:when test="position() = last()"> <div class="last article"> - <xsl:call-template name="get_article"> - <xsl:with-param name="handle" select="@handle"/> - </xsl:call-template> + <xsl:apply-templates select="$root/articles/entry[@handle = $handle]" mode="resolve"/> </div> </xsl:when> <xsl:otherwise> <div class="article"> - <xsl:call-template name="get_article"> - <xsl:with-param name="handle" select="@handle"/> - </xsl:call-template> + <xsl:apply-templates select="$root/articles/entry[@handle = $handle]" mode="resolve"/> </div> </xsl:otherwise> </xsl:choose> diff --git a/utility/master.xsl b/utility/master.xsl index 84ecfe7..cb9e025 100644 --- a/utility/master.xsl +++ b/utility/master.xsl @@ -16,6 +16,14 @@ <xsl:variable name="root" select="datasource"/> +<xsl:template match="meta/tags/entry" mode="master"> + <li> + <a href="/tag/{@handle}"> + <xsl:value-of select="@handle"/> + </a> + </li> +</xsl:template> + <xsl:template match="/"> <html> <head> @@ -26,7 +34,7 @@ <meta name="viewport" content="width=device-width,initial-scale=1.0"/> <link rel="stylesheet" type="text/css" href="/main.css" /> - <link rel="shortcut icon" type="image/x-icon" href="/media/favicon.ico" /> + <link rel="shortcut icon" type="image/x-icon" href="/media/favicon.ico" /> <title> <xsl:call-template name="title-text"/> @ <xsl:value-of select="$root/meta/title"/> @@ -65,13 +73,7 @@ <div id="tags"> <ul> - <xsl:for-each select="datasource/meta/tags/entry"> - <li> - <a href="/tag/{@handle}"> - <xsl:value-of select="@handle"/> - </a> - </li> - </xsl:for-each> + <xsl:apply-templates select="datasource/meta/tags/entry" mode="master"/> </ul> </div> |