posts.xslt 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3. ShaarliGo, microblogging detox
  4. Copyright (C) 2017-2021 Marcus Rohrmoser, http://purl.mro.name/ShaarliGo
  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. <!-- xsl:variable name="redirector">https://anonym.to/?</xsl:variable --> <!-- mask the HTTP_REFERER -->
  30. <xsl:variable name="redirector"></xsl:variable>
  31. <xsl:variable name="archive">https://web.archive.org/web/</xsl:variable>
  32. <!-- replace linefeeds with <br> tags -->
  33. <xsl:template name="linefeed2br">
  34. <xsl:param name="string" select="''"/>
  35. <xsl:param name="pattern" select="'&#10;'"/>
  36. <xsl:choose>
  37. <xsl:when test="contains($string, $pattern)">
  38. <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>
  39. <xsl:call-template name="linefeed2br">
  40. <xsl:with-param name="string" select="substring-after($string, $pattern)"/>
  41. <xsl:with-param name="pattern" select="$pattern"/>
  42. </xsl:call-template>
  43. </xsl:when>
  44. <xsl:otherwise>
  45. <xsl:value-of select="$string"/>
  46. </xsl:otherwise>
  47. </xsl:choose>
  48. </xsl:template>
  49. <xsl:template name="human_time">
  50. <xsl:param name="time">-</xsl:param>
  51. <xsl:value-of select="substring($time, 9, 2)"/><xsl:text>. </xsl:text>
  52. <xsl:variable name="month" select="substring($time, 6, 2)"/>
  53. <xsl:choose>
  54. <xsl:when test="'01' = $month">Jan</xsl:when>
  55. <xsl:when test="'02' = $month">Feb</xsl:when>
  56. <xsl:when test="'03' = $month">Mar</xsl:when>
  57. <xsl:when test="'04' = $month">Apr</xsl:when>
  58. <xsl:when test="'05' = $month">May</xsl:when>
  59. <xsl:when test="'06' = $month">Jun</xsl:when>
  60. <xsl:when test="'07' = $month">Jul</xsl:when>
  61. <xsl:when test="'08' = $month">Aug</xsl:when>
  62. <xsl:when test="'09' = $month">Sep</xsl:when>
  63. <xsl:when test="'10' = $month">Oct</xsl:when>
  64. <xsl:when test="'11' = $month">Nov</xsl:when>
  65. <xsl:when test="'12' = $month">Dec</xsl:when>
  66. <xsl:otherwise>?</xsl:otherwise>
  67. </xsl:choose><xsl:text> </xsl:text>
  68. <xsl:value-of select="substring($time, 1, 4)"/><xsl:text> </xsl:text>
  69. <xsl:value-of select="substring($time, 12, 5)"/><!-- xsl:text> Uhr</xsl:text -->
  70. </xsl:template>
  71. <xsl:template name="degrees">
  72. <xsl:param name="num" select="0"/>
  73. <xsl:choose>
  74. <xsl:when test="$num &lt; 0">-<xsl:call-template name="degrees"><xsl:with-param name="num" select="-$num"/></xsl:call-template></xsl:when>
  75. <xsl:when test="$num &gt;= 0">
  76. <xsl:variable name="deg" select="floor($num)"/>
  77. <xsl:variable name="min" select="floor(($num * 60) mod 60)"/>
  78. <xsl:variable name="sec" select="format-number((($num * 36000) mod 600) div 10, '0.0')"/>
  79. <xsl:value-of select="$deg"/>° <!--
  80. --><xsl:value-of select="$min"/>' <!--
  81. --><xsl:value-of select="$sec"/>"
  82. </xsl:when>
  83. <xsl:otherwise>?</xsl:otherwise>
  84. </xsl:choose>
  85. </xsl:template>
  86. <xsl:output
  87. method="html"
  88. doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
  89. doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"/>
  90. <!-- http://stackoverflow.com/a/16328207 -->
  91. <xsl:key name="CategorY" match="a:entry/a:category" use="@term" />
  92. <xsl:variable name="self" select="/*/a:link[@rel = 'self']/@href"/>
  93. <xsl:variable name="xml_base_absolute" select="/*/@xml:base"/>
  94. <!-- a bit hairy, but actually works -->
  95. <xsl:variable name="xml_base_relative">../../<xsl:choose>
  96. <xsl:when test="'shaarligo.cgi/search/?q=' = substring($self, 1, 24)"/>
  97. <xsl:when test="'//' = translate($self, 'abcdefghijklmnopqrstuvwxyz0123456789-', '')"/>
  98. <xsl:otherwise>../</xsl:otherwise>
  99. </xsl:choose>
  100. </xsl:variable>
  101. <xsl:variable name="xml_base" select="normalize-space($xml_base_relative)"/>
  102. <xsl:variable name="xml_base_pub" select="concat($xml_base,'o')"/>
  103. <xsl:variable name="skin_base" select="concat($xml_base,'themes/current')"/>
  104. <xsl:variable name="cgi_base" select="concat($xml_base,'shaarligo.cgi')"/>
  105. <xsl:template match="/">
  106. <!--
  107. Do not set a class="logged-out" initially, but do via early JavaScript.
  108. If JavaScript is off, we need mixture between logged-in and -out.
  109. -->
  110. <html xmlns="http://www.w3.org/1999/xhtml" data-xml-base-pub="{$xml_base_pub}">
  111. <xsl:if test="234 &lt; count(a:feed/a:category)">
  112. <xsl:attribute name="class">manytags</xsl:attribute>
  113. </xsl:if>
  114. <xsl:call-template name="head"/>
  115. <body>
  116. <xsl:apply-templates select="a:feed|a:entry" mode="root"/>
  117. </body>
  118. </html>
  119. </xsl:template>
  120. <xsl:template name="head">
  121. <head>
  122. <meta content="text/html; charset=utf-8" http-equiv="content-type"/>
  123. <!-- https://developer.apple.com/library/IOS/documentation/AppleApplications/Reference/SafariWebContent/UsingtheViewport/UsingtheViewport.html#//apple_ref/doc/uid/TP40006509-SW26 -->
  124. <!-- http://maddesigns.de/meta-viewport-1817.html -->
  125. <!-- meta name="viewport" content="width=device-width"/ -->
  126. <!-- http://www.quirksmode.org/blog/archives/2013/10/initialscale1_m.html -->
  127. <meta name="viewport" content="width=device-width,initial-scale=1.0"/>
  128. <!-- meta name="viewport" content="width=400"/ -->
  129. <link rel="icon" data-emoji="🌺" type="image/png"/>
  130. <link href="{$skin_base}/awesomplete.css" rel="stylesheet" type="text/css"/>
  131. <link href="{$skin_base}/style.css" rel="stylesheet" type="text/css"/>
  132. <script src="{$skin_base}/posts.js"><!-- async="true" fails --></script>
  133. <script src="{$skin_base}/awesomplete.js"><!-- async="true" fails --></script>
  134. <link href="." rel="alternate" type="application/atom+xml"/>
  135. <link href="." rel="self" type="application/xhtml+xml"/>
  136. <title><xsl:value-of select="a:*/a:title"/></title>
  137. </head>
  138. </xsl:template>
  139. <xsl:template match="a:feed" mode="root">
  140. <noscript><p>JavaScript deactivated, almost fully functional, but <em>nicer</em> if on.</p></noscript>
  141. <xsl:call-template name="links_commands"/>
  142. <xsl:call-template name="prev-next"/>
  143. <!-- h1><xsl:value-of select="a:title"/></h1 -->
  144. <xsl:if test="a:subtitle">
  145. <h2><xsl:value-of select="a:subtitle"/></h2>
  146. </xsl:if>
  147. <p id="tags" class="categories">
  148. <xsl:variable name="countMax">
  149. <!-- https://stackoverflow.com/a/17966412 -->
  150. <xsl:for-each select="a:category">
  151. <xsl:sort select="@label" data-type="number" order="descending"/>
  152. <xsl:if test="position() = 1"><xsl:value-of select="@label"/></xsl:if>
  153. </xsl:for-each>
  154. </xsl:variable>
  155. <xsl:variable name="labelsDesc">
  156. <xsl:for-each select="a:category">
  157. <xsl:sort select="@label" order="descending"/>
  158. <xsl:value-of select="@label"/>
  159. </xsl:for-each>
  160. </xsl:variable>
  161. <xsl:for-each select="a:category[@label >= 1]">
  162. <xsl:sort select="@term" order="ascending"/>
  163. <!-- not log, just linear, similar to https://github.com/sebsauvage/Shaarli/blob/master/index.php#L1254 -->
  164. <xsl:variable name="size" select="8 + 40 * @label div $countMax"/>
  165. <a style="font-size:{$size}pt" href="{$cgi_base}/search/?q=%23{@term}+" class="tag" data-count="{@label}"><span class="label"><xsl:value-of select="@term"/></span><span style="font-size:8pt">&#160;(<span class="count"><xsl:value-of select="@label"/></span>)</span></a><xsl:text> </xsl:text>
  166. </xsl:for-each>
  167. </p>
  168. <ol id="entries">
  169. <xsl:apply-templates select="a:entry"/>
  170. </ol>
  171. <xsl:call-template name="prev-next"/>
  172. <xsl:call-template name="footer"/>
  173. </xsl:template>
  174. <xsl:template name="links_commands">
  175. <table id="links_commands" aria-label="Befehle">
  176. <tbody>
  177. <tr>
  178. <td class="text-left">
  179. <a tabindex="10" href="{$xml_base_pub}/p/">
  180. <xsl:choose>
  181. <xsl:when test="a:link[@rel = 'up']/@title">
  182. <xsl:value-of select="a:link[@rel = 'up']/@title"/>
  183. </xsl:when>
  184. <xsl:otherwise>
  185. <xsl:value-of select="a:title"/>
  186. </xsl:otherwise>
  187. </xsl:choose>
  188. </a>
  189. </td>
  190. <td tabindex="20" class="text-right"><a href="{$xml_base_pub}/t/">⛅ <span class="hidden-xs"># Tags</span></a></td>
  191. <td tabindex="30" class="text-right"><a class="disabled" href="{$xml_base_pub}/d/" title="Not implemented yet.">📅 <span class="hidden-xs">Daily</span></a></td>
  192. <td tabindex="40" class="text-right"><a class="disabled" href="{$xml_base_pub}/i/" title="Not implemented yet.">🎨 <span class="hidden-xs">Images</span></a></td>
  193. <td class="text-right"><!-- I'd prefer a class="text-right hidden-logged-out" but just don't get it right -->
  194. <a class="hidden-logged-out" href="{$cgi_base}/tools/" rel="nofollow">🔨 <span class="hidden-xs">Tools</span></a>
  195. </td>
  196. <td class="text-right">
  197. <a tabindex="50" id="link_login" href="{$cgi_base}?do=login" class="visible-logged-out" rel="nofollow"><span class="hidden-xs">Login</span> 🌺 </a>
  198. <a tabindex="51" id="link_logout" href="{$cgi_base}?do=logout" class="hidden-logged-out" rel="nofollow"><span class="hidden-xs">Logout</span> 🐾 </a>
  199. </td>
  200. </tr>
  201. </tbody>
  202. </table>
  203. <xsl:comment> https://stackoverflow.com/a/18520870 http://jsfiddle.net/66Ynx/ </xsl:comment>
  204. <form id="form_search" name="form_search" action="{$cgi_base}/search/">
  205. <input tabindex="100" name="q" id="q" value="{@sg:searchTerms}" autofocus="autofocus" type="text" placeholder="🔍
  206. Search text or #tag..." class="awesomplete" data-multiple="true"/>
  207. </form>
  208. <form id="form_post" name="form_post" class="hidden-logged-out" action="{$cgi_base}">
  209. <input tabindex="300" name="post" type="text" placeholder="What to #post? (note or URL)"/>
  210. </form>
  211. </xsl:template>
  212. <xsl:template name="prev-next">
  213. <xsl:if test="a:link[@rel='first'] or a:link[@rel='last']">
  214. <table class="prev-next">
  215. <tbody>
  216. <tr>
  217. <td class="text-left">
  218. <xsl:variable name="disabled"><xsl:if test="a:link[@rel='first']/@href = a:link[@rel='self']/@href">disabled</xsl:if></xsl:variable>
  219. <a href="{$xml_base}{a:link[@rel='first']/@href}" class="{$disabled} btn"><xsl:value-of select="a:link[@rel='first']/@title"/></a>
  220. </td>
  221. <td class="text-center">
  222. <xsl:variable name="disabled"><xsl:if test="not(a:link[@rel='previous'])">disabled</xsl:if></xsl:variable>
  223. <a href="{$xml_base}{a:link[@rel='previous']/@href}" class="{$disabled} btn">&#160;&lt;&#160;</a>
  224. </td>
  225. <td class="text-center">
  226. <span class="hidden-xs"></span><xsl:value-of select="a:link[@rel='self']/@title"/>
  227. </td>
  228. <td class="text-center">
  229. <xsl:variable name="disabled"><xsl:if test="not(a:link[@rel='next'])">disabled</xsl:if></xsl:variable>
  230. <a href="{$xml_base}{a:link[@rel='next']/@href}" class="{$disabled} btn">&#160;&gt;&#160;</a>
  231. </td>
  232. <td class="text-right">
  233. <xsl:variable name="disabled"><xsl:if test="a:link[@rel='last']/@href = a:link[@rel='self']/@href">disabled</xsl:if></xsl:variable>
  234. <a href="{$xml_base}{a:link[@rel='last']/@href}" class="{$disabled} btn"><xsl:value-of select="a:link[@rel='last']/@title"/></a>
  235. </td>
  236. </tr>
  237. </tbody>
  238. </table>
  239. </xsl:if>
  240. </xsl:template>
  241. <xsl:template name="footer">
  242. <p id="footer">
  243. <a title="Syndicate" href="{$xml_base_absolute}{a:link[@rel='self']/@href}">
  244. <img alt="Feed" src="{$skin_base}/feed-icon.svg" style="border:0;width:27px;height:27px"/>
  245. </a>
  246. <xsl:text> </xsl:text>
  247. <a title="Validate (Atom 1.0)" href="https://validator.w3.org/feed/check.cgi?url={$xml_base_absolute}{a:link[@rel='self']/@href}">
  248. <img alt="Validity badge (Atom 1.0)" src="{$skin_base}/valid-atom.svg" style="border:0;width:77px;height:27px"/>
  249. </a>
  250. <!-- <xsl:text> </xsl:text>
  251. <a href="https://validator.w3.org/check?uri=referer">
  252. <img alt="Valid XHTML 1.0 Strict" src="{$skin_base}/valid-xhtml10-blue-v.svg" style="border:0;width:88px;height:31px"/>
  253. </a>
  254. <a href="https://jigsaw.w3.org/css-validator/check/referer?profile=css3&amp;usermedium=screen&amp;warning=2&amp;vextwarning=false&amp;lang=de">
  255. <img alt="CSS ist valide!" src="{$skin_base}/valid-css-blue-v.svg" style="border:0;width:88px;height:31px"/>
  256. </a>
  257. -->
  258. <xsl:text> </xsl:text>
  259. <a href="{a:link[@rel='about']/@href}">
  260. About<xsl:if test="string-length(a:link[@rel='about']/@href) &lt; 2"><span> link rel='about' missing.</span></xsl:if>
  261. </a>
  262. <xsl:text> </xsl:text>
  263. <a href="{a:link[@rel='license']/@href}">
  264. <xsl:value-of select="a:link[@rel='license']/@title"/><xsl:if test="string-length(a:link[@rel='license']/@href) &lt; 2"><span> link rel='license' missing.</span></xsl:if>
  265. </a>
  266. <xsl:text> </xsl:text>
  267. <a href="{a:link[@rel='terms-of-service']/@href}">
  268. § Imprint<xsl:if test="string-length(a:link[@rel='terms-of-service']/@href) &lt; 2"><span> link rel='terms-of-service' missing.</span></xsl:if>
  269. </a>
  270. <xsl:text> </xsl:text>
  271. <a href="{a:link[@rel='privacy-policy']/@href}">
  272. 🤫 Privacy<xsl:if test="string-length(a:link[@rel='terms-of-service']/@href) &lt; 2"><span> link rel='terms-of-service' missing.</span></xsl:if>
  273. </a>
  274. <xsl:text> </xsl:text>
  275. <a title="Generator" href="{a:generator/@uri}v{a:generator/@version}">
  276. <xsl:value-of select="a:generator"/>
  277. <xsl:text> </xsl:text>
  278. <img class="qrcode" src="{$skin_base}/qrcode.png" alt="QR Code (Generator URI)"/>
  279. </a>
  280. </p>
  281. </xsl:template>
  282. <xsl:template match="a:entry" mode="root">
  283. <noscript><p>JavaScript deactivated, almost fully functional, but <em>nicer</em> if on.</p></noscript>
  284. <xsl:call-template name="links_commands"/>
  285. <ol id="entries" class="list-unstyled">
  286. <xsl:apply-templates select="."/>
  287. </ol>
  288. <xsl:call-template name="footer"/>
  289. </xsl:template>
  290. <xsl:template match="a:entry">
  291. <xsl:variable name="link" select="a:link[not(@rel)]/@href"/>
  292. <xsl:variable name="self" select="a:link[@rel='self']/@href"/>
  293. <xsl:variable name="id_slash" select="substring-after($self, '/p/')"/>
  294. <xsl:variable name="id" select="substring-before($id_slash, '/')"/>
  295. <li id="{$id}">
  296. <h3>
  297. <xsl:if test="media:thumbnail/@url">
  298. <!-- https://varvy.com/pagespeed/defer-images.html -->
  299. <img alt="Vorschaubild" data-src="{media:thumbnail/@url}" src="data:image/png;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs=" />
  300. </xsl:if>
  301. <xsl:choose>
  302. <xsl:when test="$link">
  303. <a href="{$redirector}{$link}" rel="noopener noreferrer" referrerpolicy="no-referrer"><xsl:value-of select="a:title"/></a>
  304. </xsl:when>
  305. <xsl:otherwise>
  306. <xsl:value-of select="a:title"/>
  307. </xsl:otherwise>
  308. </xsl:choose>
  309. </h3>
  310. <xsl:if test="a:summary">
  311. <h5>
  312. <xsl:call-template name="linefeed2br">
  313. <xsl:with-param name="string" select="a:summary"/>
  314. </xsl:call-template>
  315. </h5>
  316. </xsl:if>
  317. <!-- p class="small text-right"><a><xsl:value-of select="$link"/></a></p -->
  318. <!-- html content won't work that easy (out-of-the-firebox): https://bugzilla.mozilla.org/show_bug.cgi?id=98168#c140 -->
  319. <!-- workaround via jquery: http://stackoverflow.com/a/9714567 -->
  320. <!-- Überbleibsel vom Shaarli Atom Feed raus: -->
  321. <!-- xsl:value-of select="substring-before(a:content[not(@src)], '&lt;br&gt;(&lt;a href=&quot;https://links.mro.name/?')" disable-output-escaping="yes" / -->
  322. <xsl:apply-templates select="a:content"/>
  323. <p class="categories">
  324. <xsl:for-each select="a:category">
  325. <xsl:sort select="@term"/>
  326. <xsl:if test="position() != 1">
  327. <xsl:text>, </xsl:text>
  328. </xsl:if>
  329. <a href="{@scheme}{@term}/" class="tag">#<xsl:value-of select="@term"/></a>
  330. </xsl:for-each>
  331. </p>
  332. <p class="footer">
  333. <xsl:variable name="entry_updated" select="a:updated"/>
  334. <xsl:variable name="entry_updated_human"><xsl:call-template name="human_time"><xsl:with-param name="time" select="$entry_updated"/></xsl:call-template></xsl:variable>
  335. <xsl:variable name="entry_published" select="a:published"/>
  336. <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>
  337. <a class="time" title="last: {$entry_updated_human}" href="{$xml_base}{a:link[@rel='self']/@href}"><xsl:value-of select="$entry_published_human"/></a>
  338. <xsl:if test="$link">
  339. <xsl:text> * </xsl:text>
  340. <a href="{$archive}{$link}" rel="noopener noreferrer" referrerpolicy="no-referrer">@archive.org</a>
  341. </xsl:if>
  342. <span class="hidden-logged-out">
  343. <xsl:text> * </xsl:text>
  344. <a href="{$xml_base}{a:link[@rel='edit']/@href}" rel="nofollow">Edit</a><xsl:text> </xsl:text>
  345. </span>
  346. </p>
  347. </li>
  348. </xsl:template>
  349. <xsl:template match="a:content[not(@type) or @type = 'text']">
  350. <p class="rendered type-text">
  351. <xsl:call-template name="linefeed2br">
  352. <xsl:with-param name="string" select="."/>
  353. </xsl:call-template>
  354. </p>
  355. </xsl:template>
  356. </xsl:stylesheet>