A place to cache linked articles (think custom and personal wayback machine)
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

index.html 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <!doctype html><!-- This is a valid HTML5 document. -->
  2. <!-- Screen readers, SEO, extensions and so on. -->
  3. <html lang="fr">
  4. <!-- Has to be within the first 1024 bytes, hence before the <title>
  5. See: https://www.w3.org/TR/2012/CR-html5-20121217/document-metadata.html#charset -->
  6. <meta charset="utf-8">
  7. <!-- Why no `X-UA-Compatible` meta: https://stackoverflow.com/a/6771584 -->
  8. <!-- The viewport meta is quite crowded and we are responsible for that.
  9. See: https://codepen.io/tigt/post/meta-viewport-for-2015 -->
  10. <meta name="viewport" content="width=device-width,initial-scale=1">
  11. <!-- Required to make a valid HTML5 document. -->
  12. <title>How to style RSS feed (archive) — David Larlet</title>
  13. <meta name="description" content="Publication mise en cache pour en conserver une trace.">
  14. <!-- That good ol' feed, subscribe :). -->
  15. <link rel="alternate" type="application/atom+xml" title="Feed" href="/david/log/">
  16. <!-- Generated from https://realfavicongenerator.net/ such a mess. -->
  17. <link rel="apple-touch-icon" sizes="180x180" href="/static/david/icons2/apple-touch-icon.png">
  18. <link rel="icon" type="image/png" sizes="32x32" href="/static/david/icons2/favicon-32x32.png">
  19. <link rel="icon" type="image/png" sizes="16x16" href="/static/david/icons2/favicon-16x16.png">
  20. <link rel="manifest" href="/static/david/icons2/site.webmanifest">
  21. <link rel="mask-icon" href="/static/david/icons2/safari-pinned-tab.svg" color="#07486c">
  22. <link rel="shortcut icon" href="/static/david/icons2/favicon.ico">
  23. <meta name="msapplication-TileColor" content="#f0f0ea">
  24. <meta name="msapplication-config" content="/static/david/icons2/browserconfig.xml">
  25. <meta name="theme-color" content="#f0f0ea">
  26. <!-- Documented, feel free to shoot an email. -->
  27. <link rel="stylesheet" href="/static/david/css/style_2021-01-20.css">
  28. <!-- See https://www.zachleat.com/web/comprehensive-webfonts/ for the trade-off. -->
  29. <link rel="preload" href="/static/david/css/fonts/triplicate_t4_poly_regular.woff2" as="font" type="font/woff2" media="(prefers-color-scheme: light), (prefers-color-scheme: no-preference)" crossorigin>
  30. <link rel="preload" href="/static/david/css/fonts/triplicate_t4_poly_bold.woff2" as="font" type="font/woff2" media="(prefers-color-scheme: light), (prefers-color-scheme: no-preference)" crossorigin>
  31. <link rel="preload" href="/static/david/css/fonts/triplicate_t4_poly_italic.woff2" as="font" type="font/woff2" media="(prefers-color-scheme: light), (prefers-color-scheme: no-preference)" crossorigin>
  32. <link rel="preload" href="/static/david/css/fonts/triplicate_t3_regular.woff2" as="font" type="font/woff2" media="(prefers-color-scheme: dark)" crossorigin>
  33. <link rel="preload" href="/static/david/css/fonts/triplicate_t3_bold.woff2" as="font" type="font/woff2" media="(prefers-color-scheme: dark)" crossorigin>
  34. <link rel="preload" href="/static/david/css/fonts/triplicate_t3_italic.woff2" as="font" type="font/woff2" media="(prefers-color-scheme: dark)" crossorigin>
  35. <script>
  36. function toggleTheme(themeName) {
  37. document.documentElement.classList.toggle(
  38. 'forced-dark',
  39. themeName === 'dark'
  40. )
  41. document.documentElement.classList.toggle(
  42. 'forced-light',
  43. themeName === 'light'
  44. )
  45. }
  46. const selectedTheme = localStorage.getItem('theme')
  47. if (selectedTheme !== 'undefined') {
  48. toggleTheme(selectedTheme)
  49. }
  50. </script>
  51. <meta name="robots" content="noindex, nofollow">
  52. <meta content="origin-when-cross-origin" name="referrer">
  53. <!-- Canonical URL for SEO purposes -->
  54. <link rel="canonical" href="https://lepture.com/en/2019/rss-style-with-xsl">
  55. <body class="remarkdown h1-underline h2-underline h3-underline em-underscore hr-center ul-star pre-tick">
  56. <article>
  57. <header>
  58. <h1>How to style RSS feed</h1>
  59. </header>
  60. <nav>
  61. <p class="center">
  62. <a href="/david/" title="Aller à l’accueil"><svg class="icon icon-home">
  63. <use xlink:href="/static/david/icons2/symbol-defs.svg#icon-home"></use>
  64. </svg> Accueil</a> •
  65. <a href="https://lepture.com/en/2019/rss-style-with-xsl" title="Lien vers le contenu original">Source originale</a>
  66. </p>
  67. </nav>
  68. <hr>
  69. <p>"RSS is dead" every year; it will be dead in the next year again. But before the dead coming in next year, we can do something to make it dead in an elegant way.</p>
  70. <p>RSS feed is meant to be used by machine (apps) not by human. But people may visit a feed link directly and shout out WTF is this.</p>
  71. <p>The RSS feed however can be human friendly. Take an example of my blog's RSS feed. It is simple and clean, not so scary to ordinary people.</p>
  72. <div class="md-photo"><figure><img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" data-src="https://i.typlog.com/lepture/8424206380_291282.jpg" alt="My blog feed UI" title="My blog feed UI"><figcaption>My blog feed UI</figcaption></figure></div>
  73. <h2 id="toc_1" class="md-block">XSL URL</h2>
  74. <div class="md-block blockquote"><blockquote><p>But how can we make a RSS feed look like the above UI?</p>
  75. </blockquote></div>
  76. <p>We added this UI in <a href="https://typlog.com/">Typlog</a> recently. It is pretty simple with <a href="https://www.w3.org/Style/XSL/"><strong>xsl</strong></a>. I'm not going to explain XSL in this post, instead, we can quickly decorate our RSS feeds with the famous copy paste method.</p>
  77. <div class="highlight"><pre><span></span><span class="cp">&lt;?xml version="1.0" encoding="UTF-8"?&gt;</span>
  78. <span class="cp">&lt;?xml-stylesheet href="/rss.xsl" type="text/xsl"?&gt;</span>
  79. <span class="nt">&lt;rss</span> <span class="na">version=</span><span class="s">"2.0"</span><span class="nt">&gt;</span>
  80. </pre></div>
  81. <p>Here you can see, the feed is styled by an external file <code>/rss.xsl</code>. Note here, instead of providing a shared URL <code>typlog.com/rss.xsl</code>, we are using a relative path here. Because it is required by some browsers for security reasons; we need to put the xsl file under the same domain, protocol and port with the RSS feed.</p>
  82. <p>Next, we can inspect the source code of <code>rss.xsl</code>:</p>
  83. <div class="md-block pre"><pre><code>view-source:https://lepture.com/rss.xsl</code></pre></div>
  84. <h2 id="toc_2" class="md-block">XSL Template</h2>
  85. <p>Here is an overview of the XSL file:</p>
  86. <div class="highlight"><pre><span></span><span class="cp">&lt;?xml version="1.0" encoding="utf-8"?&gt;</span>
  87. <span class="nt">&lt;xsl:stylesheet</span> <span class="na">version=</span><span class="s">"3.0"</span> <span class="na">xmlns:xsl=</span><span class="s">"http://www.w3.org/1999/XSL/Transform"</span>
  88. <span class="na">xmlns:atom=</span><span class="s">"http://www.w3.org/2005/Atom"</span><span class="nt">&gt;</span>
  89. <span class="nt">&lt;xsl:output</span> <span class="na">method=</span><span class="s">"html"</span> <span class="na">version=</span><span class="s">"1.0"</span> <span class="na">encoding=</span><span class="s">"UTF-8"</span> <span class="na">indent=</span><span class="s">"yes"</span><span class="nt">/&gt;</span>
  90. <span class="nt">&lt;xsl:template</span> <span class="na">match=</span><span class="s">"/"</span><span class="nt">&gt;</span>
  91. ...
  92. <span class="nt">&lt;/xsl:template&gt;</span>
  93. <span class="nt">&lt;/xsl:stylesheet&gt;</span>
  94. </pre></div>
  95. <p>Things to do:</p>
  96. <div class="md-block list"><ol>
  97. <li>XML namespaces: register the required namespace when you need to select it via xpath.</li>
  98. <li>XSL template: create the UI in XHTML</li>
  99. </ol></div>
  100. <h2 id="toc_3" class="md-block">XSL Methods</h2>
  101. <p>We will use some XSL methods to create our XHTML template:</p>
  102. <div class="md-block list"><ol>
  103. <li><code>xsl:if</code></li>
  104. <li><code>xsl:for-each</code></li>
  105. <li><code>xsl:attribute</code></li>
  106. <li><code>xsl:value-of</code></li>
  107. </ol></div>
  108. <p>Take a look at <code>https://lepture.com/rss.xsl</code>, follow the example. It is not hard to create a pretty UI for RSS feed.</p>
  109. </article>
  110. <hr>
  111. <footer>
  112. <p>
  113. <a href="/david/" title="Aller à l’accueil"><svg class="icon icon-home">
  114. <use xlink:href="/static/david/icons2/symbol-defs.svg#icon-home"></use>
  115. </svg> Accueil</a> •
  116. <a href="/david/log/" title="Accès au flux RSS"><svg class="icon icon-rss2">
  117. <use xlink:href="/static/david/icons2/symbol-defs.svg#icon-rss2"></use>
  118. </svg> RSS</a> •
  119. <a href="http://larlet.com" title="Go to my English profile" data-instant><svg class="icon icon-user-tie">
  120. <use xlink:href="/static/david/icons2/symbol-defs.svg#icon-user-tie"></use>
  121. </svg> Pro</a> •
  122. <a href="mailto:david%40larlet.fr" title="Envoyer un courriel"><svg class="icon icon-mail">
  123. <use xlink:href="/static/david/icons2/symbol-defs.svg#icon-mail"></use>
  124. </svg> Email</a> •
  125. <abbr class="nowrap" title="Hébergeur : Alwaysdata, 62 rue Tiquetonne 75002 Paris, +33184162340"><svg class="icon icon-hammer2">
  126. <use xlink:href="/static/david/icons2/symbol-defs.svg#icon-hammer2"></use>
  127. </svg> Légal</abbr>
  128. </p>
  129. <template id="theme-selector">
  130. <form>
  131. <fieldset>
  132. <legend><svg class="icon icon-brightness-contrast">
  133. <use xlink:href="/static/david/icons2/symbol-defs.svg#icon-brightness-contrast"></use>
  134. </svg> Thème</legend>
  135. <label>
  136. <input type="radio" value="auto" name="chosen-color-scheme" checked> Auto
  137. </label>
  138. <label>
  139. <input type="radio" value="dark" name="chosen-color-scheme"> Foncé
  140. </label>
  141. <label>
  142. <input type="radio" value="light" name="chosen-color-scheme"> Clair
  143. </label>
  144. </fieldset>
  145. </form>
  146. </template>
  147. </footer>
  148. <script>
  149. function loadThemeForm(templateName) {
  150. const themeSelectorTemplate = document.querySelector(templateName)
  151. const form = themeSelectorTemplate.content.firstElementChild
  152. themeSelectorTemplate.replaceWith(form)
  153. form.addEventListener('change', (e) => {
  154. const chosenColorScheme = e.target.value
  155. localStorage.setItem('theme', chosenColorScheme)
  156. toggleTheme(chosenColorScheme)
  157. })
  158. const selectedTheme = localStorage.getItem('theme')
  159. if (selectedTheme && selectedTheme !== 'undefined') {
  160. form.querySelector(`[value="${selectedTheme}"]`).checked = true
  161. }
  162. }
  163. const prefersColorSchemeDark = '(prefers-color-scheme: dark)'
  164. window.addEventListener('load', () => {
  165. let hasDarkRules = false
  166. for (const styleSheet of Array.from(document.styleSheets)) {
  167. let mediaRules = []
  168. for (const cssRule of styleSheet.cssRules) {
  169. if (cssRule.type !== CSSRule.MEDIA_RULE) {
  170. continue
  171. }
  172. // WARNING: Safari does not have/supports `conditionText`.
  173. if (cssRule.conditionText) {
  174. if (cssRule.conditionText !== prefersColorSchemeDark) {
  175. continue
  176. }
  177. } else {
  178. if (cssRule.cssText.startsWith(prefersColorSchemeDark)) {
  179. continue
  180. }
  181. }
  182. mediaRules = mediaRules.concat(Array.from(cssRule.cssRules))
  183. }
  184. // WARNING: do not try to insert a Rule to a styleSheet you are
  185. // currently iterating on, otherwise the browser will be stuck
  186. // in a infinite loop…
  187. for (const mediaRule of mediaRules) {
  188. styleSheet.insertRule(mediaRule.cssText)
  189. hasDarkRules = true
  190. }
  191. }
  192. if (hasDarkRules) {
  193. loadThemeForm('#theme-selector')
  194. }
  195. })
  196. </script>
  197. </body>
  198. </html>