My personal website, goal is to have a blog and a "resume".

building_azrazalea.net.html.post 3.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. ;;;;;
  2. title: Building Azrazalea.net
  3. tags: website
  4. date: 2014-11-24
  5. author: Lily Carpenter
  6. format: md
  7. ;;;;;
  8. #### Updates
  9. * 2015-10-21T09:21:00Z Updated published/updated timestamp to be iso8601 format.
  10. * 2017-05-15T00:10:00Z Fix various broken links.
  11. After many years of my domain leading to an "Under Construction" page, I decided that it was time for me to actually sit down and write a website. I decided I wanted to use [Clojure](http://clojure.org) since it was my new favorite language to play with and started down my usual route of a MVC based site. As I played with [Compojure](https://github.com/weavejester/compojure) and [Korma](http://sqlkorma.com/) I realized that for a simple blog/portfolio based site MVC was overkill.
  12. I scrapped my original idea and researched static site generation in Clojure. I quickly found a [blog post](http://cjohansen.no/building-static-sites-in-clojure-with-stasis) by Christian Johansen on using [Stasis](https://github.com/magnars/stasis) and other Clojure libraries (see this site's [gitlab](https://gitlab.com/azrazalea/azrazalea.net) for a full list[no longer accurate since site has been rebuilt]) to setup a basic static site with a developer server.
  13. However, this basic template was not complete enough for my site as-is. Primarily, I needed more dynamic control over the site layout/templating. For instance I wanted the site title to be generated based on a formatted version of the file name of the page. The formatting itself was easily accomplished:
  14. ```scheme
  15. (defn format-title [title]
  16. (str/join " "
  17. (map str/capitalize
  18. (str/split
  19. (str/replace title #"(.*/|\.html)" "")
  20. #"_"))))
  21. ```
  22. I did find myself with a small problem. I ended up needing to map over a hash-map and format the key then pass the formatted key to a function along with the value. I didn't find a function that already does this, so I imagine there was a different way to do it. In the end, I ended up with this function to perform this:
  23. ```scheme
  24. ;; This is probably a case of me not knowing a better way to do this...
  25. ;; my-map is a hash-map
  26. ;; key-func takes a key and returns a key
  27. ;; val-func takes the formatted key and the val and returns a key
  28. (defn map-map-with-funcs [key-func val-func my-map]
  29. (apply merge (map (fn [[k v]]
  30. (let [new-key (key-func k)]
  31. (hash-map new-key (val-func new-key v))))
  32. my-map)))
  33. ```
  34. I ended up using this function like this, where pages is a hash-map with the key being the filename and the value being the contents of the file:
  35. ```scheme
  36. (defn partial-pages [pages]
  37. (map-map-with-funcs #(str/replace % #"\.clj$" "")
  38. #(fn [req]
  39. (layout-page req %1 (load-string %2)))
  40. pages))
  41. ```
  42. I am new to clojure so I imagine this is neither idomatic nor efficient (for instance, my map-map-with-funcs function may be better written as a macro). However, it is certainly working for my purposes.
  43. The best part of all of this is that in the end, what I have is a bunch of minimized html/css/js that is easily served by [Nginx](http://nginx.org/en/) making a very low resource site that easily runs on my small [Linode](https://www.linode.com/) instance. I also got some practice using Clojure.
  44. My next steps are to include some kind of hosted comments (I need to research options) so that I can get feedback from the readers of the site and continue to write blog posts (and talk at local meetups).