Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: fix: Filtering #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
34 changes: 22 additions & 12 deletions src/ukko/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
template)

(defmethod transform :org [_ template _]
(println (color/red "----PANDOC---"))
(pandoc "org" template))

(defmethod transform :md [_ template _]
Expand Down Expand Up @@ -378,12 +379,23 @@
find-files
(assoc ctx :artifact-files)))

(defn filter-files [ctx options]
(defn filter-artifacts [ctx options]
(if (:filter options)
(update ctx :artifact-files (partial filter (fn [file]
(re-find (re-pattern (:filter options)) file))))
(update ctx :artifacts (partial map (fn [artifact]
(if (re-find (re-pattern (:filter options)) (-> artifact :path))
artifact
(assoc artifact :no-render true)))))
ctx))


(defn render-artifacts [{:keys [artifacts] :as ctx}]
(let [artifacts-map (reduce #(assoc %1 (:id %2) %2) {} artifacts)
ctx (assoc ctx :artifacts artifacts-map)
artifact-ids (->> ctx :artifacts (remove :no-render) (sort-by sort-key) (map first))
ctx (reduce process-artifact-id ctx artifact-ids)]
ctx))


;; TODO: refactor this mess
(defn add-artifacts [{:keys [artifact-files site-path config] :as ctx}]
(let [artifacts (mmap parse-file artifact-files) ;; add-artifacts
Expand All @@ -396,10 +408,7 @@
artifacts (mmap add-canonical-link artifacts)
artifacts (mmap sanitize-id artifacts)
artifacts (mmap add-target artifacts)
artifacts-map (reduce #(assoc %1 (:id %2) %2) {} artifacts)
ctx (assoc ctx :artifacts artifacts-map)
artifact-ids (->> ctx :artifacts (sort-by sort-key) (map first))
ctx (reduce process-artifact-id ctx artifact-ids)]
ctx (assoc ctx :artifacts artifacts)]
ctx))

(defn sync-assets! [{:keys [assets-path target-path]}]
Expand All @@ -416,20 +425,21 @@
add-data
add-layouts
add-files
(filter-files options)
add-artifacts)
add-artifacts
(filter-artifacts options)
render-artifacts)
artifacts (->> ctx :artifacts vals (sort-by :id))]
(doall
(for [{:keys [id output hidden target] :as artifact} artifacts]
(for [{:keys [id output hidden target] :as artifact} (remove :no-render artifacts)]
(if hidden
(println (color/yellow "Skipping hidden artifact") id)
(do
;; (print ".")
;; (println artifact)
(println (color/blue "Writing") target (str "(" (count output) " bytes)"))
;; TODO: measure write time
(io/make-parents target)
(spit target output)))))
(println (color/green (str "Complete. Wrote " (count artifacts) " artifacts.")))
(println (color/green (str "Complete. Processed " (count artifacts) " artifacts. Wrote " (count (remove :no-render artifacts)) " artifacts.")))
(when (:linkcheck options)
(println (color/blue "Checking links... (this might take a while)"))
(let [{:keys [out exit]} (apply shell/sh (flatten ["linkchecker" "--no-status" (str/split (or (:linkcheck-params config) "") #"\s+") target-path]))]
Expand Down