Add post crawling
This commit is contained in:
parent
da11623da2
commit
4825e9cf26
|
@ -17,3 +17,4 @@ profiles.clj
|
||||||
*.swp
|
*.swp
|
||||||
resources/posts/
|
resources/posts/
|
||||||
/resources/author/
|
/resources/author/
|
||||||
|
resources/index/
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
[clojure.java-time "0.3.2"]
|
[clojure.java-time "0.3.2"]
|
||||||
[org.clojure/data.json "0.2.7"]
|
[org.clojure/data.json "0.2.7"]
|
||||||
[cprop "0.1.15"]
|
[cprop "0.1.15"]
|
||||||
|
[clucy "0.4.0"]
|
||||||
[expound "0.8.3"]
|
[expound "0.8.3"]
|
||||||
[funcool/struct "1.4.0"]
|
[funcool/struct "1.4.0"]
|
||||||
[luminus-jetty "0.1.7"]
|
[luminus-jetty "0.1.7"]
|
||||||
|
|
|
@ -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))))
|
|
@ -35,12 +35,11 @@
|
||||||
card (get author :card)]
|
card (get author :card)]
|
||||||
(assoc post :author card)))
|
(assoc post :author card)))
|
||||||
|
|
||||||
(defn read-post [dt-path n]
|
(defn read-post
|
||||||
(let [path (format "%s/%s/%s/%s" base-posts-path (pathmap-to-path dt-path) n post-filename)
|
([file]
|
||||||
f (clojure.java.io/file path)]
|
(when (.exists file)
|
||||||
(when (.exists f)
|
(-> file slurp read-string assoc-author)))
|
||||||
(-> f
|
([dt-path n]
|
||||||
slurp
|
(let [path (format "%s/%s/%s/%s" base-posts-path (pathmap-to-path dt-path) n post-filename)
|
||||||
read-string
|
f (clojure.java.io/file path)]
|
||||||
assoc-author
|
(read-post f))))
|
||||||
))))
|
|
||||||
|
|
Loading…
Reference in New Issue