Add post crawling

This commit is contained in:
Charlotte Allen 2020-02-03 12:29:19 -08:00
parent da11623da2
commit 4825e9cf26
4 changed files with 32 additions and 9 deletions

1
.gitignore vendored
View File

@ -17,3 +17,4 @@ profiles.clj
*.swp
resources/posts/
/resources/author/
resources/index/

View File

@ -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"]

View File

@ -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))))

View File

@ -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))))