<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="4.4.1">Jekyll</generator><link href="https://meganrenae.me/feed.xml" rel="self" type="application/atom+xml" /><link href="https://meganrenae.me/" rel="alternate" type="text/html" /><updated>2026-08-17T01:35:36+00:00</updated><id>https://meganrenae.me/feed.xml</id><title type="html">meganrenae.me</title><subtitle>Personal creativity and tech blog of Megan Renae</subtitle><author><name>Megan Renae</name></author><entry><title type="html">Algorithms, Randomness, and Algorithmic Randomness</title><link href="https://meganrenae.me/algorithms-randomness-algorithmic-randomness" rel="alternate" type="text/html" title="Algorithms, Randomness, and Algorithmic Randomness" /><published>2025-10-18T00:00:00+00:00</published><updated>2025-10-18T00:00:00+00:00</updated><id>https://meganrenae.me/algorithms-randomness-algorithmic-randomness</id><content type="html" xml:base="https://meganrenae.me/algorithms-randomness-algorithmic-randomness"><![CDATA[<p>I’m fascinated by systems that can surprise even their own creators. This is the beauty of procedural generation. A few lines of code can spawn near-infinite possibilities, all mathematically bound to the initial rules established by the programmer.</p>

<p>Generative art and procedural generation (or <em>procgen</em>) can be as simple or as complex as you want. Generative art is created with the help of an autonomous system, while procedural generation uses algorithms–and often randomness–to produce content.</p>

<p>The results can be predictable or chaotic. What makes a creation “procedural”? There are two criteria, it usually meets at least one of two criteria: the use of algorithm, and the use of randomness.</p>

<h2 id="random-walks">Random Walks</h2>

<p>The random walk, also known as the drunkard’s walk, may be the simplest form of procedural randomness. It can be generated in any number of dimensions, but in this post I will demonstrating it within a 2D surface.</p>

<p>Imagine you find yourself in the middle of a grid of paths. There are sidewalks going east and west, and others going north and south. They are all evenly spaced apart. You are at a crossroads within this grid. You can go in one of four directions.</p>

<p><img src="/assets/images/stick-figure-grid-of-roads.png" alt="a grid of roads, in the center is a stick figure wondering where to go next" class="post-img-no-caption" /></p>

<p>In a random walk, you would choose a direction at random to walk, and walk in that direction until the next crossroads. And then you would again choose a direction at random, and walk in <em>that</em> direction until you reached the next crossroads – and so on. Each new step is chosen independently of the previous steps.</p>

<p>In my own version, I decided to place a pixel on the canvas at 10% opacity. The position of the next pixel (again at 10% opacity) placed was randomly selected from four possibilities – either directly above, below, left, or right of the one before it. I repeated this process step by step.</p>

<p>What this pattern ends up generating resembles a topographic map. Areas that have been retread multiple times appear darker, while other unexplored areas remain completely white. Over time, more and more of the canvas is filled with color, but the longer it goes, the longer it takes to fill.</p>

<iframe height="500" style="width: 80%;margin-left:10%" scrolling="no" title="Random Walk" src="https://codepen.io/megan-durham/embed/NPGZyXj?default-tab=result" frameborder="no" loading="lazy" allowtransparency="true" allowfullscreen="true">
  See the Pen <a href="https://codepen.io/megan-durham/pen/NPGZyXj">
  Random Walk</a> by Megan Durham (<a href="https://codepen.io/megan-durham">@megan-durham</a>)
  on <a href="https://codepen.io">CodePen</a>.
</iframe>

<p>The pattern can be adjusted in clever ways to generate a variety of effects. By limiting the direction in one dimension – for example, allowing travel up, down, on forward, but not backward – you can generate a <a href="https://codepen.io/konstantindenerz/pen/KKOYdpp">lightning effect like this one</a>. And if you connect the last step to the first with a straight line, <a href="https://codepen.io/DonKarlssonSan/pen/bWWede">you can create geometric shapes resembling buildings</a>.<sup id="fnref:1"><a href="#fn:1" class="footnote" rel="footnote" role="doc-noteref">1</a></sup></p>

<h2 id="cellular-automata-conways-game-of-life">Cellular Automata (Conway’s Game of Life)</h2>

<p>A <em>cellular automaton</em> is a visual iterating pattern that uses a grid (of any dimension) consisting of <em>cells</em>. A cell has a certain state, such as <em>on</em> or <em>off</em>, or <em>alive</em> or <em>dead</em>. With each iteration, each cell’s state updates according to the state of its neighbors.</p>

<p>The most famous cellular automaton is John Conway’s “Game of Life”. In this pattern, each cell in a 2D grid has an initial state of “alive” or “dead”. The cells’ states are updated in each iteration according to these rules:</p>

<ol>
  <li>An “alive” cell with fewer than two “alive” neighbors (neighbors can border a cell horizontally, vertically, or diagonally) will become “dead” (the “underpopulation” rule).</li>
  <li>An “alive” cell with 2-3 “alive” neighbors will stay alive.</li>
  <li>An “alive” cell with more than 3 “alive” neigbhors will become dead (the “overpopulation” rule)</li>
  <li>A dead cell with exactly 3 “alive” neighbors will become “alive” (the “reproduction” rule).</li>
</ol>

<p>The initial pattern (or seed) can be set manually or, as I’ve done below, set randomly.</p>

<iframe height="500" style="width: 80%;margin-left:10%" scrolling="no" title="cellular automata" src="https://codepen.io/megan-durham/embed/myVqapa?default-tab=result" frameborder="no" loading="lazy" allowtransparency="true" allowfullscreen="true">
  See the Pen <a href="https://codepen.io/megan-durham/pen/myVqapa">
  cellular automata</a> by Megan Durham (<a href="https://codepen.io/megan-durham">@megan-durham</a>)
  on <a href="https://codepen.io">CodePen</a>.
</iframe>

<p>To me, the most interesting thing about this pattern isn’t the illustrations it produces, but how it creates a timelapse that can tell a story of epic scale. Notice how every now and then you’ll have a space of four cells, two on top and two on bottom, that have been stable and alive for several generations, only to be undone by a much larger encroaching pattern venturing from several grid spaces away.</p>

<p>Eventually, most seeds in the Game of Life will settle in to an infinite holding pattern or loop, but some go on forever.</p>

<p>The algorithm itself is simple to implement, and there are options to play around with when it comes to visual customization. You can <a href="https://codepen.io/foretoo/pen/xxeoJoq">stack each generation on top of its predecessors to create a 3D structure</a>. You can <a href="https://codepen.io/bigsweater/pen/borNym">play around with color</a> or go with an <a href="https://codepen.io/safx/pen/MWaKqZ">isometric design</a>.<sup id="fnref:2"><a href="#fn:2" class="footnote" rel="footnote" role="doc-noteref">2</a></sup></p>

<h2 id="recursive-backtracker-maze-generation">Recursive Backtracker Maze Generation</h2>

<p>Now, it’s time to put randomness and algorithmic patterns together. There are several generative patterns that make use of both.</p>

<p>As an example, I made this <a href="https://codepen.io/megan-durham/full/RNWXbjw">spinning hexagon grid</a> by changing the <em>range</em> of the random values determining the speed at which a particular hexagon spins and grows. The closer a hexagon is to the center of the grid, the higher its potential speed.</p>

<p>The spinning hexagon grid can be described as a “noise-like”<sup id="fnref:3"><a href="#fn:3" class="footnote" rel="footnote" role="doc-noteref">3</a></sup> generative pattern.</p>

<p>Another pattern type that uses “algorithmic randomness” is <em>maze generation</em> – which is exactly what the name suggests. <a href="https://en.wikipedia.org/wiki/Maze_generation_algorithm">There are several maze generation algorithms out there</a>. The one I went with below is the <em>recursive backtracker</em> method (or the <em>randomized depth-first search</em> method). This method, which implements that random walk pattern shown earlier, creates a grid and tracks the state of each cell as “visited” and “unvisited”.</p>

<p>Here’s how it works:</p>

<ol>
  <li>Start with a grid of cells, like in our cellular automaton generation. To start, each cell has four walls (north, east, south, and west). All cells are “unvisited”.</li>
  <li>Pick a random starting cell and mark it as “visited”.</li>
  <li>While there are still “unvisited” cells:
    <ol>
      <li>From the current cell, if there are any unvisited neighbors:
        <ol>
          <li>Randomly choose an unvisited neighbor.</li>
          <li>Remove the wall between the current cell and the neighbor.</li>
          <li>Mark the neighbor as the current cell, mark it as visited, and add the previous cell to an array called a “stack” to track the movement.</li>
        </ol>
      </li>
      <li>If the current cell has no unvisited neighbors:
        <ol>
          <li>Remove the last cell visited from the stack, and go back to that cell, and repeat the process again.</li>
        </ol>
      </li>
      <li>If the “stack” is empty, all cells have been visited and the loop can be exited. The process is complete.</li>
    </ol>
  </li>
</ol>

<p>And this is the result:</p>

<iframe height="500" style="width: 80%;margin-left:10%" scrolling="no" title="Recursive Backtracker" src="https://codepen.io/megan-durham/embed/pvgpEev?default-tab=result" frameborder="no" loading="lazy" allowtransparency="true" allowfullscreen="true">
  See the Pen <a href="https://codepen.io/megan-durham/pen/pvgpEev">
  Recursive Backtracker</a> by Megan Durham (<a href="https://codepen.io/megan-durham">@megan-durham</a>)
  on <a href="https://codepen.io">CodePen</a>.
</iframe>

<p>Once the maze is complete, you can choose any two points on the grid as your “entrance” and “exit”. There will be exactly one path between them.</p>

<p>As always, there are several adjustments one can make to a maze generation. Instead of using squares as cells, you could use <a href="https://codepen.io/timohausmann/pen/YzyXpr">hexagons</a>. You may try to <a href="https://codepen.io/obsfx/pen/xMQLmd">creative a visualization of your path</a>.<sup id="fnref:4"><a href="#fn:4" class="footnote" rel="footnote" role="doc-noteref">4</a></sup></p>

<h2 id="some-other-neat-patterns">Some other neat patterns</h2>

<ul>
  <li><a href="https://codepen.io/search/pens?q=Sierpinski+Triangle">Sierpinski Triangle</a></li>
  <li><a href="https://codepen.io/search/pens?q=tree+branching">Tree branching</a></li>
  <li><a href="https://codepen.io/search/pens?q=mandelbrot+set">Mandelbrot set</a></li>
  <li><a href="https://codepen.io/search/pens?q=golden+ratio">Golden ratio</a></li>
  <li><a href="https://codepen.io/search/pens?q=kaleidoscope">Kaleidoscope</a></li>
  <li><a href="https://codepen.io/search/pens?q=Bauhaus">Bauhaus</a></li>
</ul>

<h2 id="recommended-reading">Recommended Reading</h2>

<ul>
  <li><a href="https://inconvergent.net/generative/">On Generative Algorithms</a> <em>inconvergent (Anders Hoff)</em></li>
  <li><a href="https://inconvergent.net/generative/">Generative Artistry</a> <em>Ruth John and Tim Holman</em></li>
  <li><a href="https://bost.ocks.org/mike/algorithms/">Visualizing Algorithms</a> <em>Mike Bostock</em></li>
</ul>

<h2 id="footnotes">Footnotes</h2>

<div class="footnotes" role="doc-endnotes">
  <ol>
    <li id="fn:1">
      <p><a href="https://codepen.io/DonKarlssonSan/pen/bWWede">Codepen search results for “Random Walk”</a> <a href="#fnref:1" class="reversefootnote" role="doc-backlink">&#8617;</a></p>
    </li>
    <li id="fn:2">
      <p><a href="https://codepen.io/search/pens?q=game+of+life">Codepen search results for “Game of Life”</a> <a href="#fnref:2" class="reversefootnote" role="doc-backlink">&#8617;</a></p>
    </li>
    <li id="fn:3">
      <p><em>Noise</em> refers to random or pseudo-random variations of brightness or color within an image. For a much better explanation and a tutorial, see <a href="https://varun.ca/noise/">this post by Varun Vachhar</a>. <a href="#fnref:3" class="reversefootnote" role="doc-backlink">&#8617;</a></p>
    </li>
    <li id="fn:4">
      <p><a href="https://codepen.io/search/pens?q=maze+generation">Codepen search results for “Maze Generation”</a> <a href="#fnref:4" class="reversefootnote" role="doc-backlink">&#8617;</a></p>
    </li>
  </ol>
</div>]]></content><author><name>Megan Renae</name></author><category term="algorithms" /><category term="programming" /><category term="procgen" /><category term="generative-art" /><category term="randomness" /><summary type="html"><![CDATA[I'm fascinated by systems that can surprise even their own creators. This is the beauty of procedural generation.]]></summary></entry><entry><title type="html">From org to jekyll: A new beginning</title><link href="https://meganrenae.me/org-to-jekyll-new-beginning" rel="alternate" type="text/html" title="From org to jekyll: A new beginning" /><published>2025-06-28T00:00:00+00:00</published><updated>2025-06-28T00:00:00+00:00</updated><id>https://meganrenae.me/org-to-jekyll-new-beginning</id><content type="html" xml:base="https://meganrenae.me/org-to-jekyll-new-beginning"><![CDATA[<p>It’s been nearly five years since I published my first blog post using org-mode. While I loved the novelty of using org-mode to create a publish a static website and blog, and I’m proud that I was able to figure out how to make it work (at least in theory), it ended up being a bit too high-maintenance for me on a practical level. My resolve to DIY my blog from the ground up ended up being its undoing.</p>

<p>So now I’m going again, this time using <a href="https://jekyllrb.com">Jekyll</a>. Jekyll was an easy choice. I’m familiar with the platform (my knowledge database, <a href="https://megan-zk.netlify.app/">megan-zk</a>, is written with Jekyll), it’s got a wide user base and extensive documentation, and it’s flexible enough that it can be custommized to just about any purpose.</p>

<p>Mostly, though: Jekyll is easy and quick. My experience with maintaining my blog using org-mode taught me the importance of choosing a platform that allowed me to focus on the important things.</p>

<h3 id="so-was-the-org-blogging-experiment-a-failure">So, was the org blogging experiment a failure?</h3>

<p>Short answer: No.</p>

<p>Long answer: No. My org-mode blog, <a href="https://meganrenae21.github.io/Meg-in-Progress/">Meg in Progress</a>, was a learning experiment. That was what I had intended for it to be, and to that end, it was successful.</p>

<p>And look, there’s nothing <em>wrong</em> with using org-mode as a blogging engine. <a href="https://orgmode.org/worg/org-web.html">Plenty of people have made it work for them</a>. And clearly, once I had gotten it up and running, it was working for me – at least for the <em>four</em> posts I published to Meg in Progress between August 2020 and March 2021.</p>

<p>When I decided to get back to blogging earlier this month, I wanted to use org again. The first thing I did was attempt to revamp the site as a whole, and I quickly ran into issues.</p>

<p>To start, org’s HTML export options are highly configurable, but I found it to be incredibly troublesome to manipulate the top-level HTML files so that my custom elements would be inserted exactly how and where I needed to be on the page.</p>

<p>I wanted to add a footer element to the site. This footer would appear at the bottom of each page on the site. I used the HTML export option <code class="language-plaintext highlighter-rouge">org-html-postamble</code> to achieve this.</p>

<p>The problem was that I wanted the footer to be <em>inside</em> the main <code class="language-plaintext highlighter-rouge">&lt;div id=content&gt;</code> which included the actual post (or page) content.</p>

<p>This is how I wanted it to look:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>&lt;div id="content"&gt;
  &lt;div class="header_containter"&gt;
    &lt;div class="header"&gt;Meg in Progress&lt;/div&gt;
    &lt;div class="nav"&gt;
      &lt;a class="navlink"&gt;about&lt;/a&gt;
      &lt;a class="navlink"&gt;archives&lt;/a&gt;
      &lt;a class="navlink"&gt;tags&lt;/a&gt;
      &lt;a class="navlink"&gt;home&lt;/a&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="post_header"&gt;
    &lt;div class="post_title"&gt;An example title&lt;/div&gt;
    &lt;div class="post_date"&gt;XX/XX/XXXX&lt;/div&gt;
    &lt;div class="post_tags"&gt;
      &lt;a class="taglink"&gt;tag&lt;/a&gt;
      &lt;a class="taglink"&gt;another&lt;/a&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="post_content"&gt;
    ...post...
  &lt;/div&gt;
  &lt;div class="footnotes"&gt;
    ...footnote section...
  &lt;/div&gt;
  &lt;div class="footer"&gt;
    Custom footer / org postamble element
  &lt;/div&gt;
&lt;/div&gt;
</code></pre></div></div>

<p>Notice how the content container isn’t closed until after the footer is inserted, but the footer is not contained in any <em>other</em> element.</p>

<p>At first, instead of the postamble, I used a custom <code class="language-plaintext highlighter-rouge">include</code> block to export the footer. But when I included the footer at the end of each page and post exported, it ended up like this:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>&lt;div id="content"&gt;
... post content here...
  &lt;div class="footnotes"&gt;
  ... some footnotes ...
    &lt;div class="footer"&gt;
      footer here
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;
</code></pre></div></div>

<p>The footer was being <em>inside</em> the last element/section of each post, rather than on its own within the top-level container.</p>

<p>I thought using the postamble export option would fix this. Instead, this was the result:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>&lt;div id="content"&gt;
  ... post content here ....
&lt;/div&gt;
&lt;div class="postamble"&gt;
  footer here
&lt;/div&gt;
</code></pre></div></div>

<p>This time, the footer ended up <em>outside</em> the content container, which wasn’t what I wanted at all. The idea was that all the content that would appear on each page would within a parent container, in which I could use CSS <code class="language-plaintext highlighter-rouge">display: flex</code> to easily align and justify the elements within that box.</p>

<p>I understand that I could tinker with the export options via trial and error to figure out how to make it work. I could remove the parent container altogether, and apply <code class="language-plaintext highlighter-rouge">display: flex</code> to the <code class="language-plaintext highlighter-rouge">&lt;body&gt;</code> element. I could use the <code class="language-plaintext highlighter-rouge">org-html-preamble</code> option to create my custom header, rather than an import statement, so both the footer and the header would be positioned <em>outside</em> the container. My issue was not that org-mode didn’t allow me to do what I wanted.</p>

<p>The issue was that the time and effort it took to get it right subtracted from the time I had available to actually write. Creating substantive content is the entire purpose of keeping a blog in the first place.</p>

<p>Another issue was that it was backwards enforcement of any the textual format of certain template elements. I used <code class="language-plaintext highlighter-rouge">ya-snippets</code> to create templates, and once a snippet was created, the content of that snippet was not dynamic.</p>

<p>Just take a look at how the first three posts I wrote for <a href="https://meganrenae21.github.io/Meg-in-Progress/">Meg in Progress</a> appear on the index page:</p>

<blockquote>
  <h4 id="what-the-latest-impreachment-trial-says-about-the-current-state-of-us-politics">What the Latest Impreachment Trial Says about the Current State of US Politics</h4>
  <p><strong>02/27/21 Sat</strong><br />
On the weekend before Last, the US Senate concluded the second impeachment trial of former president Donald Trump, who had been impeached for inciting the insurrection at the US Capitol on January 6.. <span class="fake_link">Read more…</span><br />
<span class="fake_link">politics</span></p>

  <h4 id="blogging-with-org-mode-an-update">Blogging with Org Mode: An Update</h4>
  <p><strong>Saturday, August 22, 2020</strong><br />
In my <span class="fake_link">last post</span>, I went over how I set up this blog solely in org-mode. And since that post has been published, I’ve made a few more changes to the configuration and so, in an effort to provide the most up to date information, I figured I’d write a little addendum. <span class="fake_link">Read more…</span><br />
<span class="fake_link">dev</span></p>

  <h4 id="how-i-built-a-simply-static-blog-with-org-mode--081120-tue">How I built a simply static blog with org-mode || 08/11/20 Tue</h4>
  <p><span class="fake_link_2">dev</span> There’s always something new to discover with emacs and org-mode, and building a blog was my way of wading into deeper waters - no longer content to just get my feet wet. <span class="fake_link">Read more…</span></p>
</blockquote>

<p>As you can see, it’s a mess of inconsistency. Changes made to the snippet don’t update the snippets that have already been applied. If I want to make a formatting change that will apply across <em>all</em> entries, including past entries, I would have to manually go back and change each post. Perhaps in time I could have figured out a solution, which brings me back to the previous point: it’s <em>time</em> I’m saving by moving to Jekyll.</p>

<h3 id="more-blogging-less-troubleshooting">More blogging, less troubleshooting</h3>

<p>As a developer, I’m all too familiar with the process of constantly adapting and fixing your code when it breaks or throws out results you didn’t expect. I know that, with a blog created with a static site generator, <em>some</em> technical fine-tuning will always be necessary.</p>

<p>As a blogging platform, Jekyll makes life <em>a lot</em> easier by offering several tools for the technical process:</p>

<ul>
  <li>Templates and includes allow you complete control over the HTML. Everything on each page and post is laid out exactly like I set it up. I can update styles without getting unexpected results.</li>
  <li>YAML frontmatter and data files used alongside the <a href="https://shopify.github.io/liquid/">Liquid templating language</a> keep pages and posts formatted consistently across the site.</li>
  <li>Extensive documentation and a huge userbase means that there are numerous resources available for any updates I want to make or any technical issues I may be having.</li>
  <li>A stockpile of available themes and plugins can help to instantly implement new features to a site.</li>
  <li>It is incredibly simple and fast to get up and running, even without a theme, and you can easily integrate your own CSS and javascript files.</li>
  <li><a href="https://jekyllrb.com/docs/deployment/">Painless deployment</a> to the back-end platform of your choice. This blog uses <a href="https://www.netlify.com/">Netlify</a> which builds the site each time I push a new commit to this blog’s <a href="https://github.com/meganrenae21/blog">Github repository</a>.</li>
</ul>

<p>This is not to say that Jekyll offers every single thing I wanted right out of the box. While its builds the site from source, convering markdown (.md) files to HTML, Jekyll doesn’t create new pages from scratch. This means that I have to create monthly archive pages and tag pages myself whenever I create the first post in a particular month or use a tag for the first time. What I <em>don’t</em> need to do, though, is update those pages each time I make a new post. Archive lists are created programmatically through the liquid templates. Every post with the tag “jekyll” will show up in the tag page for <a href="./tags/jekyll.html">jekyll</a>, provided the page exists. Every post from June 2025 will show up in the corresponding <a href="./archives/2025/june.html">June 2025 archive page</a> – again, provided the page exists. The markdown source for these tag and archive pages is completely empty except for two lines of YAML frontmatter:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>---
title: 
layout: 
---
</code></pre></div></div>

<p>The <em>layout</em> is the file in the source <code class="language-plaintext highlighter-rouge">_layouts</code> folder that serves as the HTML template for the page, and the <em>title</em> is used to pull all posts with that tag or from that month.</p>

<p>There is a <a href="https://github.com/pattex/jekyll-tagging">plugin</a> for a simpler implementation of tags. I could also write a script in Python that would generate pages for me. I may do this in the future. However, it’s hardly any trouble to manually add a new page with the required frontmatter whenever I need to–and that way I don’t have to worry about any additional scripts or plugins breaking. It keeps things light-weight.</p>

<h3 id="what-next">What next?</h3>

<p>I plan to keep contributing to this blog, and making changes as I go along. I don’t really have any major plans for the blog itself for the time being. I had considered adding a comment system, but I don’t have the readership for that right now.</p>

<p>I see this site as a way to share information about various projects I’m working on and the things I’m learning. I want to focus primarily on publishing good, substantive content worth reading.</p>]]></content><author><name>Megan Renae</name></author><category term="jekyll" /><category term="blogging" /><summary type="html"><![CDATA[It's been nearly five years since I published my first blog post using org-mode. While I loved the novelty of using org-mode to create a publish a static website and blog, and I'm proud that I was able to figure out how to make it work (at least in theory), it ended up being a bit too high-maintenance for me on a practical level. My resolve to DIY my blog from the ground up ended up being its undoing.]]></summary></entry><entry><title type="html">Blogging with Org-Mode: An Update</title><link href="https://meganrenae.me/org-mode-blog-pt-2" rel="alternate" type="text/html" title="Blogging with Org-Mode: An Update" /><published>2020-08-22T00:00:00+00:00</published><updated>2020-08-22T00:00:00+00:00</updated><id>https://meganrenae.me/blogging-with-org-mode-part-2</id><content type="html" xml:base="https://meganrenae.me/org-mode-blog-pt-2"><![CDATA[<p>In my <a href="../blogging-with-org-mode/">last post</a>, I went over how I set up this blog solely in org-mode. And since that post has been published, I’ve made a few more changes to the configuration and so, in an effort to provide the most up to date information, I figured I’d write a little addendum.</p>

<h3 id="comments">Comments</h3>

<p>I wanted to add a comments section to entries. I really didn’t want to put much effort into this…just a simple box to respond to posts. It turned out that <a href="http://utteranc.es">utterances</a> provided me with something that was easy to set up and visually appealing. The only issue is that in order to comment, you have to be signed in to <a href="http://github.com">github</a>. Since my site is hosted on github pages, though, this seems like an okay compromise.</p>

<p>I chose utterances because each comment section will be self-hosted on this site’s repo, it was simple to set up, and while people have to log in to leave comments, I preferred that to allowing “guest” comments. Since internet comment sections have a reputation for being toxic hell-scapes, I wanted to ensure commenters have a stake in what they say. As much as I am an advocate for free speech, I don’t want to provide a platform where people are enabled to evade responsibility for what they say.</p>

<p>Facebook comments was out because I am not going to force people to use their real names to comment. Disqus would be the obvious choice, or any number of third-party systems. I wasn’t inclined to go down that road, mostly because of privacy issues. I don’t want data gathered from user comments on my site to be sold by a third party to advertisers. If I expect commenters on my posts to take responsibility for their words, I have a responsibility to ensure an open discussion forum doesn’t turn into a for-profit opportunity for anonymous corporations.</p>

<p>It was incredibly easy to set up. All it involved was to install the utterances app on my blog repo, then paste a code snippet to my post template. If you’ll recall, I am using YASnippet as a templating tool for my blog posts. That said, I didn’t add the code directly into my post snippet. Instead I added a new directory, <code class="language-plaintext highlighter-rouge">~/org/src/</code> where I created an <code class="language-plaintext highlighter-rouge">utterances.html</code> file with the code in question. Then I simply included the file in my snippet to be exported as html:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>#+INCLUDE: "../src/utterances.html" export html
</code></pre></div></div>

<h3 id="templating-update">Templating Update</h3>

<p>Another change I made I started to touch on in my last post, and that has to do with my yasnippet “snippets”. I mentioned that including actual code within my ya-snippet file created an issue if I were to make changes to my blog template after the fact. Because of this, I decided to completely revamp my post snippet so that the build of each post is made mostly from external files. Here’s an example of what I’m talking about:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>#+BEGIN_SRC html
#+SETUPFILE: ../org-templates/level-1.org
#+INCLUDE: "./src/header.html" export html

#+TITLE: ${1:Title}
#+CATEGORY: ${2:Category}
#+DATE: `(current-time-string)`
#+FILENAME: ${3:filename}

=* $1=

#+INCLUDE: "../../content/$3.org"

#+INCLUDE: "../src/utterances.html" export html
#+END_SRC
</code></pre></div></div>

<p>Notice that, in addition to the <code class="language-plaintext highlighter-rouge">SETUPFILE</code>, I have added three different <code class="language-plaintext highlighter-rouge">INCLUDE</code> files to export as blocks.</p>

<ul>
  <li><code class="language-plaintext highlighter-rouge">header.html</code> :: previously this was part of an export block included directly in the snippet. The code hasn’t changed; it’s just housed elsewhere.</li>
  <li><code class="language-plaintext highlighter-rouge">/content/</code> directory :: this was the solution to my date problem that I mentioned in my previous entry. Basically, posts should be dated according to when they were published, not when I started writing them. One solution would be to use the org exporter’s <code class="language-plaintext highlighter-rouge">{{{DATE}}}</code> macro, which assigns a date when the file is exported, but I wanted to ensure the date wouldn’t change if I needed to republish a file for any reason. So, I decided the best thing to do would be to house the actual blog content in a separate file, to be included in the post file, so the date would only be calculated when the snippet was inserted into the post. The idea is to only create a post for export when it is ready to be published.</li>
  <li><code class="language-plaintext highlighter-rouge">utterances.html</code> :: I explained this above.</li>
</ul>

<h3 id="to-conclude">To conclude</h3>

<p>As I said in my the previous post, this blog is, and will continue to be, a work in progress. Still, I probably won’t go over every single change or update I make to the configuration and templating system in the future. Instead, I’ll focus on figuring out what kind of content to put on here. I’m barely a programmer or developer – I would call myself a creative, and the purpose of this blog is to share some of my story and my process with the world. Stay tuned!</p>]]></content><author><name>Megan Renae</name></author><category term="orgmode" /><category term="emacs" /><category term="webdev" /><summary type="html"><![CDATA[In my [last post](../blogging-with-org-mode/), I went over how I set up this blog solely in org-mode. And since that post has been published, I've made a few more changes to the configuration and so, in an effort to provide the most up to date information, I figured I'd write a little addendum.]]></summary></entry><entry><title type="html">How I built a simple static blog with org-mode</title><link href="https://meganrenae.me/blogging-with-org-mode" rel="alternate" type="text/html" title="How I built a simple static blog with org-mode" /><published>2020-08-11T00:00:00+00:00</published><updated>2020-08-11T00:00:00+00:00</updated><id>https://meganrenae.me/blogging-with-org-mode</id><content type="html" xml:base="https://meganrenae.me/blogging-with-org-mode"><![CDATA[<p>There’s always something new to discover with Emacs and org-mode, and building a blog was my way of wading into deeper waters - no longer content to just get my feet wet.</p>

<p>And then there’s org-mode<sup id="fnref:4"><a href="#fn:4" class="footnote" rel="footnote" role="doc-noteref">1</a></sup>, and all of its customization options and packages<sup id="fnref:5"><a href="#fn:5" class="footnote" rel="footnote" role="doc-noteref">2</a></sup>, and after playing around a bit I asked myself: <em>is there anything I can’t do from here?</em> I began using org-mode as a simple orgnization system and going through example setups and tutorial, noticing that many of the blogs and sites I was getting information from were themselves /written in org-mode/. And since I learn things best by doing projects I get really passionate about, I decided to give it a go and create my own static site blog with org-mode, which I would host on Github pages.</p>

<p>That’s how I became obsessed.</p>

<p>What follows is an abridged step-by-step summary of my process in creating a very basic framework for a static<sup id="fnref:6"><a href="#fn:6" class="footnote" rel="footnote" role="doc-noteref">3</a></sup> site blogging framework, which I am using for this blog.</p>

<h3 id="starting-points-and-goals">Starting points and goals</h3>

<p>I use <a href="https://www.spacemacs.org/">Spacemacs</a>, which is not a separate piece of software; rather, it is a specific emacs  configuration for organizing and using emacs (to put it in the most simple terms). I also have access to all the built-in functionality of org-mode, and, if necessary, whatever package extensions I would need to get started. I realized that, given the right packages, there was very little that <em>couldn’t</em> be done.</p>

<p>Yet, installing packages left and right carried the risk of overreliance on external packages, and a lack of confidence in my own ability to find creative resolutions outside of fancy extensions. So I made a few flexible ground rules for myself with this in mind:</p>

<ul>
  <li>I would use, as much as possible, the built-in functionality of org-mode, including org-publish and the org exporters, and would not use an external static site generator package<sup id="fnref:7"><a href="#fn:7" class="footnote" rel="footnote" role="doc-noteref">4</a></sup>.</li>
  <li>I would build a framework that took advantage of org-mode functions while also allowing myself to /not/ use methods that existed if they didn’t suit my needs.</li>
  <li>I would not be restricted to solely using org-mode. I had to remind myself that there could be built-in or external emacs packages that weren’t specific to org, but could be easily integrated into my workflow.</li>
  <li>It didn’t have to be perfect or do <em>every little thing</em> I’d like to be “live”; this was a project that could be continuously in development, with features/functionality added as I learned more.</li>
</ul>

<p>I’m going to reiterate here, <strong>I’m a complete newbie</strong>. I know very little emacs-lisp, I’ve only been playing around in emacs for a little over a month, and this build is based on what I’ve mastered <em>so far</em>. There are certainly aspects that could have been made a lot easier by using already-established solutions for a lot of my issues, but what fun would that be? I wanted this to be a fun, discovery process where I could figure things out, largely by my own tinkering and experimentation. So, please, if you are an emacs and org-mode master, be kind.</p>

<h3 id="initial-file-framework">Initial file framework</h3>

<p>The best resource I found at the beginning of this endeavor was an <a href="https://orgmode.org/worg/org-tutorials/org-publish-html-tutorial.html">org-publish tutorial</a> on <a href="https://orgmode.org/worg/index.html">Worg</a>, a subsection of the official  org-mode website maintained by the community of org-users that is an invaluable tool in learning all that you can do with org-mode.</p>

<p>Using this tutorial as a guide, I created two folders within my main project folder: <code class="language-plaintext highlighter-rouge">~/org/</code> and  <code class="language-plaintext highlighter-rouge">~/public_html/</code>. The idea is that my input would be under the  <code class="language-plaintext highlighter-rouge">~/org/</code> directory, and whatever was in that directory would be exported to html and published in the <code class="language-plaintext highlighter-rouge">~/public_html/</code> directory.</p>

<p>After that, I left the <code class="language-plaintext highlighter-rouge">~/public_html/</code> folder alone, as any files and subdirectories should be created during the publishing process. Any changes I would make to the final html version of the files would be done in the org version.</p>

<p>Additionally, since <em>anything</em> in the <code class="language-plaintext highlighter-rouge">~/org/</code> directory would be exported (unless I specifically configured a certain file or headline not to be exported), it wasn’t restricted to simply <em>org</em> files. Simply put, any file at all that I wanted to eventually wind up in <code class="language-plaintext highlighter-rouge">~/public_html/</code> would be placed within <code class="language-plaintext highlighter-rouge">~/org/</code>.</p>

<p>First, I created <code class="language-plaintext highlighter-rouge">index.org</code> within <code class="language-plaintext highlighter-rouge">~/org/</code> and then I created several folders (subdirectories) that would eventually carry files of their own. This was my initial file organization for this blog:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>| ~/org/
  |- index.org
  |- css/
    |- style.css
  |- img/
  |- posts/
| ~/public_html/
</code></pre></div></div>

<p>With this setup, <code class="language-plaintext highlighter-rouge">index.org</code> would become <code class="language-plaintext highlighter-rouge">index.html</code> under the <code class="language-plaintext highlighter-rouge">~/public_html/</code> directory. Additionally, <code class="language-plaintext highlighter-rouge">~/org/css/style.css</code> would be exported to <code class="language-plaintext highlighter-rouge">~/public_html/css/style.css</code> so I could apply a consistent style to exported HTML files. The <code class="language-plaintext highlighter-rouge">img/</code> directory would carry images and other attachments, while all posts would go into the <code class="language-plaintext highlighter-rouge">posts/</code> folder for export.</p>

<p>Note, that if, in editing an org file within the <code class="language-plaintext highlighter-rouge">~/org/</code> directory, if I were to link to another org file within <code class="language-plaintext highlighter-rouge">~/org/</code>, the exporter would then transform that link into a link to the corresponding file in <code class="language-plaintext highlighter-rouge">~/public_html/</code>. Likewise, by applying <code class="language-plaintext highlighter-rouge">/css/style.css</code> to <code class="language-plaintext highlighter-rouge">index.org</code>, the <code class="language-plaintext highlighter-rouge">~/public_html/index.html</code> file resulting from the export would be loaded with a stylesheet in <code class="language-plaintext highlighter-rouge">~/public_html/css/style.css</code>.</p>

<h3 id="the-exportel-file">The <code class="language-plaintext highlighter-rouge">export.el</code> file</h3>

<p>Once I got some basic files set up under this framework, I needed to perform an initial export test to ensure that this would work as planned. Instead of creating my project configuration under my main emacs config file, I decided to use a separate file, <code class="language-plaintext highlighter-rouge">~/export.el</code>, which I placed in my <em>root</em> (even with, and not under, <code class="language-plaintext highlighter-rouge">~/public_html/</code> and <code class="language-plaintext highlighter-rouge">~/org/</code>).</p>

<p>The first line is <code class="language-plaintext highlighter-rouge">(require 'ox-publish)</code> which I use to ensure that emacs loads the ox-publish library when publication is triggered. After that I set the variable <code class="language-plaintext highlighter-rouge">org-publish-project-alist</code> to define my project scope.</p>

<p>First, I provide a list of components (“blog-posts”, “blog-pages”, and “blog-static”), and then I compile those components (and all of their settings) into the “blog” project. So it goes like this:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>    (setq org-publish-project-alist
       '(("blog-posts"
          :base-directory "org/posts/"
          :base-extension "org"
          :publishing-directory "public_html/posts/"
          :recursive t
          :publishing-function org-html-publish-to-html
          :org-html-preamble nil
         )
         ("blog-pages"
          :base-directory "org/"
          :base-extension "org"
          :publishing-directory "public_html/"
          :recursive t
          :publishing-function org-html-publish-to-html
          :org-html-preamble nil
         )
         ("blog-static"
          :base-directory "org/"
          :base-extension "css\\|js\\|png\\|jpg\\|gif\\|pdf\\|mp3\\|ogg\\|swf"
          :publishing-directory "public_html/"
          :recursive t
          :publishing-function org-publish-attachment
         )
         ("blog"
          :components ("blog-posts" "blog-pages" "blog-static"))
    )
</code></pre></div></div>

<p>Now, I have several other options set up in <code class="language-plaintext highlighter-rouge">export.el</code> but have narrowed down what I felt were the most important for me to get this page set up how I want it. Let’s take a closer look at the three components and the settings I gave them above.</p>

<h4 id="components">Components</h4>

<ul>
  <li><strong>blog-posts:</strong> these are all the posts that will be published to the blog. I’ve given them a separate component because the configuration for these files could potentially differentiate from what’s in “blog-pages”, and I think it’s better to keep each part of the site separate as much as possible.</li>
  <li><strong>blog-pages:</strong> so here we’re going with every org file within the <code class="language-plaintext highlighter-rouge">~/org/</code> directory<sup id="fnref:8"><a href="#fn:8" class="footnote" rel="footnote" role="doc-noteref">5</a></sup>.</li>
  <li><strong>blog-static:</strong> for all files included in the <code class="language-plaintext highlighter-rouge">~/org/</code> directory that <em>aren’t</em> org files, and should keep their native extension upon export.</li>
  <li><strong>blog:</strong> this gives us all these separate components, and puts them together into one project.</li>
</ul>

<h4 id="options">Options</h4>

<ul>
  <li><strong>base-directory:</strong> this is the directory where the files are coming <em>from</em> - in this case <code class="language-plaintext highlighter-rouge">~/org/</code></li>
  <li><strong>publishing-directory:</strong> the directory where the files are going to be published <em>to</em> - <code class="language-plaintext highlighter-rouge">~/public_html/</code></li>
  <li><strong>base-extension:</strong> tells the exporter to export files with this(these) extensions. For pages and posts, the files exported will end in <code class="language-plaintext highlighter-rouge">.org</code>, but for the static files, the base extension has multiple possibilities.</li>
  <li><strong>publishing-function:</strong> this tells the back-end how to publish these files. I need to publish everything that’s an org file as an html file, so I set <code class="language-plaintext highlighter-rouge">blog-posts</code> and <code class="language-plaintext highlighter-rouge">blog-pages</code> with <code class="language-plaintext highlighter-rouge">org-html-publish-to-html</code>. Meanwhile, anything in the <code class="language-plaintext highlighter-rouge">~/org/</code> directory that doesn’t end in <code class="language-plaintext highlighter-rouge">.org</code> (<code class="language-plaintext highlighter-rouge">blog-static</code>) should just be copies into the desination folder using <code class="language-plaintext highlighter-rouge">org-publish-attachment</code>.</li>
  <li><strong>recursive:</strong> tells the exporter whether to include files from subdirectories recursively, or just from the parent directory. This has two possible options: <code class="language-plaintext highlighter-rouge">nil</code>, meaning just use the parent directory, or non-nil (typically <code class="language-plaintext highlighter-rouge">t</code> is used), which means to also include subdirectories.</li>
  <li><strong>org-html-preamble:</strong> this was important for me to set as <code class="language-plaintext highlighter-rouge">nil</code> to ensure that the exporter did not include a preamble, something that is included at the top of each file. While the preamble can be customized to suit your needs, I preferred not to mess with it and used a templating method instead (which I will go into later).</li>
</ul>

<p>Now that I had my <code class="language-plaintext highlighter-rouge">export.el</code> file configured the way I wanted it and some dummy posts and pages set up to see how it looked, I could go ahead and publish. To do so, I placed my cursor after the ending parenthesis on the first line of the file (<code class="language-plaintext highlighter-rouge">(require 'ox-publish)</code>), and pressed <code class="language-plaintext highlighter-rouge">C-x C-e</code><sup id="fnref:9"><a href="#fn:9" class="footnote" rel="footnote" role="doc-noteref">6</a></sup>. Then I navigated to the end of the file, after the last ending parenthesis on the last line, and pressed <code class="language-plaintext highlighter-rouge">C-x C-e</code> again. This will evaluate the emacs-lisp code in the file. After that, all I had to do to execute was to press <code class="language-plaintext highlighter-rouge">M-x org-publish-project</code> which would list all the components in the minibuffer. I could then navigate down to select “blog” and press the <code class="language-plaintext highlighter-rouge">return</code> key. Afterward, I could find the resulting exported files and folders in the <code class="language-plaintext highlighter-rouge">~/public_html/</code> directory.</p>

<h3 id="adding-style-and-usability">Adding style and usability</h3>

<p>So now that I knew how to export an entire static website via org-mode, the question was: <em>how do I get it to look how I want it to and behave how I need it to?</em> I had a list of problems I needed to solve to brainstorm ways to fix them:</p>

<ul>
  <li>Custom CSS stylesheet</li>
  <li>A tagging/category system for posts</li>
  <li>A custom header with custom links</li>
  <li>An index page that would contain my most recent posts</li>
  <li>A sitemap or archives page that would contain past entries</li>
</ul>

<p>So let’s talk about the solutions I’ve implemented so far.</p>

<h4 id="export-templates">Export templates</h4>

<p>While I already selected certain export options within <code class="language-plaintext highlighter-rouge">export.el</code>, I could also set options within specific files using properties dictating how the files would be exported<sup id="fnref:10"><a href="#fn:10" class="footnote" rel="footnote" role="doc-noteref">7</a></sup>. That meant I could create export templates that could then be associated with whatever files I wanted.</p>

<p>I created a new folder on the same level as <code class="language-plaintext highlighter-rouge">~/org/</code> and <code class="language-plaintext highlighter-rouge">~/public_html/</code> called <code class="language-plaintext highlighter-rouge">~/org-templates/</code> and added two files: <code class="language-plaintext highlighter-rouge">level-0.org</code> and <code class="language-plaintext highlighter-rouge">level-1.org</code>. This was the level-0 file:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>    #+options: html-link-use-abs-url:nil html-postamble:nil html-preamble:nil
    #+options: html-scripts:t html-style:nil html5-fancy:t tex:t
    #+options: tags:t title:nil toc:nil num:0 date:t
    #+html_doctype: html5
    #+html_container: div
    #+html_head: &lt;link rel="stylesheet" type="text/css" href="css/style.css" /&gt;
    #+creator: Megan Renae
</code></pre></div></div>

<p>The <code class="language-plaintext highlighter-rouge">level-1.org</code> is exactly the same except the stylesheet link goes back a directory, becoming <code class="language-plaintext highlighter-rouge">"../css/style.css"</code>.</p>

<p>Here are the important bits:</p>

<ul>
  <li>No, I don’t want the exporter to insert org’s own postambe and preamble</li>
  <li>No, I don’t want to use the default stylesheet</li>
  <li>Yes, export posts with tags (in the end, I didn’t need this at all, as I decided not to use tags, but the option remains)</li>
  <li>No, don’t export the <code class="language-plaintext highlighter-rouge">#+TITLE</code> property with the file (I add the title myself through headlines)</li>
  <li>Use the HTML5 doctype</li>
  <li>Use <code class="language-plaintext highlighter-rouge">div</code> as the primary container for content</li>
  <li>Insert my custom CSS stylesheet into the <code class="language-plaintext highlighter-rouge">head</code> of the document</li>
  <li>No, don’t insert a table of contents with each file</li>
  <li>No, don’t number sections on the file</li>
  <li>Yes, please export with the date</li>
</ul>

<p>I added the path to the template file at the top of each page with the #+SETUPFILE property:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>    #+SETUPFILE: ~/org-templates/level-1.org
</code></pre></div></div>

<h4 id="yasnippet">YASnippet</h4>

<p>Org-mode allows creation of special blocks that are written between lines that start with <code class="language-plaintext highlighter-rouge">#+BEGIN_XXXXX</code> and end with <code class="language-plaintext highlighter-rouge">#+END_XXXXX</code>. In particular, to include HTML code within an org-file, you can use the lines <code class="language-plaintext highlighter-rouge">#+BEGIN_EXPORT html</code> and <code class="language-plaintext highlighter-rouge">#+END_EXPORT</code>.</p>

<p>I created a snippet to use for blog posts, and after adding the <code class="language-plaintext highlighter-rouge">#+SETUPFILE</code>, I wrote a very simple code to ensure my blog header was added to each new post. My blog post snippet, then, begins like this:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>    #+SETUPFILE: ~/org-templates/level-1.org
    
    #+BEGIN_EXPORT html
    /code for my HTML header/
    #+END_EXPORT
</code></pre></div></div>

<p><strong>I could create custom fields so each post had defined properties</strong></p>

<p>Essentially, when beginning a new post, I was filling out a form, with each field providing more specific information about the post. There were five properties I felt were important to include:</p>

<ul>
  <li><code class="language-plaintext highlighter-rouge">#+TITLE</code> :: The title of the post, which was <em>mirrored</em><sup id="fnref:11"><a href="#fn:11" class="footnote" rel="footnote" role="doc-noteref">8</a></sup> in the first-level  headline of the content of the post.</li>
  <li><code class="language-plaintext highlighter-rouge">#+CATEGORY</code> :: The category of the post, which would then be mirrored in a custom link created at the bottom of the entry that would lead back to the category’s (though I used the word “tag”) index page, which would have a list of all entries under that tag.</li>
  <li><code class="language-plaintext highlighter-rouge">#+DATE</code> ::  Automatically updated with the date the template was first inserted into the file. This isn’t ideal, and I realize this would be better to instead be the date of publication. Hey, I never said this was perfect.</li>
  <li><code class="language-plaintext highlighter-rouge">#+FILENAME</code> :: This is just the name of the file without the =.org= extension, and it’s mirrors are used to create backlinks that will appear in the index page and the category page.</li>
  <li><code class="language-plaintext highlighter-rouge">#+EXCERPT</code> :: Generally, just the first paragraph of an entry. This is used to create the “preview” text that will appear in the index page.</li>
</ul>

<p>Here’s what this part looks like in practice:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>#+TITLE: ${1:title}
#+CATEGORY: ${2:category}
#+DATE: `(format-time-string "%F")`
#+FILENAME: ${3:filename} 
#+EXCERPT: ${4:excerpt}

=* $1=
**`(format-time-string "%A, %B %d, %Y")`**

$4
$0
=/Tagged: [[../tags/$2.org][$2]]/=
</code></pre></div></div>

<p>The fields are formatted as <code class="language-plaintext highlighter-rouge">${X:placeholder}</code>, with X being the number of the field, and “placeholder” being the text to be updated. Mirrors are given with <code class="language-plaintext highlighter-rouge">$X</code>. This also involves custom timestamps, and the values for the symbols used can be found in the <a href="https://www.gnu.org/software/emacs/manual/html_node/elisp/Time-Parsing.html">GNU Emacs manual</a>.</p>

<p><strong>I could create backlinks with headline entries that I could refile to a tag index and to a custom sitemap</strong></p>

<p>Notice that in the previous block I included a link at the end of the entry to a tag index which would then display all entries with the same category. Well, this is where that magic happens.</p>

<p>Now, <code class="language-plaintext highlighter-rouge">org-publish</code> does come with its own sitemap and index features, which have served plenty well on plenty of org-based websites. And I still may implement one or both of these features on this blog in the future. That said, I chose to use backlinking to create a poor-man’s indexing process.</p>

<p>The key here is the <code class="language-plaintext highlighter-rouge">org-refile</code><sup id="fnref:12"><a href="#fn:12" class="footnote" rel="footnote" role="doc-noteref">9</a></sup> function, and that requires the pages that I’m using to be refiling targets to be included in the  <code class="language-plaintext highlighter-rouge">org-refile-targets</code> variable, which I ended up defining in my personal configuration file. For purposes of this site, the setup is something like this:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>(setq org-refile-targets '(org-agenda-files . (:maxlevel . 9)))
(setq org-reverse-note-order t)
</code></pre></div></div>

<p>I’ve turned on <code class="language-plaintext highlighter-rouge">org-reverse-note-order</code> so that newer entries would appear at the top of the indices. I can add any file to <code class="language-plaintext highlighter-rouge">org-agenda-files</code> by visiting it and pressing <code class="language-plaintext highlighter-rouge">C-c [</code>. With this configuration any headline within an agenda file (up to the 9th level) is a refile target. This leads me to the last section of my blog post snippet:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>=* [[../posts/$3.org][$1]]=
`(format-time-string "%D %a")` ;; this is the refile headline in the tag indexing

=* [[./posts/$3.org][$1]]= || `(format-time-string "%D %a")`
/[[./tags/$2.org][$2]]/
$4
[[./posts/$3.org][Read more...]] :: this is refiled to the sitemap
</code></pre></div></div>

<p>This creates more mirrors from the fields that were defined earlier in the snippet. Now I just need to run the command <code class="language-plaintext highlighter-rouge">org-refile</code>, select the correct target, and these headlines will be placed in their correct place.</p>

<p>One problem, though… where is that?</p>

<h4 id="refining-the-structure">Refining the structure</h4>

<p>Let’s go back to the very beginning, when I created an <code class="language-plaintext highlighter-rouge">index.org</code> file, the first file of my <code class="language-plaintext highlighter-rouge">org-publish</code> project. It’s time to finalize that page by giving it our sitemap. To do this, I create a new file under <code class="language-plaintext highlighter-rouge">~/org/</code>, <code class="language-plaintext highlighter-rouge">sitemap.org</code>, which I add as an agenda file.  This is the file that I will end up using to create the list of posts in anti-chronological order that will appear in my <code class="language-plaintext highlighter-rouge">index.org</code> page.</p>

<p>To start, <code class="language-plaintext highlighter-rouge">sitemap.org</code> will have a single first-level headline, “Latest Posts”. Then I will refile the headline created with my blog post snippet to the sitemap file, and it will show up as the first entry. Now I go back to <code class="language-plaintext highlighter-rouge">index.org</code> so I can include the latest posts from <code class="language-plaintext highlighter-rouge">sitemap.org</code> on my blog’s front page. To do this, I can use the <code class="language-plaintext highlighter-rouge">#+INCLUDE</code> property, like this:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>=#+INCLUDE: "~/org/sitemap.org"=
</code></pre></div></div>

<p>That’s a good start, but since the sitemap is going to house ALL files from the blog’s history, I don’t want to include the <em>entire</em> sitemap in my index page. Luckily, there’s a way to limit what lines will be included.</p>

<p>Let’s look back at the entry we’ve refiled to <code class="language-plaintext highlighter-rouge">sitemap.org</code>:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>=* [[./posts/post.org][Post Title[]]= || XXXX-XX-XX XXX
/[[./tags/tag.org][category]]/
POST EXCERPT
[[./posts/post.org][Read more...]]
</code></pre></div></div>

<p>Since Emacs doesn’t automatically create new lines, I know that each entry in <code class="language-plaintext highlighter-rouge">sitemap.org</code> will be exactly 4 lines. The actual sitemap will begin on line 2, after the “Latest Posts” headline. Say I want to include the last five posts in my index page; all I need to do is calculate how many lines that would be.</p>

<p>In this case, 5 posts would be 20 lines. Since we’re starting on line 2, we know the last line we’ll need to use is line 21. However, when we include line numbers in the <code class="language-plaintext highlighter-rouge">#+INCLUDE</code> line, the last line given is excluded, so we’ll need to add one more to ensure the last post doesn’t get cut off early.</p>

<p>This is what we end up with:</p>

<p><code class="language-plaintext highlighter-rouge">#+INCLUDE: "~/org/sitemap.org" :lines "2-22"</code></p>

<p>Now, there’s one more thing: individual pages for each category or tag. I’ve already laid the groundwork with out snippet and the post, at the very end, contains a link to the category page under a new subdirectory I’ve created: <code class="language-plaintext highlighter-rouge">~/org/tags/</code>. I can click that link when I’m done writing my post, and it will take me to a new buffer containing the category/tag index page. If it’s a new category, and therefore no page has been created yet, it will create a new buffer with a completely blank file and all I need to do is insert a headline (<code class="language-plaintext highlighter-rouge">* TAG: CategoryName</code>), press <code class="language-plaintext highlighter-rouge">C-x C-s</code>, and just like that the file is created. By pressing <code class="language-plaintext highlighter-rouge">C-c [</code>, the new file is added as an agenda file. Then, I can refile the corresponding headline to add a new entry to the tag page.</p>

<h3 id="final-touches">Final touches</h3>

<p>Now that I have built the framework I need for this to work correctly, there are only a couple of things left before going live. The obvious one is to create an About page, which is self-explanatory, along with an Archives page for past entries (for which I use the same re-filing method I explained above with tags), and a Caategories Page to link to all of the individual category indices.</p>

<p>No, this isn’t exactly finished. I’ll be continuously working on this blog, whether that means to add something else, or to change things around, just to keep it in sync with my org learning curve, as well as my changing tastes and needs. I’d still like to implement an Archives page. I know that using ya-snippet in the way that I have can provide some difficulties when it comes to retroactive changes, so I’m trying to isolate individual elements in separate files to make implementing changes easier. I’m also using <a href="https://magit.vc/">Magit</a> for version control.</p>

<p>In short, this is a work in progress - just like me.</p>

<h3 id="footnotes">Footnotes</h3>

<div class="footnotes" role="doc-endnotes">
  <ol>
    <li id="fn:4">
      <p>Explaining Org-mode succinctly is even more of a lost cause than Emacs, so just <a href="https://orgmode.org/">go here</a> if you’re curious. <a href="#fnref:4" class="reversefootnote" role="doc-backlink">&#8617;</a></p>
    </li>
    <li id="fn:5">
      <p>software in software in software <a href="#fnref:5" class="reversefootnote" role="doc-backlink">&#8617;</a></p>
    </li>
    <li id="fn:6">
      <p>a static site is basically a website built from HTML files, as opposed to a dynamic site where a webpage is built on the server pulling resources from several different locations. On a static site blog, when you click on a link to a post or page, you’re served a page that has already been built in the file system. On a dynamic blog (built with Wordpress, for example), each request builds a page from scratch based on current site data and content. Confused? <a href="https://learn.cloudcannon.com/jekyll/why-use-a-static-site-generator/">This may do a better job of explaining</a> <a href="#fnref:6" class="reversefootnote" role="doc-backlink">&#8617;</a></p>
    </li>
    <li id="fn:7">
      <p>Don’t get me wrong, I think these packages look awesome. <a href="https://orgmode.org/worg/org-blog-wiki.html">Here’s a pretty good list.</a>. Please don’t think I won’t take advantage of these in the future - I’m sure I will. They just weren’t right for <em>this</em> project. <a href="#fnref:7" class="reversefootnote" role="doc-backlink">&#8617;</a></p>
    </li>
    <li id="fn:8">
      <p>A little caveat here: I ended up setting this to recursive, which means all files are technically included in this component, which could cause an issue as the files in the <code class="language-plaintext highlighter-rouge">/posts/</code> directory are included in <code class="language-plaintext highlighter-rouge">blog-posts</code>. This hasn’t caused an issue for me yet, and my main decision for doing so would be to include the <code class="language-plaintext highlighter-rouge">/tags/</code> directory. However, looking at this now I realize it would make more sense to add <code class="language-plaintext highlighter-rouge">blog-tags</code> as a separate component. <a href="#fnref:8" class="reversefootnote" role="doc-backlink">&#8617;</a></p>
    </li>
    <li id="fn:9">
      <p>Remember emacs using the control and meta keys, and these are shorted to “C” and “M” when written out. When used with a hyphen and then another letter, this would mean to press the command key (control or meta) and the corresponding letter at the same time. In this example, <code class="language-plaintext highlighter-rouge">C-x C-e</code> means to press the Control key at the same time as “x”, let go, then press the Control key again, at the same time as “e” on the keyboard. <a href="#fnref:9" class="reversefootnote" role="doc-backlink">&#8617;</a></p>
    </li>
    <li id="fn:10">
      <p>As always, for more information, check out the <a href="https://orgmode.org/org.html#Export-Settings">org manual</a>. <a href="#fnref:10" class="reversefootnote" role="doc-backlink">&#8617;</a></p>
    </li>
    <li id="fn:11">
      <p>In ya-snippets, <em>mirrors</em> can be placed anywhere in the template, and they are updated with the value of their primary field. <a href="#fnref:11" class="reversefootnote" role="doc-backlink">&#8617;</a></p>
    </li>
    <li id="fn:12">
      <p>Org-refile is more of an organization thing, and less of a publication thing, and I’ve just manipulated its use here for my purposes. However, to know more about how it’s <em>supposed</em> to be used, again, <a href="https://orgmode.org/manual/Refile-and-Copy.html#Refile-and-copy">check out the org manual</a>. <a href="#fnref:12" class="reversefootnote" role="doc-backlink">&#8617;</a></p>
    </li>
  </ol>
</div>]]></content><author><name>Megan Renae</name></author><category term="orgmode" /><category term="emacs" /><category term="webdev" /><summary type="html"><![CDATA[There’s always something new to discover with Emacs and org-mode, and building a blog was my way of wading into deeper waters - no longer content to just get my feet wet.]]></summary></entry></feed>