<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: meganrenae21</title>
    <description>The latest articles on DEV Community by meganrenae21 (@meganrenae21).</description>
    <link>https://dev.to/meganrenae21</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F456828%2F8e5f1e3e-7178-4cc6-931a-e909d1b2b3f9.png</url>
      <title>DEV Community: meganrenae21</title>
      <link>https://dev.to/meganrenae21</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/meganrenae21"/>
    <language>en</language>
    <item>
      <title>How I built a simple static blog with org-mode</title>
      <dc:creator>meganrenae21</dc:creator>
      <pubDate>Sat, 22 Aug 2020 21:20:31 +0000</pubDate>
      <link>https://dev.to/meganrenae21/how-i-built-a-simple-static-blog-with-org-mode-4b4l</link>
      <guid>https://dev.to/meganrenae21/how-i-built-a-simple-static-blog-with-org-mode-4b4l</guid>
      <description>&lt;p&gt;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. &lt;/p&gt;

&lt;p&gt;For the uninitiated, Emacs is a highly extendable and configurable free and open source text editor that has been around since, like, since the dinosaurs or something, I don't know. The history isn't all that interesting&lt;sup&gt;1&lt;/sup&gt; and also it doesn't lend itself to a good succinct explanation. Basically: it's a software that writes text-based files and allows you to generate all manner of stuff, plus you can install extension packages&lt;sup&gt;2&lt;/sup&gt; where you can do even more stuff. All this "stuff" you can comes from setting configuration files, written in emacs-lisp code, where you tell the software how to behave, and from keyboard commands bound to the "control" and "meta"&lt;sup&gt;3&lt;/sup&gt; keys that will execute when called. &lt;/p&gt;

&lt;p&gt;And then there's org-mode&lt;sup&gt;4&lt;/sup&gt;, and all of its customization options and packages&lt;sup&gt;5&lt;/sup&gt;, and after playing around a bit I asked myself: &lt;em&gt;is there anything I can't do from here?&lt;/em&gt; 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 &lt;em&gt;written in org-mode&lt;/em&gt;. 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. &lt;/p&gt;

&lt;p&gt;That's how I became obsessed. &lt;/p&gt;

&lt;p&gt;What follows is an abridged step-by-step summary of my process in creating a very basic framework for a static&lt;sup&gt;6&lt;/sup&gt; site blogging framework, which I am using for this blog. &lt;/p&gt;

&lt;h2&gt;
  
  
  Starting point and goals
&lt;/h2&gt;

&lt;p&gt;I use &lt;a href="https://www.spacemacs.org/"&gt;Spacemacs&lt;/a&gt;, 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 &lt;em&gt;couldn't&lt;/em&gt; be done. &lt;/p&gt;

&lt;p&gt;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:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  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&lt;sup&gt;7&lt;/sup&gt;.&lt;/li&gt;
&lt;li&gt;  I would build a framework that took advantage of org-mode functions while also allowing myself to &lt;em&gt;not&lt;/em&gt; use methods that existed if they didn't suit my needs.&lt;/li&gt;
&lt;li&gt;  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.&lt;/li&gt;
&lt;li&gt;  It didn't have to be perfect or do &lt;em&gt;every little thing&lt;/em&gt; I'd like to be "live"; this was a project that could be continuously in development, with features/functionality added as I learned more.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I'm going to reiterate here, *&lt;strong&gt;&lt;em&gt;I'm a complete newbie&lt;/em&gt;&lt;/strong&gt;&lt;em&gt;. 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 *so far&lt;/em&gt;. 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. &lt;/p&gt;

&lt;h2&gt;
  
  
  Initial file framework
&lt;/h2&gt;

&lt;p&gt;The best resource I found at the beginning of this endeavor was an &lt;a href="https://orgmode.org/worg/org-tutorials/org-publish-html-tutorial.html"&gt;org-publish tutorial&lt;/a&gt; on &lt;a href="https://orgmode.org/worg/index.html"&gt;Worg&lt;/a&gt;, an 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.&lt;/p&gt;

&lt;p&gt;Using this tutorial as a guide, I created two folders within my main project folder: &lt;code&gt;~/org/&lt;/code&gt; and  &lt;code&gt;~/public_html/&lt;/code&gt;. The idea is that my input would be under the  &lt;code&gt;~/org/&lt;/code&gt; directory, and whatever was in that directory would be exported to html and published in the &lt;code&gt;~/public_html/&lt;/code&gt; directory. &lt;/p&gt;

&lt;p&gt;After that, I left the &lt;code&gt;~/public_html/&lt;/code&gt; 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. &lt;/p&gt;

&lt;p&gt;Additionally, since &lt;em&gt;anything&lt;/em&gt; in the &lt;code&gt;~/org/&lt;/code&gt; directory would be exported (unless I specifically configured a certain file or headline not to be exported), it wasn't restricted to simply &lt;em&gt;org&lt;/em&gt; files. Simply put, any file at all that I wanted to eventually wind up in &lt;code&gt;~/public_html/&lt;/code&gt; would be placed within &lt;code&gt;~/org/&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;First, I created &lt;code&gt;index.org&lt;/code&gt; within &lt;code&gt;~/org/&lt;/code&gt; and then I created several folders (subdirectories) that would eventually carry files of their own. This was my initial file organization for this blog:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;~/org/
   |- index.org
   |- css/
   |  `style.css
   |- img/
   |- posts/
~/public_html/
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;With this setup, &lt;code&gt;index.org&lt;/code&gt; would become &lt;code&gt;index.html&lt;/code&gt; under the &lt;code&gt;~/public_html/&lt;/code&gt; directory. Additionally, &lt;code&gt;~/org/css/style.css&lt;/code&gt; would be exported to &lt;code&gt;~/public_html/css/style.css&lt;/code&gt; so I could apply a consistent style to exported HTML files. The &lt;code&gt;img/&lt;/code&gt; directory would carry images and other attachments, while all posts would go into the &lt;code&gt;posts/&lt;/code&gt; folder for export. &lt;/p&gt;

&lt;p&gt;Note, that if, in editing an org file within the &lt;code&gt;~/org/&lt;/code&gt; directory, if I were to link to another org file within &lt;code&gt;~/org/&lt;/code&gt;, the exporter would then transform that link into a link to the corresponding file in &lt;code&gt;~/public_html/&lt;/code&gt;. Likewise, by applying &lt;code&gt;/css/style.css&lt;/code&gt; to &lt;code&gt;index.org&lt;/code&gt;, the &lt;code&gt;~/public_html/index.html&lt;/code&gt; file resulting from the export would be loaded with a stylesheet in &lt;code&gt;~/public_html/css/style.css&lt;/code&gt;. &lt;/p&gt;

&lt;h2&gt;
  
  
  The "export.el" file
&lt;/h2&gt;

&lt;p&gt;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, &lt;code&gt;~/export.el&lt;/code&gt;, which I placed in my &lt;em&gt;main project directory&lt;/em&gt; (even with, and not under, &lt;code&gt;~/public_html/&lt;/code&gt; and &lt;code&gt;~/org/&lt;/code&gt;). &lt;/p&gt;

&lt;p&gt;The first line is &lt;code&gt;(require 'ox-publish)&lt;/code&gt; which I use to ensure that emacs loads the ox-publish library when publication is triggered. After that I set the variable &lt;code&gt;org-publish-project-alist&lt;/code&gt; to define my project scope. &lt;/p&gt;

&lt;p&gt;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:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(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"))
)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Now, I have several other options set up in &lt;code&gt;export.el&lt;/code&gt; 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.&lt;/p&gt;

&lt;h3&gt;
  
  
  Components
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;blog-posts:&lt;/strong&gt; 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.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;blog-pages:&lt;/strong&gt; so here we're going with every org file within the &lt;code&gt;~/org/&lt;/code&gt; directory&lt;sup&gt;8&lt;/sup&gt;.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;blog-static:&lt;/strong&gt; for all files included in the &lt;code&gt;~/org/&lt;/code&gt; directory that &lt;em&gt;aren't&lt;/em&gt; org files, and should keep their native extension upon export.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;blog:&lt;/strong&gt; this gives us all these separate components, and puts them together into one project.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Options
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;base-directory:&lt;/strong&gt; this is the directory where the files are coming &lt;em&gt;from&lt;/em&gt; - in this case &lt;code&gt;~/org/&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;publishing-directory:&lt;/strong&gt; the directory where the files are going to be published &lt;em&gt;to&lt;/em&gt; - &lt;code&gt;~/public_html/&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;base-extension:&lt;/strong&gt; tells the exporter to export files with this(these) extensions. For pages and posts, the files exported will end in &lt;code&gt;.org&lt;/code&gt;, but for the static files, the base extension has multiple possibilities.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;publishing-function:&lt;/strong&gt; 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 &lt;code&gt;blog-posts&lt;/code&gt; and &lt;code&gt;blog-pages&lt;/code&gt; with &lt;code&gt;org-html-publish-to-html&lt;/code&gt;. Meanwhile, anything in the &lt;code&gt;~/org/&lt;/code&gt; directory that doesn't end in &lt;code&gt;.org&lt;/code&gt; (&lt;code&gt;blog-static&lt;/code&gt;) should just be copies into the desination folder using &lt;code&gt;org-publish-attachment&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;recursive:&lt;/strong&gt; tells the exporter whether to include files from subdirectories recursively, or just from the parent directory. This has two possible options: &lt;code&gt;nil&lt;/code&gt;, meaning just use the parent directory, or non-nil (typically &lt;code&gt;t&lt;/code&gt; is used), which means to also include subdirectories.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;org-html-preamble:&lt;/strong&gt; this was important for me to set as &lt;code&gt;nil&lt;/code&gt; 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).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now that I had my &lt;code&gt;export.el&lt;/code&gt; 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 (&lt;code&gt;(require 'ox-publish)&lt;/code&gt;), and pressed &lt;code&gt;C-x C-e&lt;/code&gt;&lt;sup&gt;9&lt;/sup&gt;. Then I navigated to the end of the file, after the last ending parenthesis on the last line, and pressed &lt;code&gt;C-x C-e&lt;/code&gt; again. This will evaluate the emacs-lisp code in the file. After that, all I had to do to execute was to press &lt;code&gt;M-x org-publish-project&lt;/code&gt; which would list all the components in the minibuffer. I could then navigate down to select "blog" and press the &lt;code&gt;return&lt;/code&gt; key. Afterward, I could find the resulting exported files and folders in the &lt;code&gt;~/public_html/&lt;/code&gt; directory. &lt;/p&gt;

&lt;h2&gt;
  
  
  Adding style and usability
&lt;/h2&gt;

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

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

&lt;p&gt;So let's talk about the solutions I've implemented so far. &lt;/p&gt;

&lt;h3&gt;
  
  
  Export templates
&lt;/h3&gt;

&lt;p&gt;While I already selected certain export options within &lt;code&gt;export.el&lt;/code&gt;, I could also set options within specific files using properties dictating how the files would be exported&lt;sup&gt;10&lt;/sup&gt;. That meant I could create export templates that could then be associated with whatever files I wanted. &lt;/p&gt;

&lt;p&gt;I created a new folder on the same level as &lt;code&gt;~/org/&lt;/code&gt; and &lt;code&gt;~/public_html/&lt;/code&gt; called &lt;code&gt;~/org-templates/&lt;/code&gt; and added two files: &lt;code&gt;level-0.org&lt;/code&gt; and &lt;code&gt;level-1.org&lt;/code&gt;. This was the level-0 file:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#+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: &amp;lt;link rel="stylesheet" type="text/css" href="css/style.css" /&amp;gt;
#+creator: Megan Renae
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;The &lt;code&gt;level-1.org&lt;/code&gt; is exactly the same except the stylesheet link goes back a directory, becoming &lt;code&gt;"../css/style.css"&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;Here are the important bits:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  No, I don't want the exporter to insert org's own postambe and preamble&lt;/li&gt;
&lt;li&gt;  No, I don't want to use the default stylesheet&lt;/li&gt;
&lt;li&gt;  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)&lt;/li&gt;
&lt;li&gt;  No, don't export the &lt;code&gt;#+TITLE&lt;/code&gt; property with the file (I add the title myself through headlines)&lt;/li&gt;
&lt;li&gt;  Use the HTML5 doctype&lt;/li&gt;
&lt;li&gt;  Use &lt;code&gt;div&lt;/code&gt; as the primary container for content&lt;/li&gt;
&lt;li&gt;  Insert my custom CSS stylesheet into the &lt;code&gt;head&lt;/code&gt; of the document&lt;/li&gt;
&lt;li&gt;  No, don't insert a table of contents with each file&lt;/li&gt;
&lt;li&gt;  No, don't number sections on the file&lt;/li&gt;
&lt;li&gt;  Yes, please export with the date&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I added the path to the template file at the top of each page with the #+SETUPFILE property:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#+SETUPFILE: ~/org-templates/level-1.org
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3&gt;
  
  
  YASnippet
&lt;/h3&gt;

&lt;p&gt;So, here's my secret weapon. I learned to create snippets (at least in their basic form, and perhaps not how they were meant to be used) that would give me a skeleton for each post, which could then easily be dressed up for a clean export. &lt;a href="http://joaotavora.github.io/yasnippet/"&gt;YASnippet&lt;/a&gt; provided the answer for about 75% of my problems. How? Well:&lt;/p&gt;

&lt;p&gt;*&lt;strong&gt;&lt;em&gt;I could export my own custom HTML header using an export block&lt;/em&gt;&lt;/strong&gt;*&lt;/p&gt;

&lt;p&gt;Org-mode allows creation of special blocks that are written between lines that start with &lt;code&gt;#+BEGIN_XXXXX&lt;/code&gt; and end with &lt;code&gt;#+END_XXXXX&lt;/code&gt;. In particular, to include HTML code within an org-file, you can use the lines &lt;code&gt;#+BEGIN_EXPORT html&lt;/code&gt; and &lt;code&gt;#+END_EXPORT&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;I created a snippet to use for blog posts, and after adding the &lt;code&gt;#+SETUPFILE&lt;/code&gt;, 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:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#+SETUPFILE: ~/org-templates/level-1.org

#+BEGIN_EXPORT html
/code for my HTML header/
#+END_EXPORT
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;*&lt;strong&gt;&lt;em&gt;I could create custom fields so each post had defined properties&lt;/em&gt;&lt;/strong&gt;*&lt;/p&gt;

&lt;p&gt;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:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;&lt;code&gt;#+TITLE&lt;/code&gt;:&lt;/strong&gt; The title of the post, which was &lt;em&gt;mirrored&lt;/em&gt;&lt;sup&gt;11&lt;/sup&gt; in the first-level  headline of the content of the post.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;&lt;code&gt;#+CATEGORY&lt;/code&gt;:&lt;/strong&gt; 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.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;&lt;code&gt;#+DATE&lt;/code&gt;:&lt;/strong&gt; 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.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;&lt;code&gt;#+FILENAME&lt;/code&gt;:&lt;/strong&gt; This is just the name of the file without the &lt;code&gt;.org&lt;/code&gt; extension, and it's mirrors are used to create backlinks that will appear in the index page and the category page.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;&lt;code&gt;#+EXCERPT&lt;/code&gt;:&lt;/strong&gt; Generally, just the first paragraph of an entry. This is used to create the "preview" text that will appear in the index page.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here's what this part looks like in practice:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#+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]]/=
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

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

&lt;p&gt;*&lt;strong&gt;&lt;em&gt;I could create backlinks with headline entries that I could refile to a tag index and to a custom sitemap&lt;/em&gt;&lt;/strong&gt;*&lt;/p&gt;

&lt;p&gt;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. &lt;/p&gt;

&lt;p&gt;Now, &lt;code&gt;org-publish&lt;/code&gt; 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. &lt;/p&gt;

&lt;p&gt;The key here is the &lt;code&gt;org-refile&lt;/code&gt;&lt;sup&gt;12&lt;/sup&gt; function, and that requires the pages that I'm using to be refiling targets to be included in the  &lt;code&gt;org-refile-targets&lt;/code&gt; variable, which I ended up defining in my personal configuration file. For purposes of this site, the setup is something like this:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(setq org-refile-targets '(org-agenda-files . (:maxlevel . 9)))
(setq org-reverse-note-order t)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;I've turned on &lt;code&gt;org-reverse-note-order&lt;/code&gt; so that newer entries would appear at the top of the indices. I can add any file to &lt;code&gt;org-agenda-files&lt;/code&gt; by visiting it and pressing &lt;code&gt;C-c [&lt;/code&gt;. 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:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;=* [[../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
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;This creates more mirrors from the fields that were defined earlier in the snippet. Now I just need to run the command &lt;code&gt;org-refile&lt;/code&gt;, select the correct target, and these headlines will be placed in their correct place.&lt;/p&gt;

&lt;p&gt;One problem, though… where is that?&lt;/p&gt;

&lt;h3&gt;
  
  
  Refining the structure
&lt;/h3&gt;

&lt;p&gt;Let's go back to the very beginning, when I created an &lt;code&gt;index.org&lt;/code&gt; file, the first file of my &lt;code&gt;org-publish&lt;/code&gt; project. It's time to finalize that page by giving it our sitemap. To do this, I create a new file under &lt;code&gt;~/org/&lt;/code&gt;, &lt;code&gt;sitemap.org&lt;/code&gt;, 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 &lt;code&gt;index.org&lt;/code&gt; page.&lt;/p&gt;

&lt;p&gt;To start, &lt;code&gt;sitemap.org&lt;/code&gt; 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 &lt;code&gt;index.org&lt;/code&gt; so I can include the latest posts from &lt;code&gt;sitemap.org&lt;/code&gt; on my blog's front page. To do this, I can use the &lt;code&gt;#+INCLUDE&lt;/code&gt; property, like this:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;#+INCLUDE: "~/org/sitemap.org"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;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 &lt;em&gt;entire&lt;/em&gt; sitemap in my index page. Luckily, there's a way to limit what lines will be included. &lt;/p&gt;

&lt;p&gt;Let's look back at the entry we've refiled to &lt;code&gt;sitemap.org&lt;/code&gt;:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;=* [[./posts/post.org][Post Title]= || XXXX-XX-XX XXX
/[[./tags/tag.org][category]]/
POST EXCERPT
[[./posts/post.org][Read more...]]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Since Emacs doesn't automatically create new lines, I know that each entry in &lt;code&gt;sitemap.org&lt;/code&gt; 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. &lt;/p&gt;

&lt;p&gt;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 &lt;code&gt;#+INCLUDE&lt;/code&gt; 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. &lt;/p&gt;

&lt;p&gt;This is what we end up with:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;#+INCLUDE: "~/org/sitemap.org" :lines "2-22"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;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: &lt;code&gt;~/org/tags/&lt;/code&gt;. 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 (&lt;code&gt;* TAG: CategoryName&lt;/code&gt;), press &lt;code&gt;C-x C-s&lt;/code&gt;, and just like that the file is created. By pressing &lt;code&gt;C-c [&lt;/code&gt;, 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. &lt;/p&gt;

&lt;h2&gt;
  
  
  Final touches
&lt;/h2&gt;

&lt;p&gt;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 &lt;a href="//../about.md"&gt;About Page&lt;/a&gt;, which is self-explanatory, along with an &lt;a href="//../archives.md"&gt;Archives&lt;/a&gt; page for past entries (for which I use the same re-filing method I explained above with tags), and a &lt;a href="//../categories.md"&gt;Categories Page&lt;/a&gt; to link to all of the individual category indices.&lt;/p&gt;

&lt;p&gt;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 &lt;a href="https://magit.vc/"&gt;Magit&lt;/a&gt; for version control. &lt;/p&gt;

&lt;p&gt;In short, this is a work in progress - just like me.&lt;/p&gt;

&lt;h1&gt;
  
  
  Footnotes
&lt;/h1&gt;

&lt;p&gt;&lt;sup&gt;1&lt;/sup&gt; but I guess if you wanted to go down that rabbit hole, you would be able to to access a wealth of information from &lt;a href="https://www.gnu.org/software/emacs/"&gt;the home page of GNU Emacs&lt;/a&gt;. Like, a lot a lot.&lt;/p&gt;

&lt;p&gt;&lt;sup&gt;2&lt;/sup&gt; *&lt;strong&gt;&lt;em&gt;extension&lt;/em&gt;&lt;/strong&gt;* - basically software in software.&lt;/p&gt;

&lt;p&gt;&lt;sup&gt;3&lt;/sup&gt; generally, the meta key is the alt or option key on Windows or Mac computers.&lt;/p&gt;

&lt;p&gt;&lt;sup&gt;4&lt;/sup&gt; Explaining Org-mode succinctly is even more of a lost cause than Emacs, so just &lt;a href="https://orgmode.org/"&gt;go here&lt;/a&gt; if you're curious.&lt;/p&gt;

&lt;p&gt;&lt;sup&gt;5&lt;/sup&gt; software in software in software&lt;/p&gt;

&lt;p&gt;&lt;sup&gt;6&lt;/sup&gt; 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? &lt;a href="https://learn.cloudcannon.com/jekyll/why-use-a-static-site-generator/"&gt;This may do a better job of explaining.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;sup&gt;7&lt;/sup&gt; Don't get me wrong, I think these packages look awesome. &lt;a href="https://orgmode.org/worg/org-blog-wiki.html"&gt;Here's a pretty good list&lt;/a&gt;. 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 &lt;em&gt;this&lt;/em&gt; project.&lt;/p&gt;

&lt;p&gt;&lt;sup&gt;8&lt;/sup&gt; 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 &lt;code&gt;/posts/&lt;/code&gt; directory are included in &lt;code&gt;blog-posts&lt;/code&gt;. This hasn't caused an issue for me yet, and my main decision for doing so would be to include the &lt;code&gt;/tags/&lt;/code&gt; directory. However, looking at this now I realize it would make more sense to add &lt;code&gt;blog-tags&lt;/code&gt; as a separate component.&lt;/p&gt;

&lt;p&gt;&lt;sup&gt;9&lt;/sup&gt; 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, &lt;code&gt;C-x C-e&lt;/code&gt; 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.&lt;/p&gt;

&lt;p&gt;&lt;sup&gt;10&lt;/sup&gt; As always, for more information, check out the &lt;a href="https://orgmode.org/org.html#Export-Settings"&gt;org manual&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;sup&gt;11&lt;/sup&gt; In ya-snippets, &lt;em&gt;mirrors&lt;/em&gt; can be placed anywhere in the template, and they are updated with the value of their primary field.&lt;/p&gt;

&lt;p&gt;&lt;sup&gt;12&lt;/sup&gt; 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 &lt;em&gt;supposed&lt;/em&gt; to be used, again, &lt;a href="https://orgmode.org/manual/Refile-and-Copy.html#Refile-and-copy"&gt;check out the org manual&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>orgmode</category>
      <category>emacs</category>
      <category>html</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
