Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions SPEC.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,6 @@ All posts have a filename which is used as a key to identify the post.
- **:include-rss**
- Set by: *markdown*, true by default
- Used by: *rss*
- **:io.perun/trace**
- Conjed onto by every task that modifies metadata
- Serves as a record of tasks to touch a file
68 changes: 48 additions & 20 deletions src/io/perun.clj
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@
(io.perun.print-meta/print-meta ~(vec (map map-fn (perun/get-meta fileset))))))
fileset))

(defn trace
"Helper function, conj `kw` onto the `:io.perun/trace` metadata
key of each entry in `entries`"
[kw entries]
(map #(update-in % [:io.perun/trace] (fnil conj []) kw) entries))

(def ^:private filedata-deps
'[[com.novemberain/pantomime "2.8.0"]])

Expand All @@ -55,7 +61,10 @@
establish metadata structure."
[]
(boot/with-pre-wrap fileset
(let [updated-files (add-filedata (boot/user-files fileset))]
(let [updated-files (->> fileset
boot/user-files
add-filedata
(trace :io.perun/base))]
(perun/set-meta fileset updated-files))))

(def ^:private images-dimensions-deps
Expand All @@ -71,7 +80,8 @@
files (->> fileset
boot/user-files
(boot/by-ext ["png" "jpeg" "jpg"])
add-filedata)
add-filedata
(trace :io.perun/images-dimensions))
updated-files (pod/with-call-in @pod
(io.perun.contrib.images-dimensions/images-dimensions ~files {}))]
(perun/set-meta fileset updated-files))))
Expand All @@ -96,7 +106,8 @@
files (->> fileset
boot/user-files
(boot/by-ext ["png" "jpeg" "jpg"])
add-filedata)
add-filedata
(trace :io.perun/images-resize))
updated-files (pod/with-call-in @pod
(io.perun.contrib.images-resize/images-resize ~(.getPath tmp) ~files ~options))]
(perun/report-debug "images-resize" "new resized images" updated-files)
Expand Down Expand Up @@ -132,11 +143,15 @@
updated-files (pod/with-call-in @pod
(io.perun.markdown/parse-markdown ~md-files ~options))
initial-metadata (perun/merge-meta* (perun/get-meta fileset) @prev-meta)
; Pure merge instead of `merge-with merge` (meta-meta).
; This is because updated metadata should replace previous metadata to
; correctly handle cases where a metadata key is removed from post metadata.
final-metadata (vals (merge (perun/key-meta initial-metadata) (perun/key-meta updated-files)))
final-metadata (remove #(-> % :path removed?) final-metadata)]
final-metadata (->> updated-files
perun/key-meta
; Pure merge instead of `merge-with merge` (meta-meta).
; This is because updated metadata should replace previous metadata to
; correctly handle cases where a metadata key is removed from post metadata.
(merge (perun/key-meta initial-metadata))
vals
(remove #(-> % :path removed?))
(trace :io.perun/markdown))]
(reset! prev-fs fileset)
(reset! prev-meta final-metadata)
(perun/set-meta fileset final-metadata)))))
Expand Down Expand Up @@ -174,8 +189,9 @@
options (merge +ttr-defaults+ *opts*)]
(boot/with-pre-wrap fileset
(let [files (filter (:filterer options) (perun/get-meta fileset))
updated-files (pod/with-call-in @pod
(io.perun.ttr/calculate-ttr ~files))]
updated-files (trace :io.perun/ttr
(pod/with-call-in @pod
(io.perun.ttr/calculate-ttr ~files)))]
(perun/report-debug "ttr" "generated time-to-read" (map :ttr updated-files))
(perun/set-meta fileset updated-files)))))

Expand All @@ -189,8 +205,9 @@
options (merge +word-count-defaults+ *opts*)]
(boot/with-pre-wrap fileset
(let [files (filter (:filterer options) (perun/get-meta fileset))
updated-files (pod/with-call-in @pod
(io.perun.word-count/count-words ~files))]
updated-files (trace :io.perun/word-count
(pod/with-call-in @pod
(io.perun.word-count/count-words ~files)))]
(perun/report-debug "word-count" "counted words" (map :word-count updated-files))
(perun/set-meta fileset updated-files)))))

Expand All @@ -209,8 +226,9 @@
options (merge +gravatar-defaults+ *opts*)]
(boot/with-pre-wrap fileset
(let [files (filter (:filterer options) (perun/get-meta fileset))
updated-files (pod/with-call-in @pod
(io.perun.gravatar/find-gravatar ~files ~source-key ~target-key))]
updated-files (trace :io.perun/gravatar
(pod/with-call-in @pod
(io.perun.gravatar/find-gravatar ~files ~source-key ~target-key)))]
(perun/report-debug "gravatar" "found gravatars" (map target-key updated-files))
(perun/set-meta fileset updated-files)))))

Expand All @@ -220,7 +238,9 @@
[]
(boot/with-pre-wrap fileset
(let [files (perun/get-meta fileset)
updated-files (remove #(true? (:draft %)) files)]
updated-files (->> files
(remove #(true? (:draft %)))
(trace :io.perun/draft))]
(perun/report-info "draft" "removed draft files. Remaining %s files" (count updated-files))
(perun/set-meta fileset updated-files))))

Expand All @@ -235,7 +255,9 @@
files (filter (:filterer options) (perun/get-meta fileset))
global-meta (perun/get-global-meta fileset)
now (java.util.Date.)
updated-files (map #(assoc % :date-build now) files)
updated-files (->> files
(map #(assoc % :date-build now))
(trace :io.perun/build-date))
new-global-meta (assoc global-meta :date-build now)
updated-fs (perun/set-meta fileset updated-files)]
(perun/report-debug "build-date" "added :date-build" (map :date-build updated-files))
Expand All @@ -260,7 +282,9 @@
(let [options (merge +slug-defaults+ *opts*)
slug-fn (:slug-fn options)
files (filter (:filterer options) (perun/get-meta fileset))
updated-files (map #(assoc % :slug (-> % :filename slug-fn)) files)]
updated-files (->> files
(map #(assoc % :slug (-> % :filename slug-fn)))
(trace :io.perun/slug))]
(perun/report-debug "slug" "generated slugs" (map :slug updated-files))
(perun/report-info "slug" "added slugs to %s files" (count updated-files))
(perun/set-meta fileset updated-files))))
Expand All @@ -279,7 +303,9 @@
(let [options (merge +permalink-defaults+ *opts*)
files (filter (:filterer options) (perun/get-meta fileset))
assoc-perma #(assoc % :permalink ((:permalink-fn options) %))
updated-files (map assoc-perma files)]
updated-files (->> files
(map assoc-perma)
(trace :io.perun/permalink))]
(perun/report-debug "permalink" "generated permalinks" (map :permalink updated-files))
(perun/report-info "permalink" "added permalinks to %s files" (count updated-files))
(perun/merge-meta fileset updated-files))))
Expand All @@ -302,7 +328,9 @@
:canonical-url
; we need to call perun/relativize-url to remove leading / because base-url has trailing /
(str base-url (perun/relativize-url (:permalink %))))
updated-files (map assoc-can-url files)]
updated-files (->> files
(map assoc-can-url)
(trace :io.perun/canonical-url))]
(perun/report-info "canonical-url" "added canonical urls to %s files" (count updated-files))
(perun/merge-meta fileset updated-files))))

Expand Down Expand Up @@ -514,7 +542,7 @@
(perun/report-info "collection" "rendered collection %s" page)
new-entry)))
grouped-files))
updated-files (apply conj files new-files)
updated-files (apply conj files (trace :io.perun/collection new-files))
updated-fileset (perun/set-meta fileset updated-files)]
(commit updated-fileset tmp))))))

Expand Down