You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.4 KiB

(ns blog.helpers
(:require ["date-fns" :refer [format]]))
(defn truncatestring-factory
[]
(fn [text limit]
(if (> (. text -length) limit)
(-> (. text substring 0 limit)
(str "..."))
text)))
(defn full-timestamp-factory
[]
(clj->js
(fn [timestamp]
(format timestamp "HH:mm MMM. do, yyyy"))))
(defn article-timestamp-factory
[]
(clj->js
(fn [timestamp]
(str "<time pubdate=\""
(format timestamp "yyyy-MM-dd")
"\" datetime=\""
(format timestamp "yyyy-MM-dd")
"\" title=\""
(format timestamp "MMMM do, yyyy")
"\">"
(format timestamp "MMMM do, yyyy")
"</time>"))))
(defn is-brief-factory
[]
(clj->js
(fn [length]
(if (> length 60)
"..."
""))))
(defn navbar-item-style-factory
[]
(clj->js
(fn [url prefix]
(let [baseurl (-> (or url "")
(.split "?")
(first))]
(if (= baseurl prefix)
"block py-2 px-3 text-white bg-blue-700 rounded md:bg-transparent md:text-blue-700 md:p-0 dark:text-white md:dark:text-blue-500"
"block py-2 px-3 text-gray-900 rounded hover:bg-gray-100 md:hover:bg-transparent md:border-0 md:hover:text-blue-700 md:p-0 dark:text-white md:dark:hover:text-blue-500 dark:hover:bg-gray-700 dark:hover:text-white md:dark:hover:bg-transparent")))))