Add parsing of posts. Need to look into the security of read-string.
This commit is contained in:
parent
8ad5be6cc2
commit
a07bfbd98c
|
@ -9,10 +9,10 @@
|
||||||
(assoc post :type post-type))
|
(assoc post :type post-type))
|
||||||
|
|
||||||
(defn set-author [post author]
|
(defn set-author [post author]
|
||||||
(assoc-in post [:properties :author] author))
|
(assoc-in post [:properties :author] author))
|
||||||
|
|
||||||
(defn set-name [post post-name]
|
(defn set-name [post post-name]
|
||||||
(assoc-in post [:properties :name] post-name))
|
(assoc-in post [:properties :name] post-name))
|
||||||
|
|
||||||
(defn set-content [post post-content]
|
(defn set-content [post post-content]
|
||||||
(assoc-in post [:properties :content] post-content))
|
(assoc-in post [:properties :content] post-content))
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
(ns shapey-shifty.posts.posts-io
|
(ns shapey-shifty.posts.posts-io
|
||||||
(:require
|
(:require
|
||||||
[shapey-shifty.posts.core :as core]))
|
[shapey-shifty.posts.core :as core]))
|
||||||
|
|
||||||
(def post-filename "post.json")
|
(def post-filename "post.json")
|
||||||
(def base-path "resources/posts")
|
(def base-path "resources/posts")
|
||||||
|
|
||||||
|
(defn create-path-by-date [year month day]
|
||||||
(defn create-path-by-date [year month day]
|
|
||||||
{:year year :month month :day day})
|
{:year year :month month :day day})
|
||||||
|
|
||||||
(defn pathmap-to-path [{:keys [year month day]}]
|
(defn pathmap-to-path [{:keys [year month day]}]
|
||||||
|
@ -25,7 +24,14 @@
|
||||||
(defn write-post [post dt-path]
|
(defn write-post [post dt-path]
|
||||||
(let [path (pathmap-to-path dt-path)
|
(let [path (pathmap-to-path dt-path)
|
||||||
increment (inc (count-posts-in-date dt-path))
|
increment (inc (count-posts-in-date dt-path))
|
||||||
final-path (format "%s/%s/%d/%s" base-path path increment post-filename)]
|
final-path (format "%s/%s/%d/%s" base-path path increment post-filename)]
|
||||||
(clojure.java.io/make-parents final-path)
|
(clojure.java.io/make-parents final-path)
|
||||||
(spit final-path post)))
|
(spit final-path post)))
|
||||||
|
|
||||||
|
(defn read-post [dt-path n]
|
||||||
|
(let [path (format "%s/%s/%d/%s" base-path (pathmap-to-path dt-path) n post-filename)
|
||||||
|
f (clojure.java.io/file path)]
|
||||||
|
(when (.exists f)
|
||||||
|
(-> f
|
||||||
|
slurp
|
||||||
|
read-string))))
|
||||||
|
|
Loading…
Reference in New Issue