Commit Diff
Diff:
4562b810c9e74697ba959cb334fc4715f0b23d50
936dc247f965aa32a9c01afad936bd27fc72cd5c
Commit:
936dc247f965aa32a9c01afad936bd27fc72cd5c
Tree:
7bb2f01eeb737a27fb85e6d9cbe2df2ee58c93ec
Author:
Omar Polo <op@omarpolo.com>
Date:
Sat Feb 19 13:09:49 2022 UTC
Message:
generate ids for titles
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"]])
Omar Polo