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.

63 lines
1.9 KiB

This is the main Flask application for
(import [flask [Flask redirect render-template request session url-for]])
(import [blog [post-exists? retrieve-posts]])
(setv app (Flask __name__))
(defn after-request [response]
Ensure CSS is reloaded on every page refresh.
This just exists for development purposes.
It should be removed or commented out before deployment.
(setv (. response headers ["Cache-Control"])
"no-cache, no-store, must-revalidate")
(setv (. response headers ["Expires"]) 0)
(setv (. response headers ["Pragma"]) "no-cache")
#@((.route app "/")
(defn index []
Render the landing page.
(render-template "index.html")))
#@((.route app "/blog.html" :methods ["GET" "POST"])
#@((.route app "/blog/<string:post_name>")
(defn blog [[post-name None]]
Render either the blog feed or, if post-name is provided,
perform sanity checks then render the requested post.
;; Eventually, this path will check the posts provided
;; and add 5-10 more posts onto it. For now, default.
[(= (. request method) "POST")
(render-template "blog.html"
:posts (retrieve-posts post-name)
:type "blog")]
;; post-name is checked to be None here as opposed to
;; in post-exists? so that the regular case (rendering
;; the blog feed) has a slightly lower overhead.
[(or (= None post-name) (post-exists? post-name))
(render-template "blog.html"
:posts (retrieve-posts post-name)
:type "blog")]
[True (redirect (url-for "blog"))]))))
#@((.route app "/feed.xml")
(defn feed [[post-name None]]
Render the RSS feed XML file.
(render-template "feed.xml"
:posts (retrieve-posts post-name)
:type "rss")))