[hugo/feat] show catalog

This commit is contained in:
SouthFox 2023-08-31 02:24:02 +08:00
parent ada8acf75e
commit a65fd26722
2 changed files with 17 additions and 2 deletions

View file

@ -42,6 +42,20 @@
(.empty link-card)
(.append link-card (.attr (.parent link-card) "data-text"))))
(defn build-catalog-item
[catalog-item]
(.tagName catalog-item "a")
(.attr catalog-item "href"
(str/join ["#" (.attr catalog-item "id")]))
(.attr catalog-item "id" "")
(str "<li>" (.toString catalog-item) "</li>"))
(defn build-catalog
[docs]
(let [catalog (.select docs "h2, h3, h4, h5")]
(apply str (mapv build-catalog-item catalog))))
(defn fetch-hu-post
[request & {:keys [hugo]}]
@ -56,7 +70,8 @@
(render-linkcard docs)
(let [content {:content (.toString docs)
:title (.text title)
:time (first (str/split (.text post-time) #"・"))}]
:time (first (str/split (.text post-time) #"・"))
:catalog (.toString (build-catalog docs))}]
(if hugo
content
{:status 200

View file

@ -19,7 +19,7 @@
[:div {:class "flex flex-row flex-wrap py-4"}
[:div {:class "w-full sm:w-1/3 md:w-1/4 px-2"}
[:div {:class "sticky top-0 p-4 bg-slate-300 rounded-xl w-full"}
[:nav]]]
[:div (:catalog content)]]]
[:div {:class "w-full sm:w-2/3 md:w-3/4 pt-1 px-2"}
[:h1 (:title content)]
[:time (:time content)]