index.html 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>004 Creation log of this place (eng)</title>
  7. <link rel="stylesheet" href="/bundle.css">
  8. </head>
  9. <body>
  10. <header class="page-header">
  11. <a href="/" class="headerlogo" title="Go home">
  12. <img src="/img/astounddS.png" alt="huh" width="28">
  13. </a>
  14. <nav>
  15. <a href="/">Home</a>
  16. <a href="/about">About Me</a>
  17. <a href="/notes">Notes</a>
  18. </nav>
  19. </header>
  20. <article>
  21. <h1>004 Creation log of this place (eng)</h1>
  22. <p>I'm neither extra proficient in English nor in coding and worst of all i have no knowledge of Javascript but this is a memo of things that didn't seems obvious to me to get this Eleventy.js blog place working at the ultimate barebone form.</p>
  23. <p>In the <strong>.eleventy.js</strong> file :</p>
  24. <pre><code class="language-js">module.exports = function(eleventyConfig) {
  25. // add my css file from the root folder
  26. eleventyConfig.addPassthroughCopy(&quot;bundle.css&quot;);
  27. // This line was to make sure my post.md weren't processed as Liquid, permitting this post here
  28. eleventyConfig.setTemplateFormats([&quot;md&quot;, &quot;njk&quot;, &quot;html&quot;]);
  29. return {
  30. // Ok idk this prevent markdown from being processed?
  31. markdownTemplateEngine: false,
  32. dir: {
  33. input: &quot;./&quot;,
  34. output: &quot;_site&quot;,
  35. layouts: &quot;layouts&quot;,
  36. includes: &quot;includes&quot;
  37. }
  38. };
  39. };
  40. </code></pre>
  41. <p>The <code>async</code> showed in the doc is unnecessary (is it?), and the return part should be at the end of the function.</p>
  42. <p>For the layout of a blog list in Nunjucks (file named &quot;home.njk&quot;):</p>
  43. <pre><code class="language-js">---
  44.     pagination:
  45.         data: collections.post
  46.         size: 3
  47.         reverse: true
  48. ---
  49. // [[PUT YOUR HTML HEADER HERE]]
  50. // A Navbar from my includes folder providing links to single pages
  51. {% include 'topbar.html' %}
  52. // I put a welcome message in this index
  53. {{ content | safe }}
  54. &lt;main&gt;
  55. &lt;ul&gt;
  56. // listing 3 blog posts, both title and whole content
  57. {% for post in pagination.items %}
  58. &lt;li&gt;&lt;h3&gt;{{ post.data.title | safe }}&lt;/h3&gt;&lt;/li&gt;
  59. {{ post.content | safe }}
  60. {% endfor %}
  61. &lt;/ul&gt;
  62. // Links to show back 3 older posts or 3 more recent
  63. &lt;p&gt;{% if page.url != pagination.href.last %}&lt;a href=&quot;{{ pagination.href.next }}&quot;&gt;Prev Page&lt;/a&gt;{% endif %} ---
  64. {% if page.url != pagination.href.first %}&lt;a href=&quot;{{ pagination.href.previous }}&quot;&gt;Next Page&lt;/a&gt;{% endif %}&lt;/p&gt;
  65. &lt;/main&gt;
  66. </code></pre>
  67. <p>The <code>data: collections.post</code> will take all files tagged with &quot;post&quot;. And then they will be listed 3 by 3 in reverse order on the blog part (the for loop).</p>
  68. <p>Be aware that if you plan on switching from Liquid to Nunjucks by renaming your file because they seems identical, there actually are minor differences :
  69. <code>{% for post in pagination.items reversed %}</code>
  70. Should become :
  71. <code>{% for post in pagination.items | reverse %}</code>
  72. And if your ever simply rename like me, be aware that Eleventy will tell you an incorrect error line number, missing as many lines as you have metadata lines on top on your file.</p>
  73. <blockquote>
  74. <p>Little anecdote: This was especially aggravating when i renamed since it told my <strong>for loop</strong> wasn't closed exactly where i had <strong>another for loop</strong> that was perfectly correct...</p>
  75. </blockquote>
  76. <p>The said index page that use home.njk to show the post list, along with the &quot; content&quot; part with the welcome message :</p>
  77. <pre><code class="language-md">---
  78. layout: home.njk
  79. title: unakt - hi
  80. ---
  81. &gt; Hi, I'm unakt - a living mess from France doing his best to sort things up.
  82. </code></pre>
  83. <p>And here is how the most basic post1.md should look like:</p>
  84. <pre><code class="language-md">---
  85. tags: post
  86. title: The title of the post
  87. ---
  88. Lorem Ipsum
  89. sit dolor amen
  90. </code></pre>
  91. <p>And this is the most basic barebone elements needed for a blog...
  92. Now there's more things to look at, like the reverse order thing being a little janky at times, but in the grand scheme of things, this let me make some text based post,</p>
  93. <p>as this one ;)</p>
  94. </article>
  95. <footer class="page-footer">
  96. <small>- unakt</small>
  97. </footer>
  98. </body>
  99. </html>