Flesh out page structure

This commit is contained in:
heyarne 2021-07-29 21:53:42 +02:00
commit 85e79a8090
5 changed files with 105 additions and 25 deletions

19
assets/style.css Normal file
View file

@ -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;
}

1
assets/ten-print.svg Normal file

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 7.5 KiB

View file

@ -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)))

13
utils.janet Normal file
View file

@ -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"))

View file

@ -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,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>🌌</text></svg>")
@ -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))