emacs-love / weblorg

Static Site Generator for Emacs
https://emacs.love/weblorg
GNU General Public License v3.0
278 stars 20 forks source link

As blogger I want to create posts from org files, so that I can publish on my blog. #2

Closed guilhermecomum closed 3 years ago

clarete commented 3 years ago

Once again, thank you for structuring a plan of action with these stories! :D Really appreciate your interest and help, dear @guilhermecomum! 🙇

This issue is a great opportunity to document how each Org-Mode document becomes an HTML file.

When blorg-cli is called with an:input-pattern that yields a list of Org-Mode files, each file will be parsed and a variable post will be created and exposed within the template. E.g.:

Let's say you have a structure similar to the one I described in #1. And let's say you have an Org-Mode file with the following contents:

The Org-Mode file

#+TITLE: My first little post
#+DATE: <2020-04-26>
#+FILETAGS: :blogging:org-mode:

This is the content of my cool post. We can use *bold* or /italics/ or ~pre-formatted~ or really any other
features, eve code blocks:

#+BEGIN_SRC emacs-lisp
(message "%s" (emacs-version))
#+END_SRC

Processing

During the parsing of the above document, all the file level properties (in this case, title, date and filetags) are collected and made available to the template via the post variable. There are currently three other properties that get inserted in the post object: 1. file name, 2. html with the rendered HTML and 3. slug which is a string that identifies the post and can be used as part of the post URL and is derived from either the post's title or from its file name. In the end of the day, all these variables are made available to the template and can be used in the following way:

The template

  <section class="post">
    <header>
      <h1>{{ post.title }}</h1>
      <div>{{ post.date }}</div>
    </header>
    <div id="content">
      {{ post.html }}
    </div>
  </section>

It's worth also noting that the :output parameter of the blog-cli function has access to all the post variables. And that's probably where the slug property of the post becomes useful in the first place.