Browse Source

Render org documents as html pages

master
Daniel Revere 8 years ago
parent
commit
87f1188162
  1. 4
      project.clj
  2. 7
      src/blog_clj/git.clj
  3. 5
      src/blog_clj/posts.clj
  4. 40
      src/blog_clj/tags.clj

4
project.clj

@ -7,11 +7,13 @@
[clj-time "0.13.0"] [clj-time "0.13.0"]
[compojure "1.6.0"] [compojure "1.6.0"]
[environ "1.1.0"] [environ "1.1.0"]
[org.clojars.gmorpheme/organum "0.1.1"]
[jarohen/chime "0.2.1"] [jarohen/chime "0.2.1"]
[org.clojure/clojure "1.8.0"] [org.clojure/clojure "1.8.0"]
[ring/ring-defaults "0.3.0"] [ring/ring-defaults "0.3.0"]
[ring/ring-jetty-adapter "1.6.1"] [ring/ring-jetty-adapter "1.6.1"]
[ring/ring-ssl "0.3.0"]] [ring/ring-ssl "0.3.0"]
[clj-org "0.0.2"]]
:plugins [[lein-environ "1.1.0"] :plugins [[lein-environ "1.1.0"]
[lein-ring "0.9.7"] [lein-ring "0.9.7"]
[environ/environ.lein "0.3.1"]] [environ/environ.lein "0.3.1"]]

7
src/blog_clj/git.clj

@ -5,6 +5,8 @@
[clj-time.periodic :refer [periodic-seq]] [clj-time.periodic :refer [periodic-seq]]
[clj-jgit.porcelain :as jgit] [clj-jgit.porcelain :as jgit]
[cheshire.core :as json] [cheshire.core :as json]
;; [organum.core :as org]
[clj-org.org :as org]
[clojure.string :as str]) [clojure.string :as str])
(:import [java.io FileNotFoundException])) (:import [java.io FileNotFoundException]))
@ -39,7 +41,10 @@
(.startsWith (.toAbsolutePath (.toPath file)) (.startsWith (.toAbsolutePath (.toPath file))
(.toAbsolutePath (.toPath dir)))) (.toAbsolutePath (.toPath dir))))
(defn assoc-id [body]
(assoc body :id (org/header-value-for "ID" (:headers body))))
(defn fetch-data [] (defn fetch-data []
(into #{} (map #(-> % slurp (json/parse-string true)) (into #{} (map #(-> % slurp org/parse-org assoc-id)
(rest (remove #(is-inside? % (io/as-file (str local-repo "/.git"))) (rest (remove #(is-inside? % (io/as-file (str local-repo "/.git")))
(file-seq (io/file local-repo))))))) (file-seq (io/file local-repo)))))))

5
src/blog_clj/posts.clj

@ -3,7 +3,6 @@
[blog-clj.git :as git])) [blog-clj.git :as git]))
(defn posts [] (defn posts []
;; [{:title "foo" :id "bar"}]
(git/fetch-data)) (git/fetch-data))
(defn get-post [id] (defn get-post [id]
@ -11,11 +10,11 @@
(defn page [id] (defn page [id]
(let [post (get-post id) (let [post (get-post id)
{:keys [title body date]} post] {:keys [title body date content]} post]
[:div [:div
[:h3 title] [:h3 title]
[:h6 date] [:h6 date]
[:p body]])) content]))
;; (defn tags [] ;; (defn tags []
;; (sort ;; (sort

40
src/blog_clj/tags.clj

@ -1,22 +1,22 @@
(ns blog-clj.tags ;; (ns blog-clj.tags
(:require [blog-clj.piece :as piece])) ;; (:require [blog-clj.piece :as piece]))
(defn has-tag [piece tag] ;; (defn has-tag [piece tag]
(let [{:keys [tags]} piece] ;; (let [{:keys [tags]} piece]
(some #(= tag %) tags))) ;; (some #(= tag %) tags)))
(defn page [tag] ;; (defn page [tag]
[:body ;; [:body
[:div.container ;; [:div.container
[:div.jumbotron.text-center ;; [:div.jumbotron.text-center
[:h1 "Nomad Expo"] ;; [:h1 "Nomad Expo"]
[:h4 "tag: " tag]] ;; [:h4 "tag: " tag]]
(let [pieces (filter #(has-tag % tag) piece/pieces)] ;; (let [pieces (filter #(has-tag % tag) piece/pieces)]
(for [piece (sort-by :promoted? ;; (for [piece (sort-by :promoted?
#(- (compare % %2)) ;; #(- (compare % %2))
pieces)] ;; pieces)]
(let [{:keys [id name url logo desc creator promoted?]} piece] ;; (let [{:keys [id name url logo desc creator promoted?]} piece]
[:div.panel.panel-default ;; [:div.panel.panel-default
[:div.panel-body {:class (if promoted? "promoted")} ;; [:div.panel-body {:class (if promoted? "promoted")}
[:a {:href (str "/piece/" id)} [:h2 name]] ;; [:a {:href (str "/piece/" id)} [:h2 name]]
[:p {:align "right"} desc]]])))]]) ;; [:p {:align "right"} desc]]])))]])

Loading…
Cancel
Save