From 0d1451b32f1a0a20525bdda4d2c70b6f788e549e Mon Sep 17 00:00:00 2001 From: Brent Hagany Date: Sun, 4 Dec 2016 21:17:02 -0600 Subject: [PATCH 01/34] Add logging for case when `assortment` doesn't find anything to render --- src/io/perun.clj | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/src/io/perun.clj b/src/io/perun.clj index 01036192..4116bd72 100644 --- a/src/io/perun.clj +++ b/src/io/perun.clj @@ -549,24 +549,29 @@ on the provided `fileset` and `options`." [task-name fileset options] (let [global-meta (perun/get-global-meta fileset) - grouper (:grouper options)] - (->> fileset - perun/get-meta - (filter (:filterer options)) - grouper - (reduce - (fn [result [path {:keys [entries group-meta permalink]}]] - (let [sorted (sort-by (:sortby options) (:comparator options) entries) - new-path (make-path (:out-dir options) permalink path) - new-entry (merge group-meta {:path new-path - :filename path}) - render-data {:meta global-meta - :entry new-entry - :entries (vec sorted)}] - (perun/report-info task-name (str "rendered " task-name " " path)) - (assoc result new-path {:render-data render-data - :entry new-entry}))) - {})))) + grouper (:grouper options) + paths (->> fileset + perun/get-meta + (filter (:filterer options)) + grouper)] + (if (seq paths) + (reduce + (fn [result [path {:keys [entries group-meta permalink]}]] + (let [sorted (sort-by (:sortby options) (:comparator options) entries) + new-path (make-path (:out-dir options) permalink path) + new-entry (merge group-meta {:path new-path + :filename path}) + render-data {:meta global-meta + :entry new-entry + :entries (vec sorted)}] + (perun/report-info task-name (str "rendered " task-name " " path)) + (assoc result new-path {:render-data render-data + :entry new-entry}))) + {} + paths) + (do + (perun/report-info task-name (str task-name " found nothing to render")) + [])))) (def ^:private +collection-defaults+ {:out-dir "public" From e70f76ae172316f0bc88da5e26b7682fd15805d9 Mon Sep 17 00:00:00 2001 From: Brent Hagany Date: Sun, 4 Dec 2016 21:17:42 -0600 Subject: [PATCH 02/34] Add `assortment` task, for collections of collections --- src/io/perun.clj | 75 ++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 60 insertions(+), 15 deletions(-) diff --git a/src/io/perun.clj b/src/io/perun.clj index 4116bd72..b453bd31 100644 --- a/src/io/perun.clj +++ b/src/io/perun.clj @@ -590,13 +590,12 @@ Entries can optionally be filtered by supplying a function to the `filterer` option. - The `sortby` and `groupby` functions can be used for ordering entries + The `sortby` function can be used for ordering entries before rendering as well as rendering groups of entries to different pages." [o out-dir OUTDIR str "the output directory" r renderer RENDERER sym "page renderer (fully qualified symbol resolving to a function)" _ filterer FILTER code "predicate to use for selecting entries (default: `:has-content`)" s sortby SORTBY code "sort entries by function" - g groupby GROUPBY code "group posts by function, keys are filenames, values are to-be-rendered entries" c comparator COMPARATOR code "sort by comparator function" p page PAGE str "collection result page path" m meta META edn "metadata to set on each collection entry"] @@ -605,29 +604,75 @@ (if-let [p (:page *opts*)] {:grouper #(-> {p {:entries % :group-meta (:meta *opts*)}})} - (if-let [gb (:groupby *opts*)] - {:grouper #(->> % - (group-by gb) - (map (fn [[page entries]] - [page {:entries entries - :group-meta (:meta *opts*)}])) - (into {}))} - {:grouper #(-> {"index.html" {:entries % - :group-meta (:meta *opts*)}})})))] + {:grouper #(-> {"index.html" {:entries % + :group-meta (:meta *opts*)}})}))] (cond (not (fn? (:comparator options))) (u/fail "collection task :comparator option should implement Fn\n") (not (ifn? (:filterer options))) (u/fail "collection task :filterer option value should implement IFn\n") - (and (:page options) (:groupby *opts*)) - (u/fail "using the :page option will render any :groupby option setting effectless\n") - (and (:groupby options) (not (ifn? (:groupby options)))) - (u/fail "collection task :groupby option value should implement IFn\n") (not (ifn? (:sortby options))) (u/fail "collection task :sortby option value should implement IFn\n") :else (let [collection-paths (partial grouped-paths "collection")] (render-pre-wrap collection-paths options :io.perun/collection))))) +(def ^:private +assortment-defaults+ + {:out-dir "public" + :filterer :has-content + :sortby (fn [file] (:date-published file)) + :comparator (fn [i1 i2] (compare i2 i1))}) + +(deftask assortment + "Render multiple collections + The symbol supplied as `renderer` should resolve to a function + which will be called with a map containing the following keys: + - `:meta`, global perun metadata + - `:entry`, the metadata for this collection + - `:entries`, all entries + + The `grouper` function will be called with a seq containing the + entries to be grouped, and it should return a map with keys that + are filenames and values that are maps with the keys: + - `:entries`: the entries for each collection + - `:group-meta`: (optional) page metadata for this collection + + Entries can optionally be filtered by supplying a function + to the `filterer` option. + + The `sortby` function can be used for ordering entries before rendering." + [o out-dir OUTDIR str "the output directory" + r renderer RENDERER sym "page renderer (fully qualified symbol resolving to a function)" + g grouper GROUPER code "group posts function, keys are filenames, values are to-be-rendered entries" + _ filterer FILTER code "predicate to use for selecting entries (default: `:has-content`)" + s sortby SORTBY code "sort entries by function" + c comparator COMPARATOR code "sort by comparator function" + m meta META edn "metadata to set on each collection entry"] + (let [options (merge +assortment-defaults+ + *opts* + (if-let [grouper* (:grouper *opts*)] + {:grouper (fn [metas] + (->> metas + grouper* + (reduce + (fn [paths [page data]] + (assoc paths page + (update-in data [:group-meta] + #(merge (:meta *opts*) %)))) + {})))} + {:grouper #(-> {"index.html" {:entries % + :group-meta (:meta *opts*)}})}))] + (cond (not (fn? (:comparator options))) + (u/fail "assortment task :comparator option should implement Fn\n") + (not (ifn? (:filterer options))) + (u/fail "assortment task :filterer option value should implement IFn\n") + (not (ifn? (:grouper options))) + (u/fail "assortment task :grouper option value should implement IFn\n") + (not (ifn? (:sortby options))) + (u/fail "assortment task :sortby option value should implement IFn\n") + :else + (let [assortment-paths (partial grouped-paths "assortment")] + (render-pre-wrap assortment-paths options :io.perun/assortment))))) + (deftask inject-scripts "Inject JavaScript scripts into html files. Use either filter to include only files matching or remove to From 136eb68680b04d41802c87b2fcb96d17364b81c5 Mon Sep 17 00:00:00 2001 From: Brent Hagany Date: Mon, 5 Dec 2016 11:15:20 -0600 Subject: [PATCH 03/34] Pedantic indentation fix --- src/io/perun.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/io/perun.clj b/src/io/perun.clj index 1175f67d..3bb936f4 100644 --- a/src/io/perun.clj +++ b/src/io/perun.clj @@ -678,7 +678,7 @@ (u/fail "assortment task :sortby option value should implement IFn\n") :else (let [assortment-paths (partial grouped-paths "assortment")] - (render-pre-wrap assortment-paths options :io.perun/assortment))))) + (render-pre-wrap assortment-paths options :io.perun/assortment))))) (deftask inject-scripts "Inject JavaScript scripts into html files. From 71ffae5c087fd61323d18596207c4c88ff7e603a Mon Sep 17 00:00:00 2001 From: Brent Hagany Date: Thu, 5 Jan 2017 21:45:03 -0600 Subject: [PATCH 04/34] Abstract assortment to make adding specialized assortments easier --- src/io/perun.clj | 110 +++++++++++++++++++++-------------------------- 1 file changed, 50 insertions(+), 60 deletions(-) diff --git a/src/io/perun.clj b/src/io/perun.clj index d470efdb..0c82289c 100644 --- a/src/io/perun.clj +++ b/src/io/perun.clj @@ -625,105 +625,95 @@ (perun/report-info task-name (str task-name " found nothing to render")) [])))) -(def ^:private +collection-defaults+ +(defn- assortment-impl + [task-name tracer grouper options] + (cond (not (fn? (:comparator options))) + (u/fail (str task-name " task :comparator option should implement Fn\n")) + (not (ifn? (:filterer options))) + (u/fail (str task-name " task :filterer option value should implement IFn\n")) + (not (ifn? (:sortby options))) + (u/fail (str task-name " task :sortby option value should implement IFn\n")) + (not (ifn? grouper)) + (u/fail (str task-name " task :grouper option value should implement IFn\n")) + :else + (let [assortment-paths (partial grouped-paths task-name) + ;; Make sure task-level metadata gets added to each entry + meta-grouper (fn [entries] + (->> entries + grouper + (map (fn [[path data]] + [path (update-in data [:group-meta] #(merge (:meta options) %))])) + (into {}))) + options (assoc options :grouper meta-grouper)] + (render-pre-wrap assortment-paths options tracer)))) + +(def ^:private +assortment-defaults+ {:out-dir "public" :filterer :has-content :sortby (fn [file] (:date-published file)) - :comparator (fn [i1 i2] (compare i2 i1))}) + :comparator (fn [i1 i2] (compare i2 i1)) + :grouper #(-> {"index.html" {:entries %}})}) -(deftask collection - "Render single file for a collection of entries +(deftask assortment + "Render multiple collections The symbol supplied as `renderer` should resolve to a function which will be called with a map containing the following keys: - `:meta`, global perun metadata - `:entry`, the metadata for this collection - `:entries`, all entries + The `grouper` function will be called with a seq containing the + entries to be grouped, and it should return a map with keys that + are filenames and values that are maps with the keys: + - `:entries`: the entries for each collection + - `:group-meta`: (optional) page metadata for this collection + Entries can optionally be filtered by supplying a function to the `filterer` option. - The `sortby` function can be used for ordering entries - before rendering as well as rendering groups of entries to different pages." + The `sortby` function can be used for ordering entries before rendering." [o out-dir OUTDIR str "the output directory" r renderer RENDERER sym "page renderer (fully qualified symbol resolving to a function)" + g grouper GROUPER code "group posts function, keys are filenames, values are to-be-rendered entries" _ filterer FILTER code "predicate to use for selecting entries (default: `:has-content`)" s sortby SORTBY code "sort entries by function" c comparator COMPARATOR code "sort by comparator function" - p page PAGE str "collection result page path" - m meta META edn "metadata to set on each collection entry"] - (let [options (merge +collection-defaults+ - (dissoc *opts* :page) - (if-let [p (:page *opts*)] - {:grouper #(-> {p {:entries % - :group-meta (:meta *opts*)}})} - {:grouper #(-> {"index.html" {:entries % - :group-meta (:meta *opts*)}})}))] - (cond (not (fn? (:comparator options))) - (u/fail "collection task :comparator option should implement Fn\n") - (not (ifn? (:filterer options))) - (u/fail "collection task :filterer option value should implement IFn\n") - (not (ifn? (:sortby options))) - (u/fail "collection task :sortby option value should implement IFn\n") - :else - (let [collection-paths (partial grouped-paths "collection")] - (render-pre-wrap collection-paths options :io.perun/collection))))) + m meta META edn "metadata to set on each collection entry" + n task-name TASKNAME str "name to use for logging messages; only for tasks that use assortment under the hood" + t tracer TRACER kw "value to put in `:io.perun/trace`; only for tasks that use assortment under the hood"] + (let [options (merge +assortment-defaults+ (dissoc *opts* :grouper))] + (assortment-impl "assortment" :io.perun/assortment (:grouper *opts*) options))) -(def ^:private +assortment-defaults+ +(def ^:private +collection-defaults+ {:out-dir "public" :filterer :has-content :sortby (fn [file] (:date-published file)) :comparator (fn [i1 i2] (compare i2 i1))}) -(deftask assortment - "Render multiple collections +(deftask collection + "Render single file for a collection of entries The symbol supplied as `renderer` should resolve to a function which will be called with a map containing the following keys: - `:meta`, global perun metadata - `:entry`, the metadata for this collection - `:entries`, all entries - The `grouper` function will be called with a seq containing the - entries to be grouped, and it should return a map with keys that - are filenames and values that are maps with the keys: - - `:entries`: the entries for each collection - - `:group-meta`: (optional) page metadata for this collection - Entries can optionally be filtered by supplying a function to the `filterer` option. - The `sortby` function can be used for ordering entries before rendering." + The `sortby` function can be used for ordering entries + before rendering as well as rendering groups of entries to different pages." [o out-dir OUTDIR str "the output directory" r renderer RENDERER sym "page renderer (fully qualified symbol resolving to a function)" - g grouper GROUPER code "group posts function, keys are filenames, values are to-be-rendered entries" _ filterer FILTER code "predicate to use for selecting entries (default: `:has-content`)" s sortby SORTBY code "sort entries by function" c comparator COMPARATOR code "sort by comparator function" + p page PAGE str "collection result page path" m meta META edn "metadata to set on each collection entry"] - (let [options (merge +assortment-defaults+ - *opts* - (if-let [grouper* (:grouper *opts*)] - {:grouper (fn [metas] - (->> metas - grouper* - (reduce - (fn [paths [page data]] - (assoc paths page - (update-in data [:group-meta] - #(merge (:meta *opts*) %)))) - {})))} - {:grouper #(-> {"index.html" {:entries % - :group-meta (:meta *opts*)}})}))] - (cond (not (fn? (:comparator options))) - (u/fail "assortment task :comparator option should implement Fn\n") - (not (ifn? (:filterer options))) - (u/fail "assortment task :filterer option value should implement IFn\n") - (not (ifn? (:grouper options))) - (u/fail "assortment task :grouper option value should implement IFn\n") - (not (ifn? (:sortby options))) - (u/fail "assortment task :sortby option value should implement IFn\n") - :else - (let [assortment-paths (partial grouped-paths "assortment")] - (render-pre-wrap assortment-paths options :io.perun/assortment))))) + (let [p (or (:page *opts*) "index.html") + options (merge +collection-defaults+ (dissoc *opts* :page)) + grouper #(-> {p {:entries %}})] + (assortment-impl "collection" :io.perun/collection grouper options))) (deftask inject-scripts "Inject JavaScript scripts into html files. From e27d02b359df892f1e11239f1192df7c08aee1bc Mon Sep 17 00:00:00 2001 From: Brent Hagany Date: Thu, 5 Jan 2017 21:47:19 -0600 Subject: [PATCH 05/34] Fix #63 - Add paginate task --- src/io/perun.clj | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/io/perun.clj b/src/io/perun.clj index 0c82289c..05f0967f 100644 --- a/src/io/perun.clj +++ b/src/io/perun.clj @@ -715,6 +715,44 @@ grouper #(-> {p {:entries %}})] (assortment-impl "collection" :io.perun/collection grouper options))) +(def ^:private +paginate-defaults+ + {:out-dir "public" + :prefix "page-" + :page-size 10 + :filterer :has-content + :sortby (fn [file] (:date-published file)) + :comparator (fn [i1 i2] (compare i2 i1))}) + +(deftask paginate + "Render multiple collections + The symbol supplied as `renderer` should resolve to a function + which will be called with a map containing the following keys: + - `:meta`, global perun metadata + - `:entry`, the metadata for this collection + - `:entries`, all entries + + Entries can optionally be filtered by supplying a function + to the `filterer` option. + + The `sortby` function can be used for ordering entries before rendering." + [o out-dir OUTDIR str "the output directory" + f prefix PREFIX str "the prefix for each html file, eg prefix-1.html, prefix-2.html (default: `\"page-\"`)" + p page-size PAGESIZE int "the number of entries to include in each page (default: `10`)" + r renderer RENDERER sym "page renderer (fully qualified symbol resolving to a function)" + _ filterer FILTER code "predicate to use for selecting entries (default: `:has-content`)" + s sortby SORTBY code "sort entries by function" + c comparator COMPARATOR code "sort by comparator function" + m meta META edn "metadata to set on each collection entry"] + (let [options (merge +paginate-defaults+ *opts*) + grouper (fn [entries] + (->> entries + (sort-by (:sortby options) (:comparator options)) + (partition-all (:page-size options)) + (map-indexed #(-> [(str (:prefix options) (inc %1) ".html") + {:entries %2}])) + (into {})))] + (assortment-impl "paginate" :io.perun/paginate grouper options))) + (deftask inject-scripts "Inject JavaScript scripts into html files. Use either filter to include only files matching or remove to From 9ea83bd07b7e67121e8fe5d0f97f887e1f6ad8f2 Mon Sep 17 00:00:00 2001 From: Brent Hagany Date: Thu, 5 Jan 2017 21:50:01 -0600 Subject: [PATCH 06/34] Fix #27 - Add tags task --- src/io/perun.clj | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/io/perun.clj b/src/io/perun.clj index 0c82289c..245f9b8e 100644 --- a/src/io/perun.clj +++ b/src/io/perun.clj @@ -715,6 +715,43 @@ grouper #(-> {p {:entries %}})] (assortment-impl "collection" :io.perun/collection grouper options))) +(def ^:private +tags-defaults+ + {:out-dir "public" + :filterer :has-content + :sortby (fn [file] (:date-published file)) + :comparator (fn [i1 i2] (compare i2 i1))}) + +(deftask tags + "Render multiple collections based on the `:tags` metadata key + The symbol supplied as `renderer` should resolve to a function + which will be called with a map containing the following keys: + - `:meta`, global perun metadata + - `:entry`, the metadata for this collection + - `:entries`, all entries + + Entries can optionally be filtered by supplying a function + to the `filterer` option. + + The `sortby` function can be used for ordering entries before rendering." + [o out-dir OUTDIR str "the output directory" + r renderer RENDERER sym "page renderer (fully qualified symbol resolving to a function)" + _ filterer FILTER code "predicate to use for selecting entries (default: `:has-content`)" + s sortby SORTBY code "sort entries by function" + c comparator COMPARATOR code "sort by comparator function" + m meta META edn "metadata to set on each collection entry"] + (let [options (merge +tags-defaults+ *opts*) + grouper (fn [entries] + (->> entries + (mapcat (fn [entry] + (map #(-> [% entry]) (:tags entry)))) + (reduce (fn [result [tag entry]] + (let [path (str tag ".html")] + (-> result + (update-in [path :entries] conj entry) + (assoc-in [path :group-meta :tag] tag)))) + {})))] + (assortment-impl "tags" :io.perun/tags grouper options))) + (deftask inject-scripts "Inject JavaScript scripts into html files. Use either filter to include only files matching or remove to From 3e82e92bfc1b4dacd554e7b4061963cb43082692 Mon Sep 17 00:00:00 2001 From: Brent Hagany Date: Mon, 9 Jan 2017 23:05:37 -0600 Subject: [PATCH 07/34] bring paginate up-to-date with fileset-invictus --- src/io/perun.clj | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/io/perun.clj b/src/io/perun.clj index ae0bd348..773f23ba 100644 --- a/src/io/perun.clj +++ b/src/io/perun.clj @@ -689,7 +689,8 @@ {:out-dir "public" :prefix "page-" :page-size 10 - :filterer :has-content + :filterer identity + :extensions [".html"] :sortby (fn [file] (:date-published file)) :comparator (fn [i1 i2] (compare i2 i1))}) @@ -705,14 +706,15 @@ to the `filterer` option. The `sortby` function can be used for ordering entries before rendering." - [o out-dir OUTDIR str "the output directory" - f prefix PREFIX str "the prefix for each html file, eg prefix-1.html, prefix-2.html (default: `\"page-\"`)" - p page-size PAGESIZE int "the number of entries to include in each page (default: `10`)" - r renderer RENDERER sym "page renderer (fully qualified symbol resolving to a function)" - _ filterer FILTER code "predicate to use for selecting entries (default: `:has-content`)" - s sortby SORTBY code "sort entries by function" - c comparator COMPARATOR code "sort by comparator function" - m meta META edn "metadata to set on each collection entry"] + [o out-dir OUTDIR str "the output directory" + f prefix PREFIX str "the prefix for each html file, eg prefix-1.html, prefix-2.html (default: `\"page-\"`)" + p page-size PAGESIZE int "the number of entries to include in each page (default: `10`)" + r renderer RENDERER sym "page renderer (fully qualified symbol resolving to a function)" + _ filterer FILTER code "predicate to use for selecting entries (default: `identity`)" + e extensions EXTENSIONS [str] "extensions of files to include" + s sortby SORTBY code "sort entries by function" + c comparator COMPARATOR code "sort by comparator function" + m meta META edn "metadata to set on each collection entry"] (let [options (merge +paginate-defaults+ *opts*) grouper (fn [entries] (->> entries From 615b35b25f877e418cfa41e0d4d2b06cb42c3c8b Mon Sep 17 00:00:00 2001 From: Brent Hagany Date: Mon, 9 Jan 2017 23:06:47 -0600 Subject: [PATCH 08/34] bring tags up-to-date with fileset-invictus --- src/io/perun.clj | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/io/perun.clj b/src/io/perun.clj index feccda9f..5bffccf6 100644 --- a/src/io/perun.clj +++ b/src/io/perun.clj @@ -687,7 +687,8 @@ (def ^:private +tags-defaults+ {:out-dir "public" - :filterer :has-content + :filterer identity + :extensions [".html"] :sortby (fn [file] (:date-published file)) :comparator (fn [i1 i2] (compare i2 i1))}) @@ -703,12 +704,13 @@ to the `filterer` option. The `sortby` function can be used for ordering entries before rendering." - [o out-dir OUTDIR str "the output directory" - r renderer RENDERER sym "page renderer (fully qualified symbol resolving to a function)" - _ filterer FILTER code "predicate to use for selecting entries (default: `:has-content`)" - s sortby SORTBY code "sort entries by function" - c comparator COMPARATOR code "sort by comparator function" - m meta META edn "metadata to set on each collection entry"] + [o out-dir OUTDIR str "the output directory" + r renderer RENDERER sym "page renderer (fully qualified symbol resolving to a function)" + _ filterer FILTER code "predicate to use for selecting entries (default: `identity`)" + e extensions EXTENSIONS [str] "extensions of files to include" + s sortby SORTBY code "sort entries by function" + c comparator COMPARATOR code "sort by comparator function" + m meta META edn "metadata to set on each collection entry"] (let [options (merge +tags-defaults+ *opts*) grouper (fn [entries] (->> entries From c59e29c2ca1737cab9ff9f84c0910cca86c72e75 Mon Sep 17 00:00:00 2001 From: Brent Hagany Date: Mon, 16 Jan 2017 19:17:16 -0600 Subject: [PATCH 09/34] Rename `assortment-impl` to `assortment-pre-wrap` Also, make arguments a map, to match other pre-wraps --- src/io/perun.clj | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/io/perun.clj b/src/io/perun.clj index 6e9326b1..42c80757 100644 --- a/src/io/perun.clj +++ b/src/io/perun.clj @@ -703,8 +703,8 @@ (perun/report-info task-name (str task-name " found nothing to render")) [])))) -(defn- assortment-impl - [task-name tracer grouper options] +(defn assortment-pre-wrap + [{:keys [task-name tracer grouper options]}] (cond (not (fn? (:comparator options))) (u/fail (str task-name " task :comparator option should implement Fn\n")) (not (ifn? (:filterer options))) @@ -764,8 +764,12 @@ m meta META edn "metadata to set on each collection entry" n task-name TASKNAME str "name to use for logging messages; only for tasks that use assortment under the hood" t tracer TRACER kw "value to put in `:io.perun/trace`; only for tasks that use assortment under the hood"] - (let [options (merge +assortment-defaults+ (dissoc *opts* :grouper))] - (assortment-impl "assortment" :io.perun/assortment grouper options))) + (let [grouper (or grouper #(-> {"index.html" {:entries %}})) + options (merge +assortment-defaults+ (dissoc *opts* :grouper))] + (assortment-pre-wrap {:task-name "assortment" + :tracer :io.perun/assortment + :grouper grouper + :options options}))) (def ^:private +collection-defaults+ {:out-dir "public" @@ -795,10 +799,11 @@ c comparator COMPARATOR code "sort by comparator function" p page PAGE str "collection result page path" m meta META edn "metadata to set on each collection entry"] - (let [p (or page "index.html") - options (merge +collection-defaults+ (dissoc *opts* :page)) - grouper #(-> {p {:entries %}})] - (assortment-impl "collection" :io.perun/collection grouper options))) + (let [p (or page "index.html")] + (assortment-pre-wrap {:task-name "collection" + :tracer :io.perun/collection + :grouper #(-> {p {:entries %}}) + :options (merge +collection-defaults+ (dissoc *opts* :page))}))) (def +inject-scripts-defaults+ {:extensions [".html"]}) From b95f4d476aed128df770c0008a5f9b2cd7da1ddf Mon Sep 17 00:00:00 2001 From: Brent Hagany Date: Mon, 16 Jan 2017 21:37:03 -0600 Subject: [PATCH 10/34] Fix tags implementations --- src/io/perun.clj | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/io/perun.clj b/src/io/perun.clj index 3ac8df86..aa0f6067 100644 --- a/src/io/perun.clj +++ b/src/io/perun.clj @@ -834,8 +834,7 @@ s sortby SORTBY code "sort entries by function" c comparator COMPARATOR code "sort by comparator function" m meta META edn "metadata to set on each collection entry"] - (let [options (merge +tags-defaults+ *opts*) - grouper (fn [entries] + (let [grouper (fn [entries] (->> entries (mapcat (fn [entry] (map #(-> [% entry]) (:tags entry)))) @@ -845,7 +844,10 @@ (update-in [path :entries] conj entry) (assoc-in [path :group-meta :tag] tag)))) {})))] - (assortment-impl "tags" :io.perun/tags grouper options))) + (assortment-pre-wrap {:task-name "tags" + :tracer :io.perun/tags + :grouper grouper + :options (merge +tags-defaults+ *opts*)}))) (deftask inject-scripts "Inject JavaScript scripts into html files. From 9ebaafe098ae03dc12b84e21d3284166b010b5db Mon Sep 17 00:00:00 2001 From: Brent Hagany Date: Mon, 16 Jan 2017 21:40:06 -0600 Subject: [PATCH 11/34] Fix paginate implementation --- src/io/perun.clj | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/io/perun.clj b/src/io/perun.clj index b51bf122..fd2daed9 100644 --- a/src/io/perun.clj +++ b/src/io/perun.clj @@ -838,15 +838,18 @@ s sortby SORTBY code "sort entries by function" c comparator COMPARATOR code "sort by comparator function" m meta META edn "metadata to set on each collection entry"] - (let [options (merge +paginate-defaults+ *opts*) + (let [{:keys [sortby comparator page-size prefix] :as options} (merge +paginate-defaults+ *opts*) grouper (fn [entries] (->> entries - (sort-by (:sortby options) (:comparator options)) - (partition-all (:page-size options)) - (map-indexed #(-> [(str (:prefix options) (inc %1) ".html") + (sort-by sortby comparator) + (partition-all page-size) + (map-indexed #(-> [(str prefix (inc %1) ".html") {:entries %2}])) (into {})))] - (assortment-impl "paginate" :io.perun/paginate grouper options))) + (assortment-pre-wrap {:task-name "paginate" + :tracer :io.perun/paginate + :grouper grouper + :options options}))) (deftask inject-scripts "Inject JavaScript scripts into html files. From 70fd19bd983d46c6c1354256ad98e41255505189 Mon Sep 17 00:00:00 2001 From: Brent Hagany Date: Tue, 17 Jan 2017 07:57:33 -0600 Subject: [PATCH 12/34] Add `assortment-pre-wrap` docstring --- src/io/perun.clj | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/io/perun.clj b/src/io/perun.clj index 42c80757..f06e85b9 100644 --- a/src/io/perun.clj +++ b/src/io/perun.clj @@ -704,6 +704,13 @@ [])))) (defn assortment-pre-wrap + "Handles common assortment task orchestration + + `task-name` is used for log messages. `tracer` is a keyword that gets added + to the `:io.perun/trace` metadata. `grouper` is a function that takes a seq + of entries and returns a map of paths to groups to be rendered. + + Returns a boot `with-pre-wrap` result" [{:keys [task-name tracer grouper options]}] (cond (not (fn? (:comparator options))) (u/fail (str task-name " task :comparator option should implement Fn\n")) From 6828c005f1a45b463c98e03a0f300bfdd377a2b2 Mon Sep 17 00:00:00 2001 From: Brent Hagany Date: Tue, 17 Jan 2017 08:06:11 -0600 Subject: [PATCH 13/34] Rename `:group-meta` to `:entry`, because that's what it is --- src/io/perun.clj | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/io/perun.clj b/src/io/perun.clj index f06e85b9..2838ab0e 100644 --- a/src/io/perun.clj +++ b/src/io/perun.clj @@ -684,7 +684,7 @@ paths (grouper (filter-meta-by-ext fileset options))] (if (seq paths) (reduce - (fn [result [path {:keys [entries group-meta]}]] + (fn [result [path {:keys [entry entries]}]] (let [sorted (->> entries (sort-by sortby comparator) (map #(assoc % :content (->> (:path %) @@ -692,7 +692,7 @@ boot/tmp-file slurp)))) new-path (perun/create-filepath out-dir path) - new-entry (assoc group-meta :out-dir out-dir)] + new-entry (assoc entry :out-dir out-dir)] (perun/report-info task-name (str "rendered " task-name " " path)) (assoc result new-path {:meta global-meta :entry new-entry @@ -708,7 +708,8 @@ `task-name` is used for log messages. `tracer` is a keyword that gets added to the `:io.perun/trace` metadata. `grouper` is a function that takes a seq - of entries and returns a map of paths to groups to be rendered. + of entries and returns a map of paths to render data (see docstring for + `assortment` for more info) Returns a boot `with-pre-wrap` result" [{:keys [task-name tracer grouper options]}] @@ -727,7 +728,7 @@ (->> entries grouper (map (fn [[path data]] - [path (update-in data [:group-meta] #(merge (:meta options) %))])) + [path (update-in data [:entry] #(merge (:meta options) %))])) (into {}))) options (assoc options :grouper meta-grouper)] (render-pre-wrap {:task-name task-name @@ -755,7 +756,7 @@ entries to be grouped, and it should return a map with keys that are filenames and values that are maps with the keys: - `:entries`: the entries for each collection - - `:group-meta`: (optional) page metadata for this collection + - `:entry`: (optional) page metadata for this collection Entries can optionally be filtered by supplying a function to the `filterer` option. From 6aab71918e1457f653d3587d441e18f0ca4732dd Mon Sep 17 00:00:00 2001 From: Brent Hagany Date: Tue, 17 Jan 2017 08:13:42 -0600 Subject: [PATCH 14/34] Remove redundant logging message --- src/io/perun.clj | 1 - 1 file changed, 1 deletion(-) diff --git a/src/io/perun.clj b/src/io/perun.clj index 2838ab0e..364a2144 100644 --- a/src/io/perun.clj +++ b/src/io/perun.clj @@ -693,7 +693,6 @@ slurp)))) new-path (perun/create-filepath out-dir path) new-entry (assoc entry :out-dir out-dir)] - (perun/report-info task-name (str "rendered " task-name " " path)) (assoc result new-path {:meta global-meta :entry new-entry :entries (vec sorted)}))) From 1ca2958a92cef0217e69d16c48969cf763c01cdf Mon Sep 17 00:00:00 2001 From: Brent Hagany Date: Wed, 18 Jan 2017 17:57:03 -0600 Subject: [PATCH 15/34] Remove `assortment` options from a previous implementation --- src/io/perun.clj | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/io/perun.clj b/src/io/perun.clj index 364a2144..abfcfc70 100644 --- a/src/io/perun.clj +++ b/src/io/perun.clj @@ -768,9 +768,7 @@ e extensions EXTENSIONS [str] "extensions of files to include" s sortby SORTBY code "sort entries by function" c comparator COMPARATOR code "sort by comparator function" - m meta META edn "metadata to set on each collection entry" - n task-name TASKNAME str "name to use for logging messages; only for tasks that use assortment under the hood" - t tracer TRACER kw "value to put in `:io.perun/trace`; only for tasks that use assortment under the hood"] + m meta META edn "metadata to set on each collection entry"] (let [grouper (or grouper #(-> {"index.html" {:entries %}})) options (merge +assortment-defaults+ (dissoc *opts* :grouper))] (assortment-pre-wrap {:task-name "assortment" From bc7f8b0027b48570e936228d4c19ff4c5acf1c58 Mon Sep 17 00:00:00 2001 From: Brent Hagany Date: Wed, 18 Jan 2017 21:31:43 -0600 Subject: [PATCH 16/34] Small cleanups --- src/io/perun.clj | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/io/perun.clj b/src/io/perun.clj index abfcfc70..e888a193 100644 --- a/src/io/perun.clj +++ b/src/io/perun.clj @@ -721,8 +721,7 @@ (not (ifn? grouper)) (u/fail (str task-name " task :grouper option value should implement IFn\n")) :else - (let [assortment-paths (partial grouped-paths task-name) - ;; Make sure task-level metadata gets added to each entry + (let [;; Make sure task-level metadata gets added to each entry meta-grouper (fn [entries] (->> entries grouper @@ -731,7 +730,7 @@ (into {}))) options (assoc options :grouper meta-grouper)] (render-pre-wrap {:task-name task-name - :render-paths-fn assortment-paths + :render-paths-fn (partial grouped-paths task-name) :options options :tracer tracer})))) @@ -780,7 +779,7 @@ {:out-dir "public" :filterer identity :extensions [".html"] - :sortby (fn [file] (:date-published file)) + :sortby :date-published :comparator (fn [i1 i2] (compare i2 i1))}) (deftask collection From 306ef3ef89536f9b4544a6459ee935e153ed4624 Mon Sep 17 00:00:00 2001 From: Brent Hagany Date: Wed, 18 Jan 2017 21:32:14 -0600 Subject: [PATCH 17/34] Test `assortment` and `collection` --- test/io/perun_test.clj | 143 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 126 insertions(+), 17 deletions(-) diff --git a/test/io/perun_test.clj b/test/io/perun_test.clj index 09c8ede3..e133ac3e 100644 --- a/test/io/perun_test.clj +++ b/test/io/perun_test.clj @@ -2,6 +2,7 @@ (:require [boot.core :as boot :refer [deftask]] [boot.task.built-in :refer [sift]] [boot.test :as boot-test :refer [deftesttask]] + [clj-yaml.core :as yaml] [clojure.java.io :as io] [clojure.string :as str] [clojure.test :refer [deftest testing is]] @@ -111,17 +112,48 @@ (boot/add-resource tmp) boot/commit!)))) +(def base-meta {:email "brent.hagany@gmail.com" + :author "Testy McTesterson"}) +(def yamls [(yaml/generate-string (assoc base-meta + :uuid "2078a34d-1b1a-4257-9eff-ffe215d90bcd" + :draft true)) + (yaml/generate-string (assoc base-meta + :uuid "2078a34d-1b1a-4257-9eff-ffe215d90bcd" + :draft false)) + (yaml/generate-string (assoc base-meta + :uuid "2078a34d-1b1a-4257-9eff-ffe215d90bcd" + :draft true + :order 4 + :foo "bar")) + + (yaml/generate-string (assoc base-meta + :uuid "e98ae98f-a621-47f3-a4be-de8b06961f41" + :tags ["tag1" "tag2" "tag3"] + :order 3 + :baz true)) + (yaml/generate-string (assoc base-meta + :uuid "2d4f8006-4a3b-4099-9f7b-3b8c9349a3dc" + :tags ["tag1" "tag2"] + :order 2 + :baz false)) + (yaml/generate-string (assoc base-meta + ;; :uuid + :tags ["tag1" "tag3"] + :order 1 + :baz false)) + (yaml/generate-string (assoc base-meta + ;; :uuid + :tags ["tag2" "tag3"] + :order 0 + :baz true))]) + (def md-content - "--- -email: brent.hagany@gmail.com -uuid: 2078a34d-1b1a-4257-9eff-ffe215d90bcd -draft: true -author: Testy McTesterson ---- -# Hello there + "# Hello there This --- be ___markdown___.") +(def input-strings (map #(str "---\n" % "\n---\n" md-content) yamls)) + (def parsed-md-basic "

Hello there

\n

This --- be markdown.

") (def parsed-md-smarts "

Hello there

\n

This — be markdown.

") @@ -139,8 +171,18 @@ This --- be ___markdown___.") [data] (str "" (:content (:entry data)) "")) +(defn render-assortment + [data] + (let [{:keys [entry entries]} data] + (str "

assortment " (count entries) "

"))) + +(defn render-collection + [data] + (let [{:keys [entry entries]} data] + (str "

collection " (count entries) "

"))) + (deftesttask default-tests [] - (comp (add-txt-file :path "2017-01-01-test.md" :content md-content) + (comp (add-txt-file :path "2017-01-01-test.md" :content (nth input-strings 0)) (boot/with-pre-wrap fileset (pm/set-global-meta fileset {:base-url "http://example.com/" :site-title "Test Title" @@ -164,7 +206,7 @@ This --- be ___markdown___.") (p/word-count) (testing "word-count" (value-test :path "public/2017-01-01-test.html" - :value-fn #(meta= %1 %2 :word-count 19) + :value-fn #(meta= %1 %2 :word-count 22) :msg "`word-count` should set `:word-count` metadata")) (p/gravatar :source-key :email :target-key :gravatar) @@ -218,6 +260,22 @@ This --- be ___markdown___.") (file-exists? :path "public/atom.xml" :msg "`atom-feed` should write atom.xml")) + (add-txt-file :path "test2.md" :content (nth yamls 3)) + (add-txt-file :path "test3.md" :content (nth yamls 4)) + (add-txt-file :path "test4.md" :content (nth yamls 5)) + (add-txt-file :path "test5.md" :content (nth yamls 6)) + (p/markdown) + + (p/assortment :renderer 'io.perun-test/render-assortment) + (testing "assortment" + (content-test :path "public/index.html" + :content "assortment 6")) + + (p/collection :renderer 'io.perun-test/render-collection) + (testing "assortment" + (content-test :path "public/index.html" + :content "collection 7")) + (p/render :renderer 'io.perun-test/render) (add-txt-file :path "test.js" :content js-content) @@ -234,7 +292,7 @@ This --- be ___markdown___.") :msg "`draft` should remove files")))) (deftesttask with-arguments-test [] - (comp (add-txt-file :path "test.md" :content md-content) + (comp (add-txt-file :path "test.md" :content (nth input-strings 0)) (boot/with-pre-wrap fileset (pm/set-global-meta fileset {:base-url "http://example.com/" :site-title "Test Title" @@ -263,7 +321,7 @@ This --- be ___markdown___.") :extensions [".htm"]) (testing "word-count" (value-test :path "hammock/test.htm" - :value-fn #(meta= %1 %2 :word-count 19) + :value-fn #(meta= %1 %2 :word-count 22) :msg "`word-count` should set `:word-count` metadata")) (p/gravatar :source-key :email @@ -343,6 +401,57 @@ This --- be ___markdown___.") (file-exists? :path "foo/test-atom.xml" :msg "`atom-feed` should write test-atom.xml")) + (add-txt-file :path "test2.md" :content (nth input-strings 3)) + (add-txt-file :path "test3.md" :content (nth input-strings 4)) + (add-txt-file :path "test4.md" :content (nth input-strings 5)) + (add-txt-file :path "test5.md" :content (nth input-strings 6)) + (p/markdown :meta {:assorting true} + :out-dir "assorting") + (sift :move {#"assorting/(.*)\.html" "assorting/$1.htm"}) + + (p/assortment :renderer 'io.perun-test/render-assortment + :out-dir "foo" + :grouper (fn [entries] + (reduce (fn [paths {:keys [baz tags] :as entry}] + (let [path (str baz "-" (first tags) ".html")] + (if (and (not (nil? baz)) (seq tags)) + (update-in paths [path :entries] conj entry) + paths))) + {} + entries)) + :filterer :assorting + :extensions [".htm"] + :sortby :order + :comparator #(compare %1 %2) + :meta {:assorted "yep"}) + (testing "assortment" + (content-test :path "foo/true-tag1.html" + :content "assortment 1") + (content-test :path "foo/true-tag2.html" + :content "assortment 1") + (content-test :path "foo/false-tag1.html" + :content "assortment 2") + (value-test :path "foo/true-tag1.html" + :value-fn #(meta= %1 %2 :assorted "yep")) + (value-test :path "foo/true-tag2.html" + :value-fn #(meta= %1 %2 :assorted "yep")) + (value-test :path "foo/false-tag1.html" + :value-fn #(meta= %1 %2 :assorted "yep"))) + + (p/collection :renderer 'io.perun-test/render-collection + :out-dir "bar" + :filterer :baz + :extensions [".htm"] + :sortby :order + :comparator #(compare %1 %2) + :page "its-a-collection.html" + :meta {:collected "uh huh"}) + (testing "collection" + (content-test :path "bar/its-a-collection.html" + :content "collection 2") + (value-test :path "bar/its-a-collection.html" + :value-fn #(meta= %1 %2 :collected "uh huh"))) + (p/render :renderer 'io.perun-test/render :filterer :markdown-set :extensions [".htm"] @@ -366,38 +475,38 @@ This --- be ___markdown___.") (comp (testing "Collection works without input files" ;; #77 (p/collection :renderer 'io.perun-test/render)) - (add-txt-file :path "test.md" :content md-content) + (add-txt-file :path "test.md" :content (nth input-strings 0)) (p/markdown) ;; render once - (add-txt-file :path "test.md" :content (str/replace md-content #"Hello" "Salutations")) + (add-txt-file :path "test.md" :content (str/replace (nth input-strings 0) #"Hello" "Salutations")) (p/markdown) (testing "detecting content changes" (content-test :path "public/test.html" :content "Salutations" :msg "content changes should result in re-rendering")) - (add-txt-file :path "test.md" :content (str/replace md-content #"draft: true" "draft: false")) + (add-txt-file :path "test.md" :content (nth input-strings 1)) (p/markdown) (testing "detecting metadata changes" (value-test :path "public/test.html" :value-fn #(meta= %1 %2 :draft false) :msg "metadata changes should result in re-rendering")) - (add-txt-file :path "test.md" :content (str/replace md-content #"draft: true" "draft: true\nfoo: bar")) + (add-txt-file :path "test.md" :content (nth input-strings 2)) (p/markdown) (testing "detecting metadata additions" (value-test :path "public/test.html" :value-fn #(meta= %1 %2 :foo "bar") :msg "metadata additions should result in re-rendering")) - (add-txt-file :path "test.md" :content md-content) + (add-txt-file :path "test.md" :content (nth input-strings 0)) (p/markdown) (testing "detecting metadata deletions" (value-test :path "public/test.html" :value-fn #(meta= %1 %2 :foo nil) :msg "metadata deletions should result in re-rendering")) - (add-txt-file :path "test2.md" :content md-content) + (add-txt-file :path "test2.md" :content (nth input-strings 3)) (p/markdown) (testing "detecting new files" (content-test :path "public/test2.html" From 9e822226dd21fc29cd34eb9519d01d0e3b8f6990 Mon Sep 17 00:00:00 2001 From: Brent Hagany Date: Wed, 18 Jan 2017 22:11:03 -0600 Subject: [PATCH 18/34] Name test correctly --- test/io/perun_test.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/io/perun_test.clj b/test/io/perun_test.clj index 66e131d3..8160842f 100644 --- a/test/io/perun_test.clj +++ b/test/io/perun_test.clj @@ -272,7 +272,7 @@ This --- be ___markdown___.") :content "assortment 6")) (p/collection :renderer 'io.perun-test/render-collection) - (testing "assortment" + (testing "collection" (content-check :path "public/index.html" :content "collection 7")) From 596c91333b1da143fbcfc1398cd5675615914a5d Mon Sep 17 00:00:00 2001 From: Brent Hagany Date: Thu, 19 Jan 2017 00:34:07 -0600 Subject: [PATCH 19/34] Add `paginate` tests --- test/io/perun_test.clj | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/test/io/perun_test.clj b/test/io/perun_test.clj index 8160842f..3bcbe03e 100644 --- a/test/io/perun_test.clj +++ b/test/io/perun_test.clj @@ -181,6 +181,11 @@ This --- be ___markdown___.") (let [{:keys [entry entries]} data] (str "

collection " (count entries) "

"))) +(defn render-paginate + [data] + (let [{:keys [entry entries]} data] + (str "

paginate " (count entries) "

"))) + (deftesttask default-tests [] (comp (add-txt-file :path "2017-01-01-test.md" :content (nth input-strings 0)) (boot/with-pre-wrap fileset @@ -276,6 +281,11 @@ This --- be ___markdown___.") (content-check :path "public/index.html" :content "collection 7")) + (p/paginate :renderer 'io.perun-test/render-paginate) + (testing "paginate" + (content-check :path "public/page-1.html" + :content "paginate 7")) + (p/render :renderer 'io.perun-test/render) (add-txt-file :path "test.js" :content js-content) @@ -452,6 +462,23 @@ This --- be ___markdown___.") (value-check :path "bar/its-a-collection.html" :value-fn #(meta= %1 %2 :collected "uh huh"))) + (p/paginate :renderer 'io.perun-test/render-paginate + :out-dir "baz" + :prefix "decomplect-" + :page-size 2 + :filterer :assorting + :extensions [".htm"] + :sortby :prder + :comparator #(compare %1 %2) + :meta {:paginated "mmhmm"}) + (testing "paginate" + (content-check :path "baz/decomplect-1.html" + :content "paginate 2") + (content-check :path "baz/decomplect-2.html" + :content "paginate 2") + (content-check :path "baz/decomplect-3.html" + :content "paginate 1")) + (p/render :renderer 'io.perun-test/render :filterer :markdown-set :extensions [".htm"] From 0f2914e69e91db5c223dd10e90396673fb233220 Mon Sep 17 00:00:00 2001 From: Brent Hagany Date: Thu, 19 Jan 2017 01:06:12 -0600 Subject: [PATCH 20/34] Fix assortment tests --- test/io/perun_test.clj | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/io/perun_test.clj b/test/io/perun_test.clj index 8160842f..a54dd8d5 100644 --- a/test/io/perun_test.clj +++ b/test/io/perun_test.clj @@ -260,10 +260,10 @@ This --- be ___markdown___.") (file-exists? :path "public/atom.xml" :msg "`atom-feed` should write atom.xml")) - (add-txt-file :path "test2.md" :content (nth yamls 3)) - (add-txt-file :path "test3.md" :content (nth yamls 4)) - (add-txt-file :path "test4.md" :content (nth yamls 5)) - (add-txt-file :path "test5.md" :content (nth yamls 6)) + (add-txt-file :path "test2.md" :content (nth input-strings 3)) + (add-txt-file :path "test3.md" :content (nth input-strings 4)) + (add-txt-file :path "test4.md" :content (nth input-strings 5)) + (add-txt-file :path "test5.md" :content (nth input-strings 6)) (p/markdown) (p/assortment :renderer 'io.perun-test/render-assortment) From 4e77fdffa01855c1b44877fc5f0557722192ca06 Mon Sep 17 00:00:00 2001 From: Brent Hagany Date: Thu, 19 Jan 2017 01:13:02 -0600 Subject: [PATCH 21/34] typo --- test/io/perun_test.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/io/perun_test.clj b/test/io/perun_test.clj index 3bcbe03e..1f3e7b5a 100644 --- a/test/io/perun_test.clj +++ b/test/io/perun_test.clj @@ -468,7 +468,7 @@ This --- be ___markdown___.") :page-size 2 :filterer :assorting :extensions [".htm"] - :sortby :prder + :sortby :order :comparator #(compare %1 %2) :meta {:paginated "mmhmm"}) (testing "paginate" From 529521b20514651ecba20efdb114daffdf2b510b Mon Sep 17 00:00:00 2001 From: Brent Hagany Date: Thu, 19 Jan 2017 01:27:36 -0600 Subject: [PATCH 22/34] Add `tags` tests --- test/io/perun_test.clj | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/test/io/perun_test.clj b/test/io/perun_test.clj index a54dd8d5..74a93253 100644 --- a/test/io/perun_test.clj +++ b/test/io/perun_test.clj @@ -181,6 +181,11 @@ This --- be ___markdown___.") (let [{:keys [entry entries]} data] (str "

collection " (count entries) "

"))) +(defn render-tags + [data] + (let [{:keys [entry entries]} data] + (str "

tags " (count entries) "

"))) + (deftesttask default-tests [] (comp (add-txt-file :path "2017-01-01-test.md" :content (nth input-strings 0)) (boot/with-pre-wrap fileset @@ -276,6 +281,15 @@ This --- be ___markdown___.") (content-check :path "public/index.html" :content "collection 7")) + (p/tags :renderer 'io.perun-test/render-tags) + (testing "tags" + (content-check :path "public/tag1.html" + :content "tags 3") + (content-check :path "public/tag2.html" + :content "tags 3") + (content-check :path "public/tag3.html" + :content "tags 3")) + (p/render :renderer 'io.perun-test/render) (add-txt-file :path "test.js" :content js-content) @@ -452,6 +466,27 @@ This --- be ___markdown___.") (value-check :path "bar/its-a-collection.html" :value-fn #(meta= %1 %2 :collected "uh huh"))) + (p/tags :renderer 'io.perun-test/render-tags + :out-dir "baz" + :filterer :assorting + :extensions [".htm"] + :sortby :order + :comparator #(compare %1 %2) + :meta {:tagged "mmhmm"}) + (testing "tags" + (content-check :path "baz/tag1.html" + :content "tags 3") + (content-check :path "baz/tag2.html" + :content "tags 3") + (content-check :path "baz/tag3.html" + :content "tags 3") + (value-check :path "baz/tag1.html" + :value-fn #(meta= %1 %2 :tagged "mmhmm")) + (value-check :path "baz/tag2.html" + :value-fn #(meta= %1 %2 :tagged "mmhmm")) + (value-check :path "baz/tag3.html" + :value-fn #(meta= %1 %2 :tagged "mmhmm"))) + (p/render :renderer 'io.perun-test/render :filterer :markdown-set :extensions [".htm"] From d2ff7c83957b2a90c1018370a865287b6e2a95d3 Mon Sep 17 00:00:00 2001 From: Brent Hagany Date: Thu, 19 Jan 2017 01:29:56 -0600 Subject: [PATCH 23/34] More paginate tests --- test/io/perun_test.clj | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/io/perun_test.clj b/test/io/perun_test.clj index 1f3e7b5a..2a703fc6 100644 --- a/test/io/perun_test.clj +++ b/test/io/perun_test.clj @@ -477,7 +477,13 @@ This --- be ___markdown___.") (content-check :path "baz/decomplect-2.html" :content "paginate 2") (content-check :path "baz/decomplect-3.html" - :content "paginate 1")) + :content "paginate 1") + (value-check :path "baz/decomplect-1.html" + :value-fn #(meta= %1 %2 :paginated "mmhmm")) + (value-check :path "baz/decomplect-2.html" + :value-fn #(meta= %1 %2 :paginated "mmhmm")) + (value-check :path "baz/decomplect-3.html" + :value-fn #(meta= %1 %2 :paginated "mmhmm"))) (p/render :renderer 'io.perun-test/render :filterer :markdown-set From 83e38228926401f780e5b4684e6cef6fb17c33b5 Mon Sep 17 00:00:00 2001 From: Brent Hagany Date: Fri, 20 Jan 2017 17:52:49 -0600 Subject: [PATCH 24/34] Add messages to checks --- test/io/perun_test.clj | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/test/io/perun_test.clj b/test/io/perun_test.clj index a54dd8d5..5d0ec517 100644 --- a/test/io/perun_test.clj +++ b/test/io/perun_test.clj @@ -269,12 +269,14 @@ This --- be ___markdown___.") (p/assortment :renderer 'io.perun-test/render-assortment) (testing "assortment" (content-check :path "public/index.html" - :content "assortment 6")) + :content "assortment 6" + :msg "assortment should modify file contents")) (p/collection :renderer 'io.perun-test/render-collection) (testing "collection" (content-check :path "public/index.html" - :content "collection 7")) + :content "collection 7" + :msg "collection should modify file contents")) (p/render :renderer 'io.perun-test/render) @@ -426,17 +428,23 @@ This --- be ___markdown___.") :meta {:assorted "yep"}) (testing "assortment" (content-check :path "foo/true-tag1.html" - :content "assortment 1") + :content "assortment 1" + :msg "assortment should modify file contents") (content-check :path "foo/true-tag2.html" - :content "assortment 1") + :content "assortment 1" + :msg "assortment should modify file contents") (content-check :path "foo/false-tag1.html" - :content "assortment 2") + :content "assortment 2" + :msg "assortment should modify file contents") (value-check :path "foo/true-tag1.html" - :value-fn #(meta= %1 %2 :assorted "yep")) + :value-fn #(meta= %1 %2 :assorted "yep") + :msg "assortment should modify file metadata") (value-check :path "foo/true-tag2.html" - :value-fn #(meta= %1 %2 :assorted "yep")) + :value-fn #(meta= %1 %2 :assorted "yep") + :msg "assortment should modify file metadata") (value-check :path "foo/false-tag1.html" - :value-fn #(meta= %1 %2 :assorted "yep"))) + :value-fn #(meta= %1 %2 :assorted "yep") + :msg "assortment should modify file metadata")) (p/collection :renderer 'io.perun-test/render-collection :out-dir "bar" @@ -448,9 +456,11 @@ This --- be ___markdown___.") :meta {:collected "uh huh"}) (testing "collection" (content-check :path "bar/its-a-collection.html" - :content "collection 2") + :content "collection 2" + :msg "collection should modify file contents") (value-check :path "bar/its-a-collection.html" - :value-fn #(meta= %1 %2 :collected "uh huh"))) + :value-fn #(meta= %1 %2 :collected "uh huh") + :msg "collection should modify file metadata")) (p/render :renderer 'io.perun-test/render :filterer :markdown-set From ad4e3811f1a0545055cb87dc18e8c4dbfcfe44f3 Mon Sep 17 00:00:00 2001 From: Brent Hagany Date: Sat, 21 Jan 2017 11:06:54 -0600 Subject: [PATCH 25/34] Add messages to checks --- test/io/perun_test.clj | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/test/io/perun_test.clj b/test/io/perun_test.clj index 7f67fb55..c73112e4 100644 --- a/test/io/perun_test.clj +++ b/test/io/perun_test.clj @@ -316,11 +316,14 @@ This --- be ___markdown___.") (p/tags :renderer 'io.perun-test/render-tags) (testing "tags" (content-check :path "public/tag1.html" - :content "tags 3") + :content "tags 3" + :msg "`tags` should write new files") (content-check :path "public/tag2.html" - :content "tags 3") + :content "tags 3" + :msg "`tags` should write new files") (content-check :path "public/tag3.html" - :content "tags 3")) + :content "tags 3" + :msg "`tags` should write new files")) (p/render :renderer 'io.perun-test/render) (testing "render" @@ -519,11 +522,14 @@ This --- be ___markdown___.") :meta {:tagged "mmhmm"}) (testing "tags" (content-check :path "baz/tag1.html" - :content "tags 3") + :content "tags 3" + :msg "`tags` should write new files") (content-check :path "baz/tag2.html" - :content "tags 3") + :content "tags 3" + :msg "`tags` should write new files") (content-check :path "baz/tag3.html" - :content "tags 3") + :content "tags 3" + :msg "`tags` should write new files") (value-check :path "baz/tag1.html" :value-fn #(meta= %1 %2 :tagged "mmhmm")) (value-check :path "baz/tag2.html" From abee4453cf4e8850982f0ad0ad2d66233b94ba62 Mon Sep 17 00:00:00 2001 From: Brent Hagany Date: Sat, 21 Jan 2017 11:08:53 -0600 Subject: [PATCH 26/34] Add messages to checks --- test/io/perun_test.clj | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/test/io/perun_test.clj b/test/io/perun_test.clj index 80c51628..8d89aabc 100644 --- a/test/io/perun_test.clj +++ b/test/io/perun_test.clj @@ -314,7 +314,8 @@ This --- be ___markdown___.") (p/paginate :renderer 'io.perun-test/render-paginate) (testing "paginate" (content-check :path "public/page-1.html" - :content "paginate 7")) + :content "paginate 7" + :msg "`paginate` should write new files")) (p/render :renderer 'io.perun-test/render) (testing "render" @@ -507,17 +508,23 @@ This --- be ___markdown___.") :meta {:paginated "mmhmm"}) (testing "paginate" (content-check :path "baz/decomplect-1.html" - :content "paginate 2") + :content "paginate 2" + :msg "`paginate` should write new files") (content-check :path "baz/decomplect-2.html" - :content "paginate 2") + :content "paginate 2" + :msg "`paginate` should write new files") (content-check :path "baz/decomplect-3.html" - :content "paginate 1") + :content "paginate 1" + :msg "`paginate` should write new files") (value-check :path "baz/decomplect-1.html" - :value-fn #(meta= %1 %2 :paginated "mmhmm")) + :value-fn #(meta= %1 %2 :paginated "mmhmm") + :msg "`paginate` should set metadata") (value-check :path "baz/decomplect-2.html" - :value-fn #(meta= %1 %2 :paginated "mmhmm")) + :value-fn #(meta= %1 %2 :paginated "mmhmm") + :msg "`paginate` should set metadata") (value-check :path "baz/decomplect-3.html" - :value-fn #(meta= %1 %2 :paginated "mmhmm"))) + :value-fn #(meta= %1 %2 :paginated "mmhmm") + :msg "`paginate` should set metadata")) (p/render :renderer 'io.perun-test/render :filterer :markdown-set From 1f9273cd4866007a3403fc6ae8b7daa24f3934da Mon Sep 17 00:00:00 2001 From: Brent Hagany Date: Sat, 21 Jan 2017 20:33:33 -0600 Subject: [PATCH 27/34] Compose multiple checks in a single `testing` form --- test/io/perun_test.clj | 100 +++++++++++++++++++++-------------------- 1 file changed, 52 insertions(+), 48 deletions(-) diff --git a/test/io/perun_test.clj b/test/io/perun_test.clj index e7caa51b..86cebc6e 100644 --- a/test/io/perun_test.clj +++ b/test/io/perun_test.clj @@ -316,15 +316,16 @@ This --- be ___markdown___.") (p/tags :renderer 'io.perun-test/render-tags) (testing "tags" - (content-check :path "public/tag1.html" - :content "tags 3" - :msg "`tags` should write new files") - (content-check :path "public/tag2.html" - :content "tags 3" - :msg "`tags` should write new files") - (content-check :path "public/tag3.html" - :content "tags 3" - :msg "`tags` should write new files")) + (comp + (content-check :path "public/tag1.html" + :content "tags 3" + :msg "`tags` should write new files") + (content-check :path "public/tag2.html" + :content "tags 3" + :msg "`tags` should write new files") + (content-check :path "public/tag3.html" + :content "tags 3" + :msg "`tags` should write new files"))) (p/render :renderer 'io.perun-test/render) (testing "render" @@ -480,24 +481,25 @@ This --- be ___markdown___.") :comparator #(compare %1 %2) :meta {:assorted "yep"}) (testing "assortment" - (content-check :path "foo/true-tag1.html" - :content "assortment 1" - :msg "assortment should modify file contents") - (content-check :path "foo/true-tag2.html" - :content "assortment 1" - :msg "assortment should modify file contents") - (content-check :path "foo/false-tag1.html" - :content "assortment 2" - :msg "assortment should modify file contents") - (value-check :path "foo/true-tag1.html" - :value-fn #(meta= %1 %2 :assorted "yep") - :msg "assortment should modify file metadata") - (value-check :path "foo/true-tag2.html" - :value-fn #(meta= %1 %2 :assorted "yep") - :msg "assortment should modify file metadata") - (value-check :path "foo/false-tag1.html" - :value-fn #(meta= %1 %2 :assorted "yep") - :msg "assortment should modify file metadata")) + (comp + (content-check :path "foo/true-tag1.html" + :content "assortment 1" + :msg "assortment should modify file contents") + (content-check :path "foo/true-tag2.html" + :content "assortment 1" + :msg "assortment should modify file contents") + (content-check :path "foo/false-tag1.html" + :content "assortment 2" + :msg "assortment should modify file contents") + (value-check :path "foo/true-tag1.html" + :value-fn #(meta= %1 %2 :assorted "yep") + :msg "assortment should modify file metadata") + (value-check :path "foo/true-tag2.html" + :value-fn #(meta= %1 %2 :assorted "yep") + :msg "assortment should modify file metadata") + (value-check :path "foo/false-tag1.html" + :value-fn #(meta= %1 %2 :assorted "yep") + :msg "assortment should modify file metadata"))) (p/collection :renderer 'io.perun-test/render-collection :out-dir "bar" @@ -508,12 +510,13 @@ This --- be ___markdown___.") :page "its-a-collection.html" :meta {:collected "uh huh"}) (testing "collection" - (content-check :path "bar/its-a-collection.html" - :content "collection 2" - :msg "collection should modify file contents") - (value-check :path "bar/its-a-collection.html" - :value-fn #(meta= %1 %2 :collected "uh huh") - :msg "collection should modify file metadata")) + (comp + (content-check :path "bar/its-a-collection.html" + :content "collection 2" + :msg "collection should modify file contents") + (value-check :path "bar/its-a-collection.html" + :value-fn #(meta= %1 %2 :collected "uh huh") + :msg "collection should modify file metadata"))) (p/tags :renderer 'io.perun-test/render-tags :out-dir "baz" @@ -523,21 +526,22 @@ This --- be ___markdown___.") :comparator #(compare %1 %2) :meta {:tagged "mmhmm"}) (testing "tags" - (content-check :path "baz/tag1.html" - :content "tags 3" - :msg "`tags` should write new files") - (content-check :path "baz/tag2.html" - :content "tags 3" - :msg "`tags` should write new files") - (content-check :path "baz/tag3.html" - :content "tags 3" - :msg "`tags` should write new files") - (value-check :path "baz/tag1.html" - :value-fn #(meta= %1 %2 :tagged "mmhmm")) - (value-check :path "baz/tag2.html" - :value-fn #(meta= %1 %2 :tagged "mmhmm")) - (value-check :path "baz/tag3.html" - :value-fn #(meta= %1 %2 :tagged "mmhmm"))) + (comp + (content-check :path "baz/tag1.html" + :content "tags 3" + :msg "`tags` should write new files") + (content-check :path "baz/tag2.html" + :content "tags 3" + :msg "`tags` should write new files") + (content-check :path "baz/tag3.html" + :content "tags 3" + :msg "`tags` should write new files") + (value-check :path "baz/tag1.html" + :value-fn #(meta= %1 %2 :tagged "mmhmm")) + (value-check :path "baz/tag2.html" + :value-fn #(meta= %1 %2 :tagged "mmhmm")) + (value-check :path "baz/tag3.html" + :value-fn #(meta= %1 %2 :tagged "mmhmm")))) (p/render :renderer 'io.perun-test/render :filterer :markdown-set From c844b2783111220b74c5a1a8ea7c3e03ee7ad082 Mon Sep 17 00:00:00 2001 From: Brent Hagany Date: Sat, 21 Jan 2017 20:36:10 -0600 Subject: [PATCH 28/34] Compose multiple checks in a single `testing` form --- test/io/perun_test.clj | 71 ++++++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 34 deletions(-) diff --git a/test/io/perun_test.clj b/test/io/perun_test.clj index 0825d77b..d532dc3e 100644 --- a/test/io/perun_test.clj +++ b/test/io/perun_test.clj @@ -472,18 +472,19 @@ This --- be ___markdown___.") :comparator #(compare %1 %2) :meta {:assorted "yep"}) (testing "assortment" - (content-check :path "foo/true-tag1.html" - :content "assortment 1") - (content-check :path "foo/true-tag2.html" - :content "assortment 1") - (content-check :path "foo/false-tag1.html" - :content "assortment 2") - (value-check :path "foo/true-tag1.html" - :value-fn #(meta= %1 %2 :assorted "yep")) - (value-check :path "foo/true-tag2.html" - :value-fn #(meta= %1 %2 :assorted "yep")) - (value-check :path "foo/false-tag1.html" - :value-fn #(meta= %1 %2 :assorted "yep"))) + (comp + (content-check :path "foo/true-tag1.html" + :content "assortment 1") + (content-check :path "foo/true-tag2.html" + :content "assortment 1") + (content-check :path "foo/false-tag1.html" + :content "assortment 2") + (value-check :path "foo/true-tag1.html" + :value-fn #(meta= %1 %2 :assorted "yep")) + (value-check :path "foo/true-tag2.html" + :value-fn #(meta= %1 %2 :assorted "yep")) + (value-check :path "foo/false-tag1.html" + :value-fn #(meta= %1 %2 :assorted "yep")))) (p/collection :renderer 'io.perun-test/render-collection :out-dir "bar" @@ -494,10 +495,11 @@ This --- be ___markdown___.") :page "its-a-collection.html" :meta {:collected "uh huh"}) (testing "collection" - (content-check :path "bar/its-a-collection.html" - :content "collection 2") - (value-check :path "bar/its-a-collection.html" - :value-fn #(meta= %1 %2 :collected "uh huh"))) + (comp + (content-check :path "bar/its-a-collection.html" + :content "collection 2") + (value-check :path "bar/its-a-collection.html" + :value-fn #(meta= %1 %2 :collected "uh huh")))) (p/paginate :renderer 'io.perun-test/render-paginate :out-dir "baz" @@ -509,24 +511,25 @@ This --- be ___markdown___.") :comparator #(compare %1 %2) :meta {:paginated "mmhmm"}) (testing "paginate" - (content-check :path "baz/decomplect-1.html" - :content "paginate 2" - :msg "`paginate` should write new files") - (content-check :path "baz/decomplect-2.html" - :content "paginate 2" - :msg "`paginate` should write new files") - (content-check :path "baz/decomplect-3.html" - :content "paginate 1" - :msg "`paginate` should write new files") - (value-check :path "baz/decomplect-1.html" - :value-fn #(meta= %1 %2 :paginated "mmhmm") - :msg "`paginate` should set metadata") - (value-check :path "baz/decomplect-2.html" - :value-fn #(meta= %1 %2 :paginated "mmhmm") - :msg "`paginate` should set metadata") - (value-check :path "baz/decomplect-3.html" - :value-fn #(meta= %1 %2 :paginated "mmhmm") - :msg "`paginate` should set metadata")) + (comp + (content-check :path "baz/decomplect-1.html" + :content "paginate 2" + :msg "`paginate` should write new files") + (content-check :path "baz/decomplect-2.html" + :content "paginate 2" + :msg "`paginate` should write new files") + (content-check :path "baz/decomplect-3.html" + :content "paginate 1" + :msg "`paginate` should write new files") + (value-check :path "baz/decomplect-1.html" + :value-fn #(meta= %1 %2 :paginated "mmhmm") + :msg "`paginate` should set metadata") + (value-check :path "baz/decomplect-2.html" + :value-fn #(meta= %1 %2 :paginated "mmhmm") + :msg "`paginate` should set metadata") + (value-check :path "baz/decomplect-3.html" + :value-fn #(meta= %1 %2 :paginated "mmhmm") + :msg "`paginate` should set metadata"))) (p/render :renderer 'io.perun-test/render :filterer :markdown-set From b97dca1483c5f578a26d99e8b7670bc2d411b41e Mon Sep 17 00:00:00 2001 From: Brent Hagany Date: Mon, 23 Jan 2017 17:54:10 -0600 Subject: [PATCH 29/34] Add `tags` task to example app --- examples/blog/build.boot | 2 +- examples/blog/resources/2015-04-01-post1.md | 3 +++ examples/blog/resources/2015-05-08-post2.md | 3 +++ examples/blog/src/io/perun/example/tags.clj | 15 +++++++++++++++ 4 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 examples/blog/src/io/perun/example/tags.clj diff --git a/examples/blog/build.boot b/examples/blog/build.boot index ef6749c6..e065d512 100644 --- a/examples/blog/build.boot +++ b/examples/blog/build.boot @@ -22,11 +22,11 @@ (ttr) (word-count) (permalink) - (canonical-url) (build-date) (gravatar :source-key :author-email :target-key :author-gravatar) (render :renderer 'io.perun.example.post/render) (collection :renderer 'io.perun.example.index/render :page "index.html") + (tags :renderer 'io.perun.example.tags/render) (inject-scripts :scripts #{"start.js"}) (sitemap) (rss :description "Hashobject blog") diff --git a/examples/blog/resources/2015-04-01-post1.md b/examples/blog/resources/2015-04-01-post1.md index aec03d06..f4aef257 100644 --- a/examples/blog/resources/2015-04-01-post1.md +++ b/examples/blog/resources/2015-04-01-post1.md @@ -16,6 +16,9 @@ in-language: en keywords: virgo, non simplex, atque, bis placavit, est frondentis aera canonical-url: http://blog.hashobject.com/celebrare-gutture uuid: d24343f7-de07-4ae8-a79e-090f346eddf2 +tags: + - Lorem + - ipsum --- # Celebrare gutture usus nebulas quisquam scitantibus intrepidum diff --git a/examples/blog/resources/2015-05-08-post2.md b/examples/blog/resources/2015-05-08-post2.md index 92355eef..f0a25426 100644 --- a/examples/blog/resources/2015-05-08-post2.md +++ b/examples/blog/resources/2015-05-08-post2.md @@ -16,6 +16,9 @@ in-language: en keywords: eadem oculos veni, mixto manus, virgo canonical-url: http://blog.hashobject.com/fulvaque-viderat uuid: 3c8029ad-db26-4036-8423-7f7ad4078d8c +tags: + - Lorem + - dolor --- Below is just about everything you'll need to style in the theme. Check the source code to see the many embedded elements within paragraphs. diff --git a/examples/blog/src/io/perun/example/tags.clj b/examples/blog/src/io/perun/example/tags.clj new file mode 100644 index 00000000..507b3dae --- /dev/null +++ b/examples/blog/src/io/perun/example/tags.clj @@ -0,0 +1,15 @@ +(ns io.perun.example.tags + (:require [hiccup.page :refer [html5]])) + +(defn render [{global-meta :meta posts :entries entry :entry}] + (html5 {:lang "en" :itemtype "http://schema.org/Blog"} + [:head + [:title (str (:site-title global-meta) "|" (:tag entry))] + [:meta {:charset "utf-8"}] + [:meta {:http-equiv "X-UA-Compatible" :content "IE=edge,chrome=1"}] + [:meta {:name "viewport" :content "width=device-width, initial-scale=1.0, user-scalable=no"}]] + [:body + [:h1 (:title entry)] + [:ul.items.columns.small-12 + (for [post posts] + [:li (:title post)])]])) From 9b96ee9f0d294af6be63e45249b7d54465a22503 Mon Sep 17 00:00:00 2001 From: Brent Hagany Date: Mon, 23 Jan 2017 18:43:28 -0600 Subject: [PATCH 30/34] Use correct map key --- src/io/perun.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/io/perun.clj b/src/io/perun.clj index 18614ecc..93d31d7d 100644 --- a/src/io/perun.clj +++ b/src/io/perun.clj @@ -846,7 +846,7 @@ (let [path (str tag ".html")] (-> result (update-in [path :entries] conj entry) - (assoc-in [path :group-meta :tag] tag)))) + (assoc-in [path :entry :tag] tag)))) {})))] (assortment-pre-wrap {:task-name "tags" :tracer :io.perun/tags From 9ca9893c3f34aa02ca1abcecda3bc047414b9f40 Mon Sep 17 00:00:00 2001 From: Brent Hagany Date: Mon, 23 Jan 2017 18:48:28 -0600 Subject: [PATCH 31/34] Add page number to paginate metadata --- src/io/perun.clj | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/io/perun.clj b/src/io/perun.clj index bcaf1f36..eab65fb7 100644 --- a/src/io/perun.clj +++ b/src/io/perun.clj @@ -848,7 +848,8 @@ (sort-by sortby comparator) (partition-all page-size) (map-indexed #(-> [(str prefix (inc %1) ".html") - {:entries %2}])) + {:entry {:page (inc %1)} + :entries %2}])) (into {})))] (assortment-pre-wrap {:task-name "paginate" :tracer :io.perun/paginate From 24b40a43d842a2356fc1eec016415e86022fe891 Mon Sep 17 00:00:00 2001 From: Brent Hagany Date: Mon, 23 Jan 2017 18:48:54 -0600 Subject: [PATCH 32/34] Add `paginate` to example blog --- examples/blog/build.boot | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/blog/build.boot b/examples/blog/build.boot index ef6749c6..bcd506d4 100644 --- a/examples/blog/build.boot +++ b/examples/blog/build.boot @@ -22,11 +22,11 @@ (ttr) (word-count) (permalink) - (canonical-url) (build-date) (gravatar :source-key :author-email :target-key :author-gravatar) (render :renderer 'io.perun.example.post/render) (collection :renderer 'io.perun.example.index/render :page "index.html") + (paginate :renderer 'io.perun.example.paginate/render) (inject-scripts :scripts #{"start.js"}) (sitemap) (rss :description "Hashobject blog") From ce9722cbc7d91daa25eaf6c4974a70e77bd12d0c Mon Sep 17 00:00:00 2001 From: Brent Hagany Date: Mon, 23 Jan 2017 18:49:58 -0600 Subject: [PATCH 33/34] Add missing source file --- examples/blog/src/io/perun/example/paginate.clj | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 examples/blog/src/io/perun/example/paginate.clj diff --git a/examples/blog/src/io/perun/example/paginate.clj b/examples/blog/src/io/perun/example/paginate.clj new file mode 100644 index 00000000..ac86b5e2 --- /dev/null +++ b/examples/blog/src/io/perun/example/paginate.clj @@ -0,0 +1,15 @@ +(ns io.perun.example.paginate + (:require [hiccup.page :refer [html5]])) + +(defn render [{global-meta :meta posts :entries entry :entry}] + (html5 {:lang "en" :itemtype "http://schema.org/Blog"} + [:head + [:title (str (:site-title global-meta) "|" (:tag entry))] + [:meta {:charset "utf-8"}] + [:meta {:http-equiv "X-UA-Compatible" :content "IE=edge,chrome=1"}] + [:meta {:name "viewport" :content "width=device-width, initial-scale=1.0, user-scalable=no"}]] + [:body + [:h1 (str "Page " (:page entry))] + [:ul.items.columns.small-12 + (for [post posts] + [:li (:title post)])]])) From 831e7121d2d73b7f6c65830c2adcf37e6858994a Mon Sep 17 00:00:00 2001 From: Brent Hagany Date: Mon, 23 Jan 2017 19:29:39 -0600 Subject: [PATCH 34/34] Add `assortment` to example blog --- examples/blog/build.boot | 17 +++++++++++++++-- .../blog/src/io/perun/example/assortment.clj | 15 +++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 examples/blog/src/io/perun/example/assortment.clj diff --git a/examples/blog/build.boot b/examples/blog/build.boot index ef6749c6..f9e9852f 100644 --- a/examples/blog/build.boot +++ b/examples/blog/build.boot @@ -5,7 +5,8 @@ [hiccup "1.0.5"] [pandeiro/boot-http "0.6.3-SNAPSHOT"]]) -(require '[io.perun :refer :all] +(require '[clojure.string :as str] + '[io.perun :refer :all] '[io.perun.example.index :as index-view] '[io.perun.example.post :as post-view] '[pandeiro.boot-http :refer [serve]]) @@ -22,11 +23,23 @@ (ttr) (word-count) (permalink) - (canonical-url) (build-date) (gravatar :source-key :author-email :target-key :author-gravatar) (render :renderer 'io.perun.example.post/render) (collection :renderer 'io.perun.example.index/render :page "index.html") + (assortment :renderer 'io.perun.example.assortment/render + :grouper (fn [entries] + (->> entries + (mapcat (fn [entry] + (if-let [kws (:keywords entry)] + (map #(-> [% entry]) (str/split kws #"\s*,\s*")) + []))) + (reduce (fn [result [kw entry]] + (let [path (str kw ".html")] + (-> result + (update-in [path :entries] conj entry) + (assoc-in [path :entry :keyword] kw)))) + {})))) (inject-scripts :scripts #{"start.js"}) (sitemap) (rss :description "Hashobject blog") diff --git a/examples/blog/src/io/perun/example/assortment.clj b/examples/blog/src/io/perun/example/assortment.clj new file mode 100644 index 00000000..15f87f43 --- /dev/null +++ b/examples/blog/src/io/perun/example/assortment.clj @@ -0,0 +1,15 @@ +(ns io.perun.example.assortment + (:require [hiccup.page :refer [html5]])) + +(defn render [{global-meta :meta posts :entries entry :entry}] + (html5 {:lang "en" :itemtype "http://schema.org/Blog"} + [:head + [:title (str (:site-title global-meta) "|" (:keyword entry))] + [:meta {:charset "utf-8"}] + [:meta {:http-equiv "X-UA-Compatible" :content "IE=edge,chrome=1"}] + [:meta {:name "viewport" :content "width=device-width, initial-scale=1.0, user-scalable=no"}]] + [:body + [:h1 (str "Page " (:page entry))] + [:ul.items.columns.small-12 + (for [post posts] + [:li (:title post)])]]))