My website, which is written using Flask from Hy.
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.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
 
 
 
 

43 lines
1.2 KiB

"""
Blog helper functions
"""
(import [os [listdir]])
(import [os.path [exists]])
;; These are global variables because they are useful
;; throughout the file. They should be considered private.
(setv _posts-prefix "templates/")
(setv _posts-dir "posts/")
(setv _posts-suffix ".html")
(defn test-retrieve-posts [^str post-name]
"""
Test to ensure retrieve-posts is working properly.
"""
(assert (= (first (retrieve-posts post-name))
(+ _posts-dir post-name _posts-suffix)))
(assert (= (retrieve-posts None)
(lfor post (listdir (+ _posts-prefix _posts-dir))
:if (.endswith post _posts-suffix)
(+ _posts-dir post)))))
(defn retrieve-posts [[post-name None]]
"""
Collect and format the name(s)
of the post(s) to be rendered.
"""
(if (= None post-name)
(lfor post (listdir (+ _posts-prefix _posts-dir))
:if (.endswith post _posts-suffix)
(+ _posts-dir post))
[(+ _posts-dir post-name)]))
(defn post-exists? [^str post-name]
"""
Ensure post-name refers to an extant post.
Assumes post-name is not None.
"""
(exists (+ _posts-prefix
_posts-dir
post-name)))