 (defn ^:export genpages [opts]
   (log "Generating site")
   (swap! config merge (js->clj opts :keywordize-keys true))
-  (let [dir (:site-dir @config)
-        timestamp (str "?" (js/Date.now))]
-    (doseq [f (:pages @config)]
-      (write-file (path-join dir (dbg (as-relative f)))
-                  (gen-page f timestamp)))
-    (write-resources dir))
+  (let [{:keys [site-dir pages] :as conf} @config
+        conf (assoc conf :timestamp (str "?" (js/Date.now)))]
+    (doseq [f pages]
+      (write-file (path-join site-dir (as-relative f))
+                  (gen-page f conf)))
+    (write-resources site-dir conf))
   (log "Wrote site"))
 
 (defn start! [site-config]

       [:link {:href (str css-file timestamp) :rel 'stylesheet}]
       [:title title]]
      [:body
       [:div {:id main-div} (danger :div body)]
       (danger :script (str "var pageConfig = "
                            (-> page-conf clj->js js/JSON.stringify)))
       [:script {:src main :type "text/javascript"}]]])))

(defn gen-page [page-name timestamp]
  (dispatch [:set-page page-name])
  (let [b (r/render-component-to-string (body))]
    (str "<!doctype html>"
         (html-template {:title (:title @config)
                         :body b
                         :page-conf {:page-name page-name}
                         :timestamp timestamp}))))

(defn mkdirs [f]
  (let [fs (js/require "fs")

                 (js->clj js/pageConfig :keywordize-keys true))]
      (swap! config merge conf)
      (init-history)
      (r/render-component (:body @config)
                          (js/document.getElementById (:main-div @config))))))
