Compare commits
8 commits
Author | SHA1 | Date | |
---|---|---|---|
fe912249b1 | |||
ae976925fb | |||
724d1e9a7f | |||
1c43b84d68 | |||
a091a377b0 | |||
84c201c6e1 | |||
be0aeeb80d | |||
4f3cfe4728 |
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -18,3 +18,4 @@ profiles.clj
|
||||||
resources/posts/
|
resources/posts/
|
||||||
/resources/author/
|
/resources/author/
|
||||||
resources/index/
|
resources/index/
|
||||||
|
*.eastwood
|
||||||
|
|
|
@ -38,10 +38,6 @@
|
||||||
:resource-paths ["resources"]
|
:resource-paths ["resources"]
|
||||||
:target-path "target/%s/"
|
:target-path "target/%s/"
|
||||||
:main ^:skip-aot shapey-shifty.core
|
:main ^:skip-aot shapey-shifty.core
|
||||||
|
|
||||||
:plugins [ [lein-cljfmt "0.6.6"]
|
|
||||||
]
|
|
||||||
|
|
||||||
:profiles
|
:profiles
|
||||||
{:uberjar {:omit-source true
|
{:uberjar {:omit-source true
|
||||||
:aot :all
|
:aot :all
|
||||||
|
@ -58,6 +54,7 @@
|
||||||
[ring/ring-devel "1.8.0"]
|
[ring/ring-devel "1.8.0"]
|
||||||
[ring/ring-mock "0.4.0"]]
|
[ring/ring-mock "0.4.0"]]
|
||||||
:plugins [[com.jakemccrary/lein-test-refresh "0.24.1"]
|
:plugins [[com.jakemccrary/lein-test-refresh "0.24.1"]
|
||||||
|
[lein-cljfmt "0.6.6"]
|
||||||
[jonase/eastwood "0.3.5"]]
|
[jonase/eastwood "0.3.5"]]
|
||||||
|
|
||||||
:source-paths ["env/dev/clj"]
|
:source-paths ["env/dev/clj"]
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
(ns shapey-shifty.index.index
|
(ns shapey-shifty.index.index
|
||||||
(:require [clucy.core :as clucy]
|
(:require [clucy.core :as clucy]
|
||||||
[shapey-shifty.posts.posts-io :as post-io]
|
[clojure.java.io :as io]
|
||||||
))
|
[shapey-shifty.posts.posts-io :as post-io]))
|
||||||
|
|
||||||
(def index-path (atom "resources/index"))
|
(def index-path (atom "resources/index"))
|
||||||
|
|
||||||
|
@ -15,8 +15,8 @@
|
||||||
(crawl-posts! path post-io/read-post))
|
(crawl-posts! path post-io/read-post))
|
||||||
([path parsing-fn]
|
([path parsing-fn]
|
||||||
(->> path
|
(->> path
|
||||||
clojure.java.io/file
|
io/file
|
||||||
file-seq
|
file-seq
|
||||||
(filter #(.isFile %))
|
(filter #(.isFile %))
|
||||||
(mapv #(parsing-fn %))
|
(mapv #(parsing-fn %))
|
||||||
(apply add-post-to-index))))
|
(map #(add-post-to-index %)))))
|
||||||
|
|
|
@ -1,22 +1,24 @@
|
||||||
(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]
|
||||||
[shapey-shifty.authors.author-core :as author]))
|
[shapey-shifty.authors.author-core :as author]
|
||||||
|
[clojure.java.io :as io]
|
||||||
|
[clojure.edn :as edn]))
|
||||||
|
|
||||||
(def post-filename "post.json")
|
(def post-filename "post.edn")
|
||||||
(def base-posts-path "resources/posts")
|
(def base-posts-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]}]
|
||||||
(format "%s/%s/%s" year month day))
|
(format "%d/%d/%d" year month day))
|
||||||
|
|
||||||
(defn count-posts-in-date [dt-path]
|
(defn count-posts-in-date [dt-path]
|
||||||
(let [path (pathmap-to-path dt-path)
|
(let [path (pathmap-to-path dt-path)
|
||||||
final-path (format "%s/%s" base-posts-path path)]
|
final-path (format "%s/%s" base-posts-path path)]
|
||||||
(->> final-path
|
(->> final-path
|
||||||
clojure.java.io/file
|
io/file
|
||||||
file-seq
|
file-seq
|
||||||
(filter #(.isDirectory %))
|
(filter #(.isDirectory %))
|
||||||
count
|
count
|
||||||
|
@ -25,9 +27,9 @@
|
||||||
(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-posts-path path increment post-filename)]
|
final-path (format "%s/%s/%s/%s" base-posts-path path increment post-filename)]
|
||||||
(clojure.java.io/make-parents final-path)
|
(io/make-parents final-path)
|
||||||
(spit final-path post)))
|
(spit final-path (pr-str post))))
|
||||||
|
|
||||||
(defn assoc-author [post]
|
(defn assoc-author [post]
|
||||||
(let [filename (get-in post [:properties :author])
|
(let [filename (get-in post [:properties :author])
|
||||||
|
@ -38,8 +40,18 @@
|
||||||
(defn read-post
|
(defn read-post
|
||||||
([file]
|
([file]
|
||||||
(when (.exists file)
|
(when (.exists file)
|
||||||
(-> file slurp read-string assoc-author)))
|
(-> file slurp edn/read-string assoc-author)))
|
||||||
([dt-path n]
|
([dt-path n]
|
||||||
(let [path (format "%s/%s/%s/%s" base-posts-path (pathmap-to-path dt-path) n post-filename)
|
(let [path (format "%s/%s/%d/%s" base-posts-path (pathmap-to-path dt-path) n post-filename)
|
||||||
f (clojure.java.io/file path)]
|
f (io/file path)]
|
||||||
(read-post f))))
|
(read-post f))))
|
||||||
|
|
||||||
|
(defn read-all-posts
|
||||||
|
([]
|
||||||
|
(read-all-posts base-posts-path))
|
||||||
|
([path]
|
||||||
|
(->> path
|
||||||
|
io/file
|
||||||
|
file-seq
|
||||||
|
(filter #(.isFile %))
|
||||||
|
(map #(read-post %)))))
|
||||||
|
|
|
@ -25,9 +25,7 @@
|
||||||
|
|
||||||
(defn about-page [request]
|
(defn about-page [request]
|
||||||
(layout/render request "h_card.html"
|
(layout/render request "h_card.html"
|
||||||
{
|
{:card (:card (author/load-author (get-in request [:path-params :name])))}))
|
||||||
:card (:card (author/load-author (get-in request [:path-params :name])))
|
|
||||||
}))
|
|
||||||
|
|
||||||
(defn home-routes []
|
(defn home-routes []
|
||||||
[""
|
[""
|
||||||
|
|
Loading…
Reference in a new issue