Merge pull request #5 from CharlieRoseMarie/add-indexing
Add post crawling
This commit is contained in:
commit
ef6922ab83
|
@ -17,3 +17,4 @@ profiles.clj
|
|||
*.swp
|
||||
resources/posts/
|
||||
/resources/author/
|
||||
resources/index/
|
||||
|
|
|
@ -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"]
|
||||
|
|
|
@ -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)]
|
||||
(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))))
|
||||
|
|
Loading…
Reference in New Issue