Skip to content

Commit

Permalink
feat: Add about page example
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
the-alex committed Nov 24, 2020
1 parent 9b283aa commit b013a6f
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
27 changes: 27 additions & 0 deletions example/blog/about.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#+TITLE: Sur Moi
#+TAGS: foo bar baz

* A blog page!

Now /this/ is content!


** A subheading

Woah

* What about formatting?

A list?

- *BOLD*
- /Italic/
- ~fixed-width~

#+BEGIN_SRC clojure
(defn hello
([] "Greetings, nerd")
([name] (format "Greetings %s" name)))

(hello "friend")
#+END_SRC
10 changes: 9 additions & 1 deletion example/site.clj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@
(stylesheet global-style)]
[:body content]])

(def-asset about-page
{:path "/about.html"
:type :html
:data (let [{title :title
content :content}
(parse-org "./example/blog/about.org")]
(page title content))})

(def-asset home-page
{:path "/index.html"
:type :html
:data (page "Hello world" [:p "This is magic"])})
:data (page "Hello world" [:a {:href (asset-path about-page)} "This is a blog link."])})
10 changes: 8 additions & 2 deletions src/teknql/statik/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@
'[garden.core
garden.stylesheet
garden.color
garden.units
clj-org.org])
garden.units])

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

(defn parse-org [path]
"Take a path and return a map of title and content."
(-> path
(slurp)
(clj-org.org/parse-org)))

(defn eval-string
"Ealuates the provided string. Returns a list of assets defined by the file."
[s]
Expand All @@ -103,6 +108,7 @@
'user) {'def-asset def-asset
'asset-path asset-path
'stylesheet stylesheet
'parse-org parse-org
'register-asset! #(swap! assets conj %)}}
(map (juxt identity ns-interns) included-namespaces))})
@assets))

0 comments on commit b013a6f

Please sign in to comment.