comments.xslt 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3. xmin-mro Hugo theme
  4. Copyright (C) 2019-2019 Marcus Rohrmoser, http://code.mro.name/mro/xmin-mro
  5. This program is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. https://www.w3.org/TR/xslt-10/
  16. -->
  17. <xsl:stylesheet
  18. xmlns="http://www.w3.org/1999/xhtml"
  19. xmlns:a="http://www.w3.org/2005/Atom"
  20. xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/"
  21. xmlns:media="http://search.yahoo.com/mrss/"
  22. xmlns:georss="http://www.georss.org/georss"
  23. xmlns:sg="http://purl.mro.name/ShaarliGo/"
  24. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  25. exclude-result-prefixes="a opensearch media georss sg"
  26. xmlns:math="http://exslt.org/math"
  27. extension-element-prefixes="math"
  28. version="1.0">
  29. <!-- replace linefeeds with <br> tags -->
  30. <xsl:template name="linefeed2br">
  31. <xsl:param name="string" select="''"/>
  32. <xsl:param name="pattern" select="'&#10;'"/>
  33. <xsl:choose>
  34. <xsl:when test="contains($string, $pattern)">
  35. <xsl:value-of select="substring-before($string, $pattern)"/><br class="br"/><xsl:comment> Why do we see 2 br on Safari and output/@method=html here? http://purl.mro.name/safari-xslt-br-bug </xsl:comment>
  36. <xsl:call-template name="linefeed2br">
  37. <xsl:with-param name="string" select="substring-after($string, $pattern)"/>
  38. <xsl:with-param name="pattern" select="$pattern"/>
  39. </xsl:call-template>
  40. </xsl:when>
  41. <xsl:otherwise>
  42. <xsl:value-of select="$string"/>
  43. </xsl:otherwise>
  44. </xsl:choose>
  45. </xsl:template>
  46. <xsl:template name="calculate-day-of-the-week">
  47. <!-- https://www.oreilly.com/library/view/xslt-cookbook/0596003722/ch03s02.html -->
  48. <xsl:param name="date-time"/>
  49. <xsl:param name="date" select="substring-before($date-time,'T')"/>
  50. <xsl:param name="year" select="substring-before($date,'-')"/>
  51. <xsl:param name="month" select="substring-before(substring-after($date,'-'),'-')"/>
  52. <xsl:param name="day" select="substring-after(substring-after($date,'-'),'-')"/>
  53. <xsl:variable name="a" select="floor((14 - $month) div 12)"/>
  54. <xsl:variable name="y" select="$year - $a"/>
  55. <xsl:variable name="m" select="$month + 12 * $a - 2"/>
  56. <xsl:value-of select="($day + $y + floor($y div 4) - floor($y div 100) + floor($y div 400) + floor((31 * $m) div 12)) mod 7"/>
  57. </xsl:template>
  58. <xsl:template name="human_time">
  59. <xsl:param name="time">-</xsl:param>
  60. <xsl:variable name="wday">
  61. <xsl:call-template name="calculate-day-of-the-week">
  62. <xsl:with-param name="date-time" select="$time"/>
  63. </xsl:call-template>
  64. </xsl:variable>
  65. <xsl:choose>
  66. <xsl:when test="0 = $wday">So</xsl:when>
  67. <xsl:when test="1 = $wday">Mo</xsl:when>
  68. <xsl:when test="2 = $wday">Di</xsl:when>
  69. <xsl:when test="3 = $wday">Mi</xsl:when>
  70. <xsl:when test="4 = $wday">Do</xsl:when>
  71. <xsl:when test="5 = $wday">Fr</xsl:when>
  72. <xsl:when test="6 = $wday">Sa</xsl:when>
  73. <xsl:otherwise>?</xsl:otherwise>
  74. </xsl:choose>
  75. <xsl:text>, </xsl:text>
  76. <xsl:value-of select="substring($time, 9, 2)"/><xsl:text>. </xsl:text>
  77. <xsl:variable name="month" select="substring($time, 6, 2)"/>
  78. <xsl:choose>
  79. <xsl:when test="'01' = $month">Jan</xsl:when>
  80. <xsl:when test="'02' = $month">Feb</xsl:when>
  81. <xsl:when test="'03' = $month">Mär</xsl:when>
  82. <xsl:when test="'04' = $month">Apr</xsl:when>
  83. <xsl:when test="'05' = $month">Mai</xsl:when>
  84. <xsl:when test="'06' = $month">Jun</xsl:when>
  85. <xsl:when test="'07' = $month">Jul</xsl:when>
  86. <xsl:when test="'08' = $month">Aug</xsl:when>
  87. <xsl:when test="'09' = $month">Sep</xsl:when>
  88. <xsl:when test="'10' = $month">Okt</xsl:when>
  89. <xsl:when test="'11' = $month">Nov</xsl:when>
  90. <xsl:when test="'12' = $month">Dez</xsl:when>
  91. <xsl:otherwise>?</xsl:otherwise>
  92. </xsl:choose><xsl:text> </xsl:text>
  93. <xsl:value-of select="substring($time, 1, 4)"/><xsl:text> </xsl:text>
  94. <xsl:value-of select="substring($time, 12, 5)"/><!-- xsl:text> Uhr</xsl:text -->
  95. </xsl:template>
  96. <xsl:template name="degrees">
  97. <xsl:param name="num" select="0"/>
  98. <xsl:choose>
  99. <xsl:when test="$num &lt; 0">-<xsl:call-template name="degrees"><xsl:with-param name="num" select="-$num"/></xsl:call-template></xsl:when>
  100. <xsl:when test="$num &gt;= 0">
  101. <xsl:variable name="deg" select="floor($num)"/>
  102. <xsl:variable name="min" select="floor(($num * 60) mod 60)"/>
  103. <xsl:variable name="sec" select="format-number((($num * 36000) mod 600) div 10, '0.0')"/>
  104. <xsl:value-of select="$deg"/>° <!--
  105. --><xsl:value-of select="$min"/>' <!--
  106. --><xsl:value-of select="$sec"/>"
  107. </xsl:when>
  108. <xsl:otherwise>?</xsl:otherwise>
  109. </xsl:choose>
  110. </xsl:template>
  111. <xsl:output
  112. method="html"
  113. doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
  114. doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"/>
  115. <xsl:variable name="base_url">../../../../</xsl:variable>
  116. <xsl:template match="/">
  117. <xsl:apply-templates select="a:feed"/>
  118. </xsl:template>
  119. <xsl:template match="a:feed">
  120. <html xmlns="http://www.w3.org/1999/xhtml">
  121. <head>
  122. <meta content="text/html; charset=utf-8" http-equiv="content-type"/>
  123. <meta name="viewport" content="width=device-width,initial-scale=1.0"/>
  124. <link rel="stylesheet" href="{$base_url}assets/style.css"/>
  125. <style type="text/css">
  126. </style>
  127. <title><xsl:value-of select="a:title"/></title>
  128. </head>
  129. <body>
  130. <p style="text-align:center">* * *</p>
  131. <h2>Comments <a href="index.xml" target="_top"><img src="{$base_url}assets/feed-icon.svg#height24" alt="Feed Icon" title="Comment Feed"/></a></h2>
  132. <ol id="entries" start="0">
  133. <li><a href="mailto:Thua4aehah4ae2tiem@mro.name?subject=Comment {a:id}..&amp;body={a:title}%0a[x] please publish this comment under the original post including my email sender name but not my email address.%0a%0a…">Comment via Email 📧</a></li>
  134. <xsl:apply-templates select="a:entry">
  135. <xsl:sort select="a:published" data-type="text" order="ascending"/>
  136. </xsl:apply-templates>
  137. </ol>
  138. <script type="text/javascript">
  139. //<![CDATA[
  140. // console.log('make http and geo URIs (RFC 5870) clickable + microformat');
  141. const elmsRendered = document.getElementById('entries').getElementsByClassName('rendered');
  142. requestAnimationFrame(function() {
  143. for (var i = 0; i < elmsRendered.length; i++) {
  144. const elm = elmsRendered[i];
  145. elm.innerHTML = elm.innerHTML.replace(/(https?:\/\/([^ \t\r\n"'<]+[^ \t\r\n"'.,;()<]))/gi, '<a rel="noreferrer" target="_parent" class="http" href="$1">$2</a>');
  146. // https://alanstorm.com/url_regex_explained/ \b(([\w-]+://?|www[.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/)))
  147. // elm.innerHTML = elm.innerHTML.replace(/\b(([\w-]+:\/\/?|www[.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|\/)))/gi, '<a rel="noreferrer" class="http" href="$1">$1</a>');
  148. elm.innerHTML = elm.innerHTML.replace(/geo:(-?\d+.\d+),(-?\d+.\d+)(\?z=(\d+))?/gi, '<a rel="noreferrer" target="_parent" class="geo" href="https://opentopomap.org/#marker=12/$1/$2" title="zoom=$4">geo:<span class="latitude">$1</span>,<span class="longitude">$2</span>$3</a>');
  149. }
  150. });
  151. //]]>
  152. </script>
  153. </body>
  154. </html>
  155. </xsl:template>
  156. <xsl:template match="a:entry">
  157. <xsl:variable name="redirector"></xsl:variable>
  158. <xsl:variable name="link" select="a:link[not(@rel)]/@href"/>
  159. <xsl:variable name="self" select="a:link[@rel='self']/@href"/>
  160. <xsl:variable name="id_slash" select="substring-after($self, '/p/')"/>
  161. <xsl:variable name="id" select="substring-before($id_slash, '/')"/>
  162. <li id="{$id}">
  163. <p>
  164. <xsl:variable name="entry_published" select="a:published"/>
  165. <xsl:variable name="entry_published_human"><xsl:call-template name="human_time"><xsl:with-param name="time" select="$entry_published"/></xsl:call-template></xsl:variable>
  166. <a href="{a:id}"><xsl:value-of select="$entry_published_human"/></a>,
  167. <a target="_parent">
  168. <xsl:variable name="author_uri" select="a:author/a:uri"/>
  169. <xsl:if test="$author_uri">
  170. <xsl:attribute name="href">
  171. <xsl:value-of select="$author_uri"/>
  172. </xsl:attribute>
  173. </xsl:if>
  174. <xsl:value-of select="a:author/a:name"/>
  175. </a>:
  176. </p>
  177. <p class="rendered type-text">
  178. <xsl:call-template name="linefeed2br">
  179. <xsl:with-param name="string" select="a:content"/>
  180. </xsl:call-template>
  181. </p>
  182. </li>
  183. </xsl:template>
  184. </xsl:stylesheet>