]> git.draconx.ca Git - homepage.git/blob - layouts/default.xsl
Add copyright license information.
[homepage.git] / layouts / default.xsl
1 <?xml version='1.0' encoding='UTF-8' ?>
2 <!--
3   Nick's web site: Final XHTML output stage
4
5   Copyright © 2018 Nick Bowler
6
7   This program is free software: you can redistribute it and/or modify
8   it under the terms of the GNU General Public License as published by
9   the Free Software Foundation, either version 3 of the License, or
10   (at your option) any later version.
11
12   This program is distributed in the hope that it will be useful,
13   but WITHOUT ANY WARRANTY; without even the implied warranty of
14   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   GNU General Public License for more details.
16
17   You should have received a copy of the GNU General Public License
18   along with this program.  If not, see <https://www.gnu.org/licenses/>
19 -->
20 <xsl:stylesheet version='1.0'
21   xmlns='http://www.w3.org/1999/xhtml'
22   xmlns:xhtml='http://www.w3.org/1999/xhtml'
23   xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
24   xmlns:func='http://exslt.org/functions'
25   xmlns:f='http://draconx.ca/my-functions'
26   extension-element-prefixes='func f'
27   exclude-result-prefixes='xhtml'>
28
29 <xsl:output method='xml' encoding='UTF-8' indent='yes'
30   doctype-public='-//W3C//DTD XHTML 1.1//EN'
31   doctype-system='http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd' />
32 <xsl:strip-space elements='*' />
33 <xsl:preserve-space elements='xhtml:p' />
34
35 <xsl:param name='source-uri'
36   select='"//git.draconx.ca/gitweb/homepage.git/blob/"' />
37 <xsl:param name='site-title' select='"The Citrine Citadel"' />
38
39 <func:function name='f:ends-with'>
40   <xsl:param name='a' />
41   <xsl:param name='b' />
42   <func:result
43     select='substring($a, string-length($a)-string-length($b)+1)=$b' />
44 </func:function>
45
46 <xsl:template match='node()|@*'>
47   <xsl:copy><xsl:apply-templates select='node()|@*' /></xsl:copy>
48 </xsl:template>
49
50 <!-- Add rel attributes to external links -->
51 <xsl:template match='xhtml:a[starts-with(@href,"http://")
52                           or starts-with(@href,"https://")
53                           or starts-with(@href,"//")]'>
54   <xsl:variable name='domain'
55     select='substring-before(
56               concat(translate(substring-after(@href, "//"), ":", "/"), "/"),
57               "/")' />
58
59   <xsl:copy>
60     <xsl:apply-templates select='@*' />
61     <xsl:if test='not($domain="draconx.ca"
62                       or f:ends-with($domain, ".draconx.ca"))'>
63       <xsl:attribute name='rel'>
64         <xsl:if test='@rel'>
65           <xsl:value-of select='@rel' />
66           <xsl:text> </xsl:text>
67         </xsl:if>
68         <xsl:text>external noopener noreferrer</xsl:text>
69       </xsl:attribute>
70     </xsl:if>
71     <xsl:apply-templates select='node()' />
72   </xsl:copy>
73 </xsl:template>
74
75 <xsl:template match='xhtml:h2[@id]'>
76   <xsl:variable name='fragment' select='concat("#", @id)' />
77   <xsl:copy>
78     <xsl:apply-templates select='node()|@*' />
79     <xsl:text> </xsl:text>
80     <small class='permalink'>
81       (<a href='{$fragment}'><xsl:value-of select='$fragment' /></a>)
82     </small>
83   </xsl:copy>
84 </xsl:template>
85
86 <xsl:template match='copyright'>
87   <p>
88     <xsl:text>Copyright © </xsl:text>
89     <xsl:value-of select='text()' />
90     <xsl:text>.</xsl:text>
91   </p>
92 </xsl:template>
93
94 <xsl:template match='license'>
95   <p>
96     <xsl:text>Copying and distribution of this material</xsl:text>
97     <xsl:if test='normalize-space(modification-allowed)="yes"'>
98       <xsl:text>, with or without modification,</xsl:text>
99     </xsl:if>
100     <xsl:text> is permitted under the terms of the </xsl:text>
101     <a rel='license'>
102       <xsl:attribute name='href'>
103         <xsl:value-of select='normalize-space(uri)' />
104       </xsl:attribute>
105       <xsl:value-of select='name' />
106     </a>
107     <xsl:text>.</xsl:text>
108   </p>
109 </xsl:template>
110
111 <xsl:template match='source'>
112   <p>
113     <xsl:text>This document was compiled from </xsl:text>
114     <a href='{concat($source-uri, revision, ":", file)}'>
115       <xsl:value-of select='file' />
116     </a>
117     <xsl:text> on </xsl:text>
118     <xsl:value-of select='compiletime' />
119     <xsl:text>.</xsl:text>
120   </p>
121 </xsl:template>
122
123 <xsl:template match='/'>
124   <html>
125     <head>
126       <meta name='viewport' content='width=device-width, initial-scale=1' />
127       <link rel='stylesheet' type='text/css' href='/style.css' />
128       <title>
129         <xsl:variable name='page-title' select='string(/document/title)' />
130         <xsl:if test='$page-title and $site-title != $page-title'>
131           <xsl:value-of select='concat($page-title, " – ")' />
132         </xsl:if>
133         <xsl:value-of select='$site-title' />
134       </title>
135     </head>
136     <body>
137       <xsl:apply-templates select='/document/xhtml:html/@*' />
138       <xsl:apply-templates select='/document/xhtml:html/node()' />
139
140       <hr />
141       <div id='footer'>
142         <xsl:apply-templates select='/document/copyright' />
143         <xsl:apply-templates select='/document/license' />
144         <xsl:apply-templates select='/document/source' />
145       </div>
146     </body>
147   </html>
148 </xsl:template>
149
150 </xsl:stylesheet>