path.clj
website.git ยท Tickets
website.git > main > 105221d > files / src / dev / grahp / website / path.clj
(ns dev.grahp.website.path
(:require
[clojure.string :as str]
[dev.grahp.website :as-alias w]))
(defn path?
"A vector of URL segments. I.e. '/foo/bar.png' is [\"foo\" \"bar.png\"]."
[x]
(and (vector? x)
(every? string? x)
(not-any? #(str/includes? % "/") x)))
(defn uri->path [uri]
(if (nil? uri)
[]
(into [] (remove str/blank?) (str/split uri #"/"))))
(defn path->uri [path]
(str "/" (str/join "/" path)))
(defn wrap-path
"Splits uris into a vector of path strings with no slashes at the :path key."
[app]
(fn [{:keys [uri] :as request}]
(app (assoc request ::w/path (uri->path uri)))))