diff --git a/assets/style.css b/assets/style.css new file mode 100644 index 0000000..0b8b4bf --- /dev/null +++ b/assets/style.css @@ -0,0 +1,19 @@ +*, *:before, *:after { + box-sizing: border-box; +} + +html, body { + padding: 0; + margin: 0; +} + +body { + background: #fefefe; +} + +path { + stroke: rebeccapurple; + fill: transparent; + stroke-width: 1.5px; + stroke-linecap: round; +} diff --git a/assets/ten-print.svg b/assets/ten-print.svg new file mode 100644 index 0000000..b146c26 --- /dev/null +++ b/assets/ten-print.svg @@ -0,0 +1 @@ + diff --git a/index.janet b/index.janet index 468d13b..fcce193 100644 --- a/index.janet +++ b/index.janet @@ -14,13 +14,44 @@ (bagatto/set-output-dir! "site") -(def data {:config {:attrs {:title "arnes.space"}} - :posts {:src (bagatto/slurp-* "posts/*.md") - :attrs bagatto/parse-mmarkdown}}) +(defn struct->table [s] + (table ;(interleave (keys s) (values s)))) + +(defn path->date [path] + (let [datestr (->> + (string/split "/" path) + (last) + (string/split "--") + (first)) + date (struct->table (bagatto/datestr->date datestr true))] + # we have to massage the struct a bit because by default the date is + # interpreted as a local date and converted to UTC. + # NOTE: we don't fix year-day because we'd have to check for leap years. + (put date :hours 0) + (update date :month-day inc) + (update date :week-day (comp |(mod $0 7) inc)))) + +(defn parse-post [slurped item] + (let [post (bagatto/parse-mmarkdown slurped item) ] + (put post :published-at (path->date (post :path))) + post)) + +(def data {:config {:attrs {:title "arnes.space" + :stylesheet "assets/style.css"}} + :assets {:src (bagatto/* "assets/*") + :attrs bagatto/parse-base} + :posts {:src (bagatto/slurp-* "content/posts/*.md") + :attrs parse-post}}) (def site {:index {:dest "index.html" - :out (views/base data [:h1 "Hello World!"])} - :posts {:each :posts - :dest (bagatto/%p "posts" '%i "title" '% ".html") - :out (fn [data item] - (views/base data (bagatto/mmarkdown->html (item :contents)) true))}}) + :out views/home} + :assets {:each :assets + :dest (bagatto/path-copier "assets/")} + :posts {:each :posts + :dest utils/slugify-content + :out views/post}}) + +(comment + (->> + (eval-data data) + (eval-site site))) diff --git a/utils.janet b/utils.janet new file mode 100644 index 0000000..6309904 --- /dev/null +++ b/utils.janet @@ -0,0 +1,13 @@ +(defn slugify-content + ``` + Converts a path from the content folder into the path of the rendered html. + ``` + [site &opt item] + (when item + (let [parts (string/split "/" (item :path)) + file (last parts)] + (string/join [;(slice parts 1 -2) (string (first (string/split "." file)) ".html")] "/")))) + +(comment + (slugify-content {} "content/posts/2021-07-07--let-there-be-light.md")) + diff --git a/views.janet b/views.janet index 24f5463..9ceadf7 100644 --- a/views.janet +++ b/views.janet @@ -1,9 +1,12 @@ (import janet-html :as html) +(import ./utils) + +# defining the basic structure of each page +# thanks to https://css-tricks.com/emojis-as-favicons/ (defn as-html [h] (html/encode (html/doctype :html5) [:html h])) -# thanks to https://css-tricks.com/emojis-as-favicons/ (def favicon "data:image/svg+xml,🌌") @@ -13,19 +16,8 @@ [:title (get-in data [:config :title])] [:link {:rel "icon" :href favicon}] - [:style - [``` - body { - background: #fefefe; - } - - path { - stroke: rebeccapurple; - fill: transparent; - stroke-width: 1.5px; - stroke-linecap: round; - } - ```]]]) + [:link {:rel "stylesheet" + :href (get-in data [:config :stylesheet])}]]) # below are some functions we need for the unique svgs generated for each page # arc drawing in svg is a bit messy. these two links helped me: @@ -96,6 +88,30 @@ (default raw? false) (as-html [(html-head data) [:body - [:header - (ten-print body) ] - (if raw? (html/raw body) body) ]])) + [:main + [:header + (ten-print body)] + [:article (if raw? (html/raw body) body)]]]])) + +# +# different page types +# + +(defn debug [jdn] + (string/format "%j" jdn)) + +(defn home [data] + (base data + [[:h1 "Projects"] + [:ul + [:li "Berliner Winter"] + [:li "Vanilla Sky"] + [:li "All My Friends"] + [:li "Kosmopolit"]] + [:h1 "Recent Posts"] + [:ul + (map (fn [post] + [:li [:a {:href (utils/slugify-content data post)} (post "title")]]) (data :posts))]])) + +(defn post [data item] + (base data (bagatto/mmarkdown->html (item :contents)) true))