Browse files

Added support for meta tags coming from the generated html of output …

…creators like markdown or org mode
  • Loading branch information...
1 parent e8844e6 commit 85bdc9da2b0743381e59b0824f98e248992ab604 @terhechte committed Sep 3, 2015
Showing with 32 additions and 4 deletions.
  1. +14 −0
  2. +2 −1 src/static/core.clj
  3. +16 −3 src/static/io.clj
@@ -130,6 +130,8 @@ Contains a vector of configuration options.
- :emacs-eval - elisp code to be evaluated on the emacs process.
+- :emacs-custom-setup - elisp code that will be executed after the org file has been opened, before the org file is being exported. This allows to perform dynamic modifications on the content.
- :host - remote host to deploy to.
- :user - remote username
@@ -379,6 +381,18 @@ Posts are Maps with the following attributes:
- javadate: A java date object in case you want to perform date manipulations
+# Org Mode Content Meta
+If you're generating the posts with Emacs' org-mode, you may want to leverage the fancy org babel or other facilities, to perform code during the exporting of your posts. For example, you you may want to to execute all code blocks to also have their results visible. Some of these code blocks may calculate values that you may want to have available in your static template in order to use them somewhere else in your page template. An example would be filling your page keywords with data generated by an org code block. Static supports so called content meta information, which are meta tags that are calculated during the org mode export process and then prepended to the actual html output, i.e.
+<!-- #+tag1: tag1 contents -->
+<!-- #+tag2: tag2 contents -->
+<p>content begins...
+These keywords (tag1 and tag2) are then available in your site metadata for a post.
# Caveats
- This is my first take on a big Clojure project after reading two books and dabbling around with the repl the code may not be good, so if you find something atrocious, just send a pull request.
@@ -234,7 +234,8 @@
description (if (and (> limit 0) (> (count @content) limit))
(str (subs @content 0 limit) "")
- description (if (:summary metadata) (:summary metadata) (escape-html description))
+ description (if (:summary metadata) (:summary metadata) (if (:description metadata) (:description metadata)
+ (escape-html description)))
[:title (escape-html (:title metadata))]
@@ -33,6 +33,15 @@
{} (re-seq #"([^:#\+]+): (.+)(\n|$)" metadata)))
+(defn- prepare-content-metadata [metadata]
+ (reduce (fn [h [_ k v]]
+ (let [key (keyword (.toLowerCase k))]
+ (if (not (h key))
+ (assoc h key v)
+ h)))
+ {} (re-seq #"([^:#\+]+): (.+) (\-\-\>)" metadata))
+ )
(defn- parse-markdown-footnotes [markdown]
"Since pegdown has no footnotes-support, we will just do
some replacement on the markdown itself in order to
@@ -98,12 +107,16 @@
" (find-file \""
(.getAbsolutePath file)
"\") "
+ ;; let the user run additional code from his config after a file has been loaded
+ (when-let [g (:emacs-custom-setup (config/config))] g)
(:org-export-command (config/config))
(:emacs-config (config/config))]
- out (println command)
- content (delay (:out (apply sh/sh command)))]
- [metadata content]))
+ out (println command)
+ content (delay (:out (apply sh/sh command)))
+ content-meta (prepare-content-metadata @content)
+ ]
+ [(merge content-meta metadata) content]))
;; We really need to parse each file once. So we memoize the results
(def read-org

0 comments on commit 85bdc9d

Please sign in to comment.