Skip to content

Commit ed9b285

Browse files
authored
Merge pull request #117 from bhagany/trace
Add `:io.perun/trace` to file metadata
2 parents c524241 + ebcd6da commit ed9b285

2 files changed

Lines changed: 51 additions & 20 deletions

File tree

SPEC.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,6 @@ All posts have a filename which is used as a key to identify the post.
7777
- **:include-rss**
7878
- Set by: *markdown*, true by default
7979
- Used by: *rss*
80+
- **:io.perun/trace**
81+
- Conjed onto by every task that modifies metadata
82+
- Serves as a record of tasks to touch a file

src/io/perun.clj

Lines changed: 48 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@
4040
(io.perun.print-meta/print-meta ~(vec (map map-fn (perun/get-meta fileset))))))
4141
fileset))
4242

43+
(defn trace
44+
"Helper function, conj `kw` onto the `:io.perun/trace` metadata
45+
key of each entry in `entries`"
46+
[kw entries]
47+
(map #(update-in % [:io.perun/trace] (fnil conj []) kw) entries))
48+
4349
(def ^:private filedata-deps
4450
'[[com.novemberain/pantomime "2.8.0"]])
4551

@@ -55,7 +61,10 @@
5561
establish metadata structure."
5662
[]
5763
(boot/with-pre-wrap fileset
58-
(let [updated-files (add-filedata (boot/user-files fileset))]
64+
(let [updated-files (->> fileset
65+
boot/user-files
66+
add-filedata
67+
(trace :io.perun/base))]
5968
(perun/set-meta fileset updated-files))))
6069

6170
(def ^:private images-dimensions-deps
@@ -71,7 +80,8 @@
7180
files (->> fileset
7281
boot/user-files
7382
(boot/by-ext ["png" "jpeg" "jpg"])
74-
add-filedata)
83+
add-filedata
84+
(trace :io.perun/images-dimensions))
7585
updated-files (pod/with-call-in @pod
7686
(io.perun.contrib.images-dimensions/images-dimensions ~files {}))]
7787
(perun/set-meta fileset updated-files))))
@@ -96,7 +106,8 @@
96106
files (->> fileset
97107
boot/user-files
98108
(boot/by-ext ["png" "jpeg" "jpg"])
99-
add-filedata)
109+
add-filedata
110+
(trace :io.perun/images-resize))
100111
updated-files (pod/with-call-in @pod
101112
(io.perun.contrib.images-resize/images-resize ~(.getPath tmp) ~files ~options))]
102113
(perun/report-debug "images-resize" "new resized images" updated-files)
@@ -132,11 +143,15 @@
132143
updated-files (pod/with-call-in @pod
133144
(io.perun.markdown/parse-markdown ~md-files ~options))
134145
initial-metadata (perun/merge-meta* (perun/get-meta fileset) @prev-meta)
135-
; Pure merge instead of `merge-with merge` (meta-meta).
136-
; This is because updated metadata should replace previous metadata to
137-
; correctly handle cases where a metadata key is removed from post metadata.
138-
final-metadata (vals (merge (perun/key-meta initial-metadata) (perun/key-meta updated-files)))
139-
final-metadata (remove #(-> % :path removed?) final-metadata)]
146+
final-metadata (->> updated-files
147+
perun/key-meta
148+
; Pure merge instead of `merge-with merge` (meta-meta).
149+
; This is because updated metadata should replace previous metadata to
150+
; correctly handle cases where a metadata key is removed from post metadata.
151+
(merge (perun/key-meta initial-metadata))
152+
vals
153+
(remove #(-> % :path removed?))
154+
(trace :io.perun/markdown))]
140155
(reset! prev-fs fileset)
141156
(reset! prev-meta final-metadata)
142157
(perun/set-meta fileset final-metadata)))))
@@ -174,8 +189,9 @@
174189
options (merge +ttr-defaults+ *opts*)]
175190
(boot/with-pre-wrap fileset
176191
(let [files (filter (:filterer options) (perun/get-meta fileset))
177-
updated-files (pod/with-call-in @pod
178-
(io.perun.ttr/calculate-ttr ~files))]
192+
updated-files (trace :io.perun/ttr
193+
(pod/with-call-in @pod
194+
(io.perun.ttr/calculate-ttr ~files)))]
179195
(perun/report-debug "ttr" "generated time-to-read" (map :ttr updated-files))
180196
(perun/set-meta fileset updated-files)))))
181197

@@ -189,8 +205,9 @@
189205
options (merge +word-count-defaults+ *opts*)]
190206
(boot/with-pre-wrap fileset
191207
(let [files (filter (:filterer options) (perun/get-meta fileset))
192-
updated-files (pod/with-call-in @pod
193-
(io.perun.word-count/count-words ~files))]
208+
updated-files (trace :io.perun/word-count
209+
(pod/with-call-in @pod
210+
(io.perun.word-count/count-words ~files)))]
194211
(perun/report-debug "word-count" "counted words" (map :word-count updated-files))
195212
(perun/set-meta fileset updated-files)))))
196213

@@ -209,8 +226,9 @@
209226
options (merge +gravatar-defaults+ *opts*)]
210227
(boot/with-pre-wrap fileset
211228
(let [files (filter (:filterer options) (perun/get-meta fileset))
212-
updated-files (pod/with-call-in @pod
213-
(io.perun.gravatar/find-gravatar ~files ~source-key ~target-key))]
229+
updated-files (trace :io.perun/gravatar
230+
(pod/with-call-in @pod
231+
(io.perun.gravatar/find-gravatar ~files ~source-key ~target-key)))]
214232
(perun/report-debug "gravatar" "found gravatars" (map target-key updated-files))
215233
(perun/set-meta fileset updated-files)))))
216234

@@ -220,7 +238,9 @@
220238
[]
221239
(boot/with-pre-wrap fileset
222240
(let [files (perun/get-meta fileset)
223-
updated-files (remove #(true? (:draft %)) files)]
241+
updated-files (->> files
242+
(remove #(true? (:draft %)))
243+
(trace :io.perun/draft))]
224244
(perun/report-info "draft" "removed draft files. Remaining %s files" (count updated-files))
225245
(perun/set-meta fileset updated-files))))
226246

@@ -235,7 +255,9 @@
235255
files (filter (:filterer options) (perun/get-meta fileset))
236256
global-meta (perun/get-global-meta fileset)
237257
now (java.util.Date.)
238-
updated-files (map #(assoc % :date-build now) files)
258+
updated-files (->> files
259+
(map #(assoc % :date-build now))
260+
(trace :io.perun/build-date))
239261
new-global-meta (assoc global-meta :date-build now)
240262
updated-fs (perun/set-meta fileset updated-files)]
241263
(perun/report-debug "build-date" "added :date-build" (map :date-build updated-files))
@@ -260,7 +282,9 @@
260282
(let [options (merge +slug-defaults+ *opts*)
261283
slug-fn (:slug-fn options)
262284
files (filter (:filterer options) (perun/get-meta fileset))
263-
updated-files (map #(assoc % :slug (-> % :filename slug-fn)) files)]
285+
updated-files (->> files
286+
(map #(assoc % :slug (-> % :filename slug-fn)))
287+
(trace :io.perun/slug))]
264288
(perun/report-debug "slug" "generated slugs" (map :slug updated-files))
265289
(perun/report-info "slug" "added slugs to %s files" (count updated-files))
266290
(perun/set-meta fileset updated-files))))
@@ -279,7 +303,9 @@
279303
(let [options (merge +permalink-defaults+ *opts*)
280304
files (filter (:filterer options) (perun/get-meta fileset))
281305
assoc-perma #(assoc % :permalink ((:permalink-fn options) %))
282-
updated-files (map assoc-perma files)]
306+
updated-files (->> files
307+
(map assoc-perma)
308+
(trace :io.perun/permalink))]
283309
(perun/report-debug "permalink" "generated permalinks" (map :permalink updated-files))
284310
(perun/report-info "permalink" "added permalinks to %s files" (count updated-files))
285311
(perun/merge-meta fileset updated-files))))
@@ -302,7 +328,9 @@
302328
:canonical-url
303329
; we need to call perun/relativize-url to remove leading / because base-url has trailing /
304330
(str base-url (perun/relativize-url (:permalink %))))
305-
updated-files (map assoc-can-url files)]
331+
updated-files (->> files
332+
(map assoc-can-url)
333+
(trace :io.perun/canonical-url))]
306334
(perun/report-info "canonical-url" "added canonical urls to %s files" (count updated-files))
307335
(perun/merge-meta fileset updated-files))))
308336

@@ -514,7 +542,7 @@
514542
(perun/report-info "collection" "rendered collection %s" page)
515543
new-entry)))
516544
grouped-files))
517-
updated-files (apply conj files new-files)
545+
updated-files (apply conj files (trace :io.perun/collection new-files))
518546
updated-fileset (perun/set-meta fileset updated-files)]
519547
(commit updated-fileset tmp))))))
520548

0 commit comments

Comments
 (0)