A place to cache linked articles (think custom and personal wayback machine)
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

index.html 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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` element
  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="#f7f7f7">
  24. <meta name="msapplication-config" content="/static/david/icons2/browserconfig.xml">
  25. <meta name="theme-color" content="#f7f7f7" media="(prefers-color-scheme: light)">
  26. <meta name="theme-color" content="#272727" media="(prefers-color-scheme: dark)">
  27. <!-- Documented, feel free to shoot an email. -->
  28. <link rel="stylesheet" href="/static/david/css/style_2021-01-20.css">
  29. <!-- See https://www.zachleat.com/web/comprehensive-webfonts/ for the trade-off. -->
  30. <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>
  31. <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>
  32. <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>
  33. <link rel="preload" href="/static/david/css/fonts/triplicate_t3_regular.woff2" as="font" type="font/woff2" media="(prefers-color-scheme: dark)" crossorigin>
  34. <link rel="preload" href="/static/david/css/fonts/triplicate_t3_bold.woff2" as="font" type="font/woff2" media="(prefers-color-scheme: dark)" crossorigin>
  35. <link rel="preload" href="/static/david/css/fonts/triplicate_t3_italic.woff2" as="font" type="font/woff2" media="(prefers-color-scheme: dark)" crossorigin>
  36. <script>
  37. function toggleTheme(themeName) {
  38. document.documentElement.classList.toggle(
  39. 'forced-dark',
  40. themeName === 'dark'
  41. )
  42. document.documentElement.classList.toggle(
  43. 'forced-light',
  44. themeName === 'light'
  45. )
  46. }
  47. const selectedTheme = localStorage.getItem('theme')
  48. if (selectedTheme !== 'undefined') {
  49. toggleTheme(selectedTheme)
  50. }
  51. </script>
  52. <meta name="robots" content="noindex, nofollow">
  53. <meta content="origin-when-cross-origin" name="referrer">
  54. <!-- Canonical URL for SEO purposes -->
  55. <link rel="canonical" href="https://lepture.com/en/2019/rss-style-with-xsl">
  56. <body class="remarkdown h1-underline h2-underline h3-underline em-underscore hr-center ul-star pre-tick" data-instant-intensity="viewport-all">
  57. <article>
  58. <header>
  59. <h1>How to style RSS feed</h1>
  60. </header>
  61. <nav>
  62. <p class="center">
  63. <a href="/david/" title="Aller à l’accueil"><svg class="icon icon-home">
  64. <use xlink:href="/static/david/icons2/symbol-defs-2021-12.svg#icon-home"></use>
  65. </svg> Accueil</a> •
  66. <a href="https://lepture.com/en/2019/rss-style-with-xsl" title="Lien vers le contenu original">Source originale</a>
  67. </p>
  68. </nav>
  69. <hr>
  70. <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>
  71. <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>
  72. <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>
  73. <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>
  74. <h2 id="toc_1" class="md-block">XSL URL</h2>
  75. <div class="md-block blockquote"><blockquote><p>But how can we make a RSS feed look like the above UI?</p>
  76. </blockquote></div>
  77. <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>
  78. <div class="highlight"><pre><span></span><span class="cp">&lt;?xml version="1.0" encoding="UTF-8"?&gt;</span>
  79. <span class="cp">&lt;?xml-stylesheet href="/rss.xsl" type="text/xsl"?&gt;</span>
  80. <span class="nt">&lt;rss</span> <span class="na">version=</span><span class="s">"2.0"</span><span class="nt">&gt;</span>
  81. </pre></div>
  82. <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>
  83. <p>Next, we can inspect the source code of <code>rss.xsl</code>:</p>
  84. <div class="md-block pre"><pre><code>view-source:https://lepture.com/rss.xsl</code></pre></div>
  85. <h2 id="toc_2" class="md-block">XSL Template</h2>
  86. <p>Here is an overview of the XSL file:</p>
  87. <div class="highlight"><pre><span></span><span class="cp">&lt;?xml version="1.0" encoding="utf-8"?&gt;</span>
  88. <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>
  89. <span class="na">xmlns:atom=</span><span class="s">"http://www.w3.org/2005/Atom"</span><span class="nt">&gt;</span>
  90. <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>
  91. <span class="nt">&lt;xsl:template</span> <span class="na">match=</span><span class="s">"/"</span><span class="nt">&gt;</span>
  92. ...
  93. <span class="nt">&lt;/xsl:template&gt;</span>
  94. <span class="nt">&lt;/xsl:stylesheet&gt;</span>
  95. </pre></div>
  96. <p>Things to do:</p>
  97. <div class="md-block list"><ol>
  98. <li>XML namespaces: register the required namespace when you need to select it via xpath.</li>
  99. <li>XSL template: create the UI in XHTML</li>
  100. </ol></div>
  101. <h2 id="toc_3" class="md-block">XSL Methods</h2>
  102. <p>We will use some XSL methods to create our XHTML template:</p>
  103. <div class="md-block list"><ol>
  104. <li><code>xsl:if</code></li>
  105. <li><code>xsl:for-each</code></li>
  106. <li><code>xsl:attribute</code></li>
  107. <li><code>xsl:value-of</code></li>
  108. </ol></div>
  109. <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>
  110. </article>
  111. <hr>
  112. <footer>
  113. <p>
  114. <a href="/david/" title="Aller à l’accueil"><svg class="icon icon-home">
  115. <use xlink:href="/static/david/icons2/symbol-defs-2021-12.svg#icon-home"></use>
  116. </svg> Accueil</a> •
  117. <a href="/david/log/" title="Accès au flux RSS"><svg class="icon icon-rss2">
  118. <use xlink:href="/static/david/icons2/symbol-defs-2021-12.svg#icon-rss2"></use>
  119. </svg> Suivre</a> •
  120. <a href="http://larlet.com" title="Go to my English profile" data-instant><svg class="icon icon-user-tie">
  121. <use xlink:href="/static/david/icons2/symbol-defs-2021-12.svg#icon-user-tie"></use>
  122. </svg> Pro</a> •
  123. <a href="mailto:david%40larlet.fr" title="Envoyer un courriel"><svg class="icon icon-mail">
  124. <use xlink:href="/static/david/icons2/symbol-defs-2021-12.svg#icon-mail"></use>
  125. </svg> Email</a> •
  126. <abbr class="nowrap" title="Hébergeur : Alwaysdata, 62 rue Tiquetonne 75002 Paris, +33184162340"><svg class="icon icon-hammer2">
  127. <use xlink:href="/static/david/icons2/symbol-defs-2021-12.svg#icon-hammer2"></use>
  128. </svg> Légal</abbr>
  129. </p>
  130. <template id="theme-selector">
  131. <form>
  132. <fieldset>
  133. <legend><svg class="icon icon-brightness-contrast">
  134. <use xlink:href="/static/david/icons2/symbol-defs-2021-12.svg#icon-brightness-contrast"></use>
  135. </svg> Thème</legend>
  136. <label>
  137. <input type="radio" value="auto" name="chosen-color-scheme" checked> Auto
  138. </label>
  139. <label>
  140. <input type="radio" value="dark" name="chosen-color-scheme"> Foncé
  141. </label>
  142. <label>
  143. <input type="radio" value="light" name="chosen-color-scheme"> Clair
  144. </label>
  145. </fieldset>
  146. </form>
  147. </template>
  148. </footer>
  149. <script src="/static/david/js/instantpage-5.1.0.min.js" type="module"></script>
  150. <script>
  151. function loadThemeForm(templateName) {
  152. const themeSelectorTemplate = document.querySelector(templateName)
  153. const form = themeSelectorTemplate.content.firstElementChild
  154. themeSelectorTemplate.replaceWith(form)
  155. form.addEventListener('change', (e) => {
  156. const chosenColorScheme = e.target.value
  157. localStorage.setItem('theme', chosenColorScheme)
  158. toggleTheme(chosenColorScheme)
  159. })
  160. const selectedTheme = localStorage.getItem('theme')
  161. if (selectedTheme && selectedTheme !== 'undefined') {
  162. form.querySelector(`[value="${selectedTheme}"]`).checked = true
  163. }
  164. }
  165. const prefersColorSchemeDark = '(prefers-color-scheme: dark)'
  166. window.addEventListener('load', () => {
  167. let hasDarkRules = false
  168. for (const styleSheet of Array.from(document.styleSheets)) {
  169. let mediaRules = []
  170. for (const cssRule of styleSheet.cssRules) {
  171. if (cssRule.type !== CSSRule.MEDIA_RULE) {
  172. continue
  173. }
  174. // WARNING: Safari does not have/supports `conditionText`.
  175. if (cssRule.conditionText) {
  176. if (cssRule.conditionText !== prefersColorSchemeDark) {
  177. continue
  178. }
  179. } else {
  180. if (cssRule.cssText.startsWith(prefersColorSchemeDark)) {
  181. continue
  182. }
  183. }
  184. mediaRules = mediaRules.concat(Array.from(cssRule.cssRules))
  185. }
  186. // WARNING: do not try to insert a Rule to a styleSheet you are
  187. // currently iterating on, otherwise the browser will be stuck
  188. // in a infinite loop…
  189. for (const mediaRule of mediaRules) {
  190. styleSheet.insertRule(mediaRule.cssText)
  191. hasDarkRules = true
  192. }
  193. }
  194. if (hasDarkRules) {
  195. loadThemeForm('#theme-selector')
  196. }
  197. })
  198. </script>
  199. </body>
  200. </html>