thr.xsl 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <xsl:stylesheet
  2. xmlns="http://www.w3.org/1999/xhtml"
  3. xmlns:a="http://www.w3.org/2005/Atom"
  4. xmlns:media="http://search.yahoo.com/mrss/"
  5. xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/"
  6. xmlns:thr="http://purl.org/syndication/thread/1.0"
  7. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  8. exclude-result-prefixes="a media opensearch thr"
  9. xmlns:math="http://exslt.org/math"
  10. extension-element-prefixes="math"
  11. version="1.0">
  12. <!-- xsl:variable name="redirector">https://anonym.to/?</xsl:variable --> <!-- mask the HTTP_REFERER -->
  13. <xsl:variable name="redirector"></xsl:variable>
  14. <xsl:variable name="archive">https://web.archive.org/web/</xsl:variable>
  15. <!-- replace linefeeds with <br> tags -->
  16. <xsl:template name="linefeed2br">
  17. <xsl:param name="string" select="''"/>
  18. <xsl:param name="pattern" select="'&#10;'"/>
  19. <xsl:choose>
  20. <xsl:when test="contains($string, $pattern)">
  21. <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>
  22. <xsl:call-template name="linefeed2br">
  23. <xsl:with-param name="string" select="substring-after($string, $pattern)"/>
  24. <xsl:with-param name="pattern" select="$pattern"/>
  25. </xsl:call-template>
  26. </xsl:when>
  27. <xsl:otherwise>
  28. <xsl:value-of select="$string"/>
  29. </xsl:otherwise>
  30. </xsl:choose>
  31. </xsl:template>
  32. <xsl:template name="calculate-day-of-the-week">
  33. <!-- https://www.oreilly.com/library/view/xslt-cookbook/0596003722/ch03s02.html -->
  34. <xsl:param name="date-time"/>
  35. <xsl:param name="date" select="substring-before($date-time,'T')"/>
  36. <xsl:param name="year" select="substring-before($date,'-')"/>
  37. <xsl:param name="month" select="substring-before(substring-after($date,'-'),'-')"/>
  38. <xsl:param name="day" select="substring-after(substring-after($date,'-'),'-')"/>
  39. <xsl:variable name="a" select="floor((14 - $month) div 12)"/>
  40. <xsl:variable name="y" select="$year - $a"/>
  41. <xsl:variable name="m" select="$month + 12 * $a - 2"/>
  42. <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"/>
  43. </xsl:template>
  44. <xsl:template name="human_time">
  45. <xsl:param name="time">-</xsl:param>
  46. <xsl:variable name="wday">
  47. <xsl:call-template name="calculate-day-of-the-week">
  48. <xsl:with-param name="date-time" select="$time"/>
  49. </xsl:call-template>
  50. </xsl:variable>
  51. <xsl:choose>
  52. <xsl:when test="0 = $wday">Sun</xsl:when>
  53. <xsl:when test="1 = $wday">Mon</xsl:when>
  54. <xsl:when test="2 = $wday">Tue</xsl:when>
  55. <xsl:when test="3 = $wday">Wed</xsl:when>
  56. <xsl:when test="4 = $wday">Thu</xsl:when>
  57. <xsl:when test="5 = $wday">Fri</xsl:when>
  58. <xsl:when test="6 = $wday">Sat</xsl:when>
  59. <xsl:otherwise>?</xsl:otherwise>
  60. </xsl:choose>
  61. <xsl:text>, </xsl:text>
  62. <xsl:value-of select="substring($time, 9, 2)"/><xsl:text>. </xsl:text>
  63. <xsl:variable name="month" select="substring($time, 6, 2)"/>
  64. <xsl:choose>
  65. <xsl:when test="'01' = $month">Jan</xsl:when>
  66. <xsl:when test="'02' = $month">Feb</xsl:when>
  67. <xsl:when test="'03' = $month">Mar</xsl:when>
  68. <xsl:when test="'04' = $month">Apr</xsl:when>
  69. <xsl:when test="'05' = $month">May</xsl:when>
  70. <xsl:when test="'06' = $month">Jun</xsl:when>
  71. <xsl:when test="'07' = $month">Jul</xsl:when>
  72. <xsl:when test="'08' = $month">Aug</xsl:when>
  73. <xsl:when test="'09' = $month">Sep</xsl:when>
  74. <xsl:when test="'10' = $month">Oct</xsl:when>
  75. <xsl:when test="'11' = $month">Nov</xsl:when>
  76. <xsl:when test="'12' = $month">Dec</xsl:when>
  77. <xsl:otherwise>?</xsl:otherwise>
  78. </xsl:choose><xsl:text> </xsl:text>
  79. <xsl:value-of select="substring($time, 1, 4)"/><xsl:text> </xsl:text>
  80. <xsl:value-of select="substring($time, 12, 5)"/><!-- xsl:text> Uhr</xsl:text -->
  81. </xsl:template>
  82. <xsl:template name="degrees">
  83. <xsl:param name="num" select="0"/>
  84. <xsl:choose>
  85. <xsl:when test="$num &lt; 0">-<xsl:call-template name="degrees"><xsl:with-param name="num" select="-$num"/></xsl:call-template></xsl:when>
  86. <xsl:when test="$num &gt;= 0">
  87. <xsl:variable name="deg" select="floor($num)"/>
  88. <xsl:variable name="min" select="floor(($num * 60) mod 60)"/>
  89. <xsl:variable name="sec" select="format-number((($num * 36000) mod 600) div 10, '0.0')"/>
  90. <xsl:value-of select="$deg"/>° <!--
  91. --><xsl:value-of select="$min"/>' <!--
  92. --><xsl:value-of select="$sec"/>"
  93. </xsl:when>
  94. <xsl:otherwise>?</xsl:otherwise>
  95. </xsl:choose>
  96. </xsl:template>
  97. <xsl:output
  98. method="html"
  99. doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
  100. doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"/>
  101. <!-- http://stackoverflow.com/a/16328207 -->
  102. <xsl:key name="CategorY" match="a:entry/a:category" use="@term" />
  103. <xsl:variable name="self" select="/*/a:link[@rel = 'self']/@href"/>
  104. <xsl:variable name="xml_base_absolute" select="/*/@xml:base"/>
  105. <!-- a bit hairy, but actually works -->
  106. <xsl:variable name="xml_base_relative">../../<xsl:choose>
  107. <xsl:when test="'shaarligo.cgi/search/?q=' = substring($self, 1, 24)"/>
  108. <xsl:when test="'//' = translate($self, 'abcdefghijklmnopqrstuvwxyz0123456789-', '')"/>
  109. <xsl:otherwise>../</xsl:otherwise>
  110. </xsl:choose>
  111. </xsl:variable>
  112. <xsl:variable name="xml_base" select="normalize-space($xml_base_relative)"/>
  113. <xsl:variable name="xml_base_pub" select="concat($xml_base,'o')"/>
  114. <xsl:variable name="skin_base" select="concat($xml_base,'themes/current')"/>
  115. <xsl:variable name="cgi_base" select="concat($xml_base,'shaarligo.cgi')"/>
  116. <xsl:template match="/">
  117. <html xmlns="http://www.w3.org/1999/xhtml" data-xml-base-pub="{$xml_base_pub}">
  118. <head>
  119. <link href="style.css" rel="stylesheet" type="text/css" />
  120. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  121. <meta name="generator" content="HTML Tidy for HTML5 for FreeBSD version 5.8.0" />
  122. <meta name="viewport" content="width=device-width,initial-scale=1.0" />
  123. <script src="../live.js"></script>
  124. <title>Threaded Atom Feeds RFC 4685</title>
  125. </head>
  126. <body>
  127. <xsl:apply-templates select="a:feed"/>
  128. </body>
  129. </html>
  130. </xsl:template>
  131. <xsl:template match="a:feed">
  132. <h1><xsl:value-of select="a:title"/></h1>
  133. <ol class="odd" data-level="1">
  134. <!-- level=0 is reserved for the primary source -->
  135. <xsl:apply-templates select="a:entry[not(thr:in-reply-to)]">
  136. <!-- entries pointing to undefined ids are lost -->
  137. <xsl:with-param name="level" select="1 + 1"/>
  138. </xsl:apply-templates>
  139. </ol>
  140. </xsl:template>
  141. <xsl:template match="a:entry">
  142. <xsl:param name="level" />
  143. <xsl:variable name="entry_published" select="a:published"/>
  144. <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>
  145. <li>
  146. <p>
  147. <img class="avatar" alt="Avatar" src= "{a:author/a:icon}" />
  148. <a href="{a:id}" data-rfc3339="{a:published}" title="{a:published}">
  149. <xsl:value-of select="$entry_published_human"/>
  150. </a>
  151. <span class="name"><xsl:value-of select="a:author/a:name"/></span>
  152. <a href="{a:author/a:uri}" data-rfc7033="{a:author/a:email}"><xsl:value-of select="a:author/a:email"/></a>
  153. </p>
  154. <p class="plaintext">
  155. <xsl:call-template name="linefeed2br">
  156. <xsl:with-param name="string" select="a:content"/>
  157. </xsl:call-template>
  158. </p>
  159. <xsl:variable name="me" select="a:id"/>
  160. <xsl:variable name="clz">
  161. <xsl:choose>
  162. <xsl:when test="$level mod 2 = 0">even</xsl:when>
  163. <xsl:otherwise>odd</xsl:otherwise>
  164. </xsl:choose>
  165. </xsl:variable>
  166. <xsl:variable name="more" select="following-sibling::a:entry[thr:in-reply-to/@ref = $me]"/>
  167. <xsl:if test="count($more) > 0">
  168. <ol class="{$clz}" data-level="{$level}">
  169. <xsl:apply-templates select="$more">
  170. <xsl:with-param name="level" select="$level + 1"/>
  171. </xsl:apply-templates>
  172. </ol>
  173. </xsl:if>
  174. </li>
  175. </xsl:template>
  176. </xsl:stylesheet>