-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.clj
66 lines (62 loc) · 2.29 KB
/
index.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
;; # 🎄 Advent of Clerk
;;
;; [Advent of Code](https://adventofcode.com) with
;; [Clerk](https://clerk.vision).
;;
;; Solutions authored by [@elken](https://github.com/elken/) with love in Clojure. 💕
;;
;; Below is a listing of all my solutions grouped by year.
;;
;; All the solutions also include the original problem spec, along with my commentary.
;;
;; Should be obvious, but this will fully spoil any days; so if you haven't yet
;; completed a particular day I would suggest you do so first. But, I'm also not
;; your parent so go nuts.
;;
;; Greatly inspired by [advent of clerk](https://github.com/nextjournal/advent-of-clerk)
(ns index
{:nextjournal.clerk/visibility {:code :hide :result :hide}}
(:require
[babashka.fs :as fs]
[nextjournal.clerk :as clerk]
[nextjournal.clerk.view :as clerk.view]
[clojure.java.io :as io]
[clojure.string :as str]
[util :as u]))
(alter-var-root #'clerk.view/include-css+js
(fn [include-css+js-orig extra-includes]
(fn [state]
(concat (include-css+js-orig state)
extra-includes)))
(list [:style#extra-styles (slurp (clojure.java.io/resource "style.css"))]))
(defn build-paths []
(-> "src/solutions"
fs/list-dir
(fs/list-dirs "*.clj")
sort))
(defn group-solutions []
(->> (build-paths)
(group-by
(fn [path]
(let [[_ _ year _] (fs/components path)]
(str year))))
(sort-by first)))
{:nextjournal.clerk/visibility {:result :show}}
^::clerk/no-cache
(clerk/html
(into [:div]
(mapv (fn [[year paths]]
[:details
[:summary
[:span.text-2xl.font-bold year]
[:span.ml-10 (format "(%s solutions)" (count paths))]]
(into [:ul]
(mapv (fn [path]
(when-let [day (second (re-matches #".*day(\d+).clj" path))]
[:li
[:a {:href (-> path
(str/replace ".clj" "")
clerk/doc-url)}
(util/load-title day year)]]))
(map str paths)))])
(group-solutions))))