Commit Diff


commit - 4562b810c9e74697ba959cb334fc4715f0b23d50
commit + 936dc247f965aa32a9c01afad936bd27fc72cd5c
blob - 7c27ddd70c8759a5a07fac72f2770d152ba3f1df
blob + 118f6fb93ac41a14f00cf5ba8363ea59d8918b0a
--- src/blog/gemtext.clj
+++ src/blog/gemtext.clj
@@ -39,10 +39,23 @@
    (and (= type :p)
         (= body ""))))
 
+(defn id-from-title [title]
+  (-> title
+      (str/replace #" +" "-")
+      .toLowerCase))
+
+(defn fix-headlines-id [[type body :as t]]
+  (case type
+    :h1 [:h1 {:id (id-from-title body)} body]
+    :h2 [:h2 {:id (id-from-title body)} body]
+    :h3 [:h3 {:id (id-from-title body)} body]
+    t))
+
 (defn to-hiccup [doc]
   (->> (gemtext/to-hiccup doc)
        (filter not-empty-ps)
-       (map maybe-patch-link)))
+       (map maybe-patch-link)
+       (map fix-headlines-id)))
 
 (comment
   (to-hiccup [[:link "http://f.com" "hello"]])