Skip to content

Commit b013a6f

Browse files
committed
feat: Add about page example
This is done by calling a parse-org function, the result of composing slurp and another function by the same name from clj-org.org. This lets us easily call parse-org on a path in the site.clj and get the hiccup content back.
1 parent 9b283aa commit b013a6f

File tree

3 files changed

+44
-3
lines changed

3 files changed

+44
-3
lines changed

example/blog/about.org

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#+TITLE: Sur Moi
2+
#+TAGS: foo bar baz
3+
4+
* A blog page!
5+
6+
Now /this/ is content!
7+
8+
9+
** A subheading
10+
11+
Woah
12+
13+
* What about formatting?
14+
15+
A list?
16+
17+
- *BOLD*
18+
- /Italic/
19+
- ~fixed-width~
20+
21+
#+BEGIN_SRC clojure
22+
(defn hello
23+
([] "Greetings, nerd")
24+
([name] (format "Greetings %s" name)))
25+
26+
(hello "friend")
27+
#+END_SRC

example/site.clj

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,15 @@
1313
(stylesheet global-style)]
1414
[:body content]])
1515

16+
(def-asset about-page
17+
{:path "/about.html"
18+
:type :html
19+
:data (let [{title :title
20+
content :content}
21+
(parse-org "./example/blog/about.org")]
22+
(page title content))})
23+
1624
(def-asset home-page
1725
{:path "/index.html"
1826
:type :html
19-
:data (page "Hello world" [:p "This is magic"])})
27+
:data (page "Hello world" [:a {:href (asset-path about-page)} "This is a blog link."])})

src/teknql/statik/core.clj

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@
7070
'[garden.core
7171
garden.stylesheet
7272
garden.color
73-
garden.units
74-
clj-org.org])
73+
garden.units])
7574

7675
(defn- ns->src-path
7776
"Utility to take a required namespace and load a src path with it"
@@ -83,6 +82,12 @@
8382
(str/replace "." "/"))
8483
".clj"))
8584

85+
(defn parse-org [path]
86+
"Take a path and return a map of title and content."
87+
(-> path
88+
(slurp)
89+
(clj-org.org/parse-org)))
90+
8691
(defn eval-string
8792
"Ealuates the provided string. Returns a list of assets defined by the file."
8893
[s]
@@ -103,6 +108,7 @@
103108
'user) {'def-asset def-asset
104109
'asset-path asset-path
105110
'stylesheet stylesheet
111+
'parse-org parse-org
106112
'register-asset! #(swap! assets conj %)}}
107113
(map (juxt identity ns-interns) included-namespaces))})
108114
@assets))

0 commit comments

Comments
 (0)