diff --git a/.gitignore b/.gitignore index dd72772..e0f2c3e 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,4 @@ profiles.clj *.swp resources/posts/ /resources/author/ +resources/index/ diff --git a/project.clj b/project.clj index 18854a1..2f86b94 100644 --- a/project.clj +++ b/project.clj @@ -8,6 +8,7 @@ [clojure.java-time "0.3.2"] [org.clojure/data.json "0.2.7"] [cprop "0.1.15"] + [clucy "0.4.0"] [expound "0.8.3"] [funcool/struct "1.4.0"] [luminus-jetty "0.1.7"] diff --git a/src/clj/shapey_shifty/index/index.clj b/src/clj/shapey_shifty/index/index.clj new file mode 100644 index 0000000..ea7b205 --- /dev/null +++ b/src/clj/shapey_shifty/index/index.clj @@ -0,0 +1,22 @@ +(ns shapey-shifty.index.index + (:require [clucy.core :as clucy] + [shapey-shifty.posts.posts-io :as post-io] + )) + +(def index-path (atom "resources/index")) + +(def post-index (clucy/disk-index @index-path)) + +(defn add-post-to-index [post] + (clucy/add post-index post)) + +(defn crawl-posts! + ([path] + (crawl-posts! path post-io/read-post)) + ([path parsing-fn] + (->> path + clojure.java.io/file + file-seq + (filter #(.isFile %)) + (mapv #(parsing-fn %)) + (apply add-post-to-index)))) diff --git a/src/clj/shapey_shifty/posts/posts_io.clj b/src/clj/shapey_shifty/posts/posts_io.clj index 13ca6a1..27bf50a 100644 --- a/src/clj/shapey_shifty/posts/posts_io.clj +++ b/src/clj/shapey_shifty/posts/posts_io.clj @@ -35,12 +35,11 @@ card (get author :card)] (assoc post :author card))) -(defn read-post [dt-path n] - (let [path (format "%s/%s/%s/%s" base-posts-path (pathmap-to-path dt-path) n post-filename) - f (clojure.java.io/file path)] - (when (.exists f) - (-> f - slurp - read-string - assoc-author - )))) +(defn read-post + ([file] + (when (.exists file) + (-> file slurp read-string assoc-author))) + ([dt-path n] + (let [path (format "%s/%s/%s/%s" base-posts-path (pathmap-to-path dt-path) n post-filename) + f (clojure.java.io/file path)] + (read-post f))))