Skip to content

Instantly share code, notes, and snippets.

@kliph
Created September 26, 2013 02:12
Show Gist options
  • Save kliph/6708917 to your computer and use it in GitHub Desktop.
Save kliph/6708917 to your computer and use it in GitHub Desktop.
The raw .org source for a blog post on links with the o-blog blog generator.
* DONE Links with o-blog :o@blog:org@mode:emacs:
CLOSED: [2013-09-25 Wed 20:13]
Links are easily embedded into [[http://orgmode.org/][org-mode]] documents. Simply type =C-c
C-l= and enter =http://linkblah.com= at the prompt. Org-mode supports
a variety of [[http://orgmode.org/manual/External-links.html][link prefix types]].
[[https://github.com/renard/o-blog][O-blog]] is slightly more complicated.
You can follow along by reading the raw =.org= source in this gist.
** Adding links to o-blog documents
Since publication using o-blog dynamically generates your website, it
can be tedious to add and update links every time you publish.
** O-blog lisp tags
The o-blog generator recognizes =<lisp></lisp>= tags in html templates
and the same tags with *angle brackets* replaced by *curly* *brackets*
in =.org= files.
All of the example links shown below have to be surrounded
by *curly* *bracket* lisp tags to function properly. I use *angle
brackets* in the examples below because they would otherwise translate
the code into actual links when this blog entry is published.
** O-blog links to static pages
A typical link to a static page, such as this blogs Archives page, is
formatted like this:
=file:<lisp>(ob:path-to-root)</lisp>/archives.html=
This code is translated upon publication to:
=file:{lisp}(ob:path-to-root){/lisp}/archives.html=
** O-blog links to dynamically generated pages
Here I'll show an example link to the previous post. The previous
post is subject to change, for example upon deletion or backdating
entries.
#+BEGIN_SRC org
file:<lisp>(format "%s/%s" (ob:path-to-root) (ob:post-htmlfile (ob:get-last-post "Blog" (1+ (ob:post-id POST)))))</lisp>
#+END_SRC
This code is translated upon publication to:
=file:{lisp}(format "%s/%s" (ob:path-to-root) (ob:post-htmlfile (ob:get-last-post "Blog" (1+ (ob:post-id POST))))){/lisp}=
Let's unpack what this function does starting with the innermost
expression. =(ob:post-id)= takes the variable =POST=, which is always
available when publishing with o-blog, and returns the =ID= number of
the current blog post. These numbers are in reverse chronological
order. The most recent post has the =ID: 0=. So adding 1 to that
number via the =(1+)= function returns the =ID= of the previous post.
The function =(ob:get-last-post)= returns a handle to the post
previous post by passing in arguments for its =CATEGORY= and =ID=.
The =(ob:post-htmlfile)= returns the path to the html file of the
previous post and =(ob:path-to-root)= returns the path to the blog
root directory.
Finally, the =(format)= command concatenates the two paths separated
by a =/=.
You can read more about the structures and variables available to
spice up the lisp tags in your blog at the [[http://renard.github.io/o-blog/structures.html][structures description on
the o-blog wesbite]].
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment