This commit was merged in pull request #27.
This commit is contained in:
@@ -4,10 +4,8 @@
|
|||||||
:latex "xelatex"
|
:latex "xelatex"
|
||||||
:dvisvgm "dvisvgm"
|
:dvisvgm "dvisvgm"
|
||||||
:doerg-temml-worker
|
:doerg-temml-worker
|
||||||
#profile {:dev-publisher "../doerg/doerg-temml-worker/index.js"
|
#profile {:dev #file "../../../../doerg-temml-worker/index.js"
|
||||||
:dev-doerg "./doerg-temml-worker/index.js"
|
|
||||||
:default "doerg-temml-worker"}
|
:default "doerg-temml-worker"}
|
||||||
:doerg-parser
|
:doerg-parser
|
||||||
#profile {:dev-publisher "../doerg/doerg-parser/index.js"
|
#profile {:dev #file "../../../../doerg-parser/index.js"
|
||||||
:dev-doerg "./doerg-parser/index.js"
|
|
||||||
:default "doerg-parser"}}
|
:default "doerg-parser"}}
|
||||||
|
|||||||
BIN
doerg/resources/net/deertopia/doerg/favicon.ico
Normal file
BIN
doerg/resources/net/deertopia/doerg/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 66 KiB |
1
doerg/resources/net/deertopia/doerg/public/Temml-Plex.css
Symbolic link
1
doerg/resources/net/deertopia/doerg/public/Temml-Plex.css
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../Temml-Plex.css
|
||||||
1
doerg/resources/net/deertopia/doerg/public/deerstar.css
Symbolic link
1
doerg/resources/net/deertopia/doerg/public/deerstar.css
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../deerstar.css
|
||||||
1
doerg/resources/net/deertopia/doerg/public/tuftesque.css
Symbolic link
1
doerg/resources/net/deertopia/doerg/public/tuftesque.css
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../tuftesque.css
|
||||||
@@ -45,29 +45,35 @@
|
|||||||
(and (fs/exists? x) x))
|
(and (fs/exists? x) x))
|
||||||
(fs/split-paths (System/getenv "XDG_DATA_DIRS"))))
|
(fs/split-paths (System/getenv "XDG_DATA_DIRS"))))
|
||||||
|
|
||||||
(defn make-read-config [spec]
|
(defmethod aero/reader 'file
|
||||||
(fn [& files]
|
[{:keys [source]} tag value]
|
||||||
(let [r (->> files
|
"Aero tag to reference a `java.io.File` relative to the config
|
||||||
(filter identity)
|
file."
|
||||||
(map aero/read-config)
|
(-> (aero/relative-resolver source value)
|
||||||
(apply merge))
|
fs/file))
|
||||||
conformed (s/conform spec r)]
|
|
||||||
(if-not (s/invalid? conformed)
|
|
||||||
conformed
|
|
||||||
(throw (IllegalArgumentException.
|
|
||||||
"bad config"
|
|
||||||
(ex-info "couldn't conform"
|
|
||||||
(s/explain-data spec r))))))))
|
|
||||||
|
|
||||||
(def read-config (make-read-config ::d/config))
|
(defn read-config [spec files & {:as opts}]
|
||||||
|
(let [r (->> files
|
||||||
|
(filter identity)
|
||||||
|
(map #(aero/read-config % opts))
|
||||||
|
(apply merge))
|
||||||
|
conformed (s/conform spec r)]
|
||||||
|
(if-not (s/invalid? conformed)
|
||||||
|
conformed
|
||||||
|
(throw (ex-info "Failed to conform config"
|
||||||
|
(s/explain-data spec r))))))
|
||||||
|
|
||||||
(def default
|
(defn load-config! [var spec files & {:as opts}]
|
||||||
(read-config
|
(alter-var-root var (constantly (read-config spec files opts))))
|
||||||
;; Default config.
|
|
||||||
|
(def sources
|
||||||
|
[;; Default config.
|
||||||
(io/resource "net/deertopia/doerg/default-config.edn")
|
(io/resource "net/deertopia/doerg/default-config.edn")
|
||||||
;; Defaults set at build time, if any.
|
;; Defaults set at build time, if any.
|
||||||
(io/resource "net/deertopia/doerg/extra-config.edn")
|
(io/resource "net/deertopia/doerg/extra-config.edn")
|
||||||
;; Config set at runtime.
|
;; Config set at runtime.
|
||||||
(System/getenv "DOERG_CONFIG")))
|
(System/getenv "DOERG_CONFIG")])
|
||||||
|
|
||||||
|
(def default (read-config ::d/config sources))
|
||||||
|
|
||||||
(def ^:dynamic *cfg* default)
|
(def ^:dynamic *cfg* default)
|
||||||
|
|||||||
@@ -27,7 +27,7 @@
|
|||||||
[:meta {:charset "utf-8"}])
|
[:meta {:charset "utf-8"}])
|
||||||
|
|
||||||
(defn external-stylesheet [href]
|
(defn external-stylesheet [href]
|
||||||
[:link {:rel "stylesheet" :type "text/css" :href href}])
|
[:link {:rel "stylesheet" :type "text/css" :href (str "/resource/" href)}])
|
||||||
|
|
||||||
(def ibm-plex
|
(def ibm-plex
|
||||||
(concat
|
(concat
|
||||||
|
|||||||
@@ -179,7 +179,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
(defn- render-pprint
|
(defn render-pprint
|
||||||
"Render the argument inline as `clojure.pprint/pprint` output."
|
"Render the argument inline as `clojure.pprint/pprint` output."
|
||||||
[x & {:keys [text]
|
[x & {:keys [text]
|
||||||
:or {text "debug!"}}]
|
:or {text "debug!"}}]
|
||||||
|
|||||||
@@ -31,17 +31,17 @@
|
|||||||
(defn render-html [& {:keys [src dest]
|
(defn render-html [& {:keys [src dest]
|
||||||
:or {src some-org-file
|
:or {src some-org-file
|
||||||
dest "/tmp/doerg-test"}}]
|
dest "/tmp/doerg-test"}}]
|
||||||
(fs/create-dirs dest)
|
(let [resource-dir (fs/file dest "resource")]
|
||||||
(force-create-sym-link (fs/file dest "ibm-plex-web")
|
(fs/create-dirs dest)
|
||||||
(-> cfg/*cfg* ::doerg/ibm-plex-web))
|
(fs/create-dirs resource-dir)
|
||||||
(force-create-sym-link (fs/file dest "deerstar.css")
|
(force-create-sym-link (fs/file resource-dir "ibm-plex-web")
|
||||||
(io/resource "net/deertopia/doerg/deerstar.css"))
|
(-> cfg/*cfg* ::doerg/ibm-plex-web))
|
||||||
(force-create-sym-link (fs/file dest "tuftesque.css")
|
(doseq [x #{"Temml-Plex.css" "tuftesque.css" "deerstar.css"}]
|
||||||
(io/resource "net/deertopia/doerg/tuftesque.css"))
|
(force-create-sym-link
|
||||||
(force-create-sym-link (fs/file dest "Temml-Plex.css")
|
(fs/file resource-dir x)
|
||||||
(io/resource "net/deertopia/doerg/Temml-Plex.css"))
|
(io/resource (str "net/deertopia/doerg/" x))))
|
||||||
(fs/delete-if-exists (fs/file dest "index.html"))
|
(fs/delete-if-exists (fs/file dest "index.html"))
|
||||||
(->> src render/to-html str (spit (fs/file dest "index.html"))))
|
(->> src render/to-html str (spit (fs/file dest "index.html")))))
|
||||||
|
|
||||||
(defn render-edn [& {:keys [src dest]
|
(defn render-edn [& {:keys [src dest]
|
||||||
:or {src some-org-file
|
:or {src some-org-file
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
((nil
|
((nil
|
||||||
. ((cider-clojure-cli-aliases . ":dev")
|
. ((cider-clojure-cli-aliases . ":dev:test")
|
||||||
(eval
|
;; (eval
|
||||||
. (progn
|
;; . (progn
|
||||||
(defun start-deertopia-server ()
|
;; (defun start-deertopia-server ()
|
||||||
(let ((n (cider-format-connection-params "%j" cider-launch-params)))
|
;; (let ((n (cider-format-connection-params "%j" cider-launch-params)))
|
||||||
(when (equal n "net-deertopia")
|
;; (when (equal n "net-deertopia")
|
||||||
(cider-interactive-eval
|
;; (cider-interactive-eval
|
||||||
"(do (require '[net.deertopia.publisher.server :as server])
|
;; "(do (require '[net.deertopia.publisher.server :as server])
|
||||||
(server/start!))"))))
|
;; (server/start!))"))))
|
||||||
(add-hook 'cider-connected-hook #'start-deertopia-server))))))
|
;; (add-hook 'cider-connected-hook #'start-deertopia-server)))
|
||||||
|
)))
|
||||||
|
|||||||
@@ -17,4 +17,5 @@
|
|||||||
:aliases
|
:aliases
|
||||||
{:test {:extra-deps {lambdaisland/kaocha {:mvn/version "1.91.1392"}}
|
{:test {:extra-deps {lambdaisland/kaocha {:mvn/version "1.91.1392"}}
|
||||||
:extra-paths ["test"]
|
:extra-paths ["test"]
|
||||||
:main-opts ["-m" "kaocha.runner"]}}}
|
:main-opts ["-m" "kaocha.runner"]}
|
||||||
|
:dev {:extra-paths ["dev"]}}}
|
||||||
|
|||||||
24
publisher/dev/user.clj
Normal file
24
publisher/dev/user.clj
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
(ns user
|
||||||
|
(:require [net.deertopia.publisher.server :as server]
|
||||||
|
[net.deertopia.doerg :as-alias doerg]
|
||||||
|
[net.deertopia.publisher :as-alias publisher]
|
||||||
|
[net.deertopia.doerg.config :as doerg-config]
|
||||||
|
[net.deertopia.publisher.config :as publisher-config]
|
||||||
|
[babashka.fs :as fs]))
|
||||||
|
|
||||||
|
(doerg-config/load-config! #'doerg-config/*cfg*
|
||||||
|
::doerg/config
|
||||||
|
doerg-config/sources
|
||||||
|
:profile :dev)
|
||||||
|
|
||||||
|
(doerg-config/load-config! #'publisher-config/*cfg*
|
||||||
|
::publisher/config
|
||||||
|
publisher-config/sources
|
||||||
|
:profile :dev)
|
||||||
|
|
||||||
|
(when (not= :running (server/status))
|
||||||
|
(server/start!))
|
||||||
|
|
||||||
|
(defn invalidate-html-cache! []
|
||||||
|
(fs/delete-tree (server/html-dir))
|
||||||
|
nil)
|
||||||
@@ -2,5 +2,7 @@
|
|||||||
{:state-directory #join [#or [#env XDG_STATE_HOME
|
{:state-directory #join [#or [#env XDG_STATE_HOME
|
||||||
#envf ["%s/.local/share" HOME]]
|
#envf ["%s/.local/share" HOME]]
|
||||||
"/doerg-publisher"]
|
"/doerg-publisher"]
|
||||||
:org-roam-db-path #join [#env HOME "/.cache/emacs/org-roam.db"]
|
:org-roam-db-path
|
||||||
:port 8080}
|
#profile {:default #join [#env HOME "/.cache/emacs/org-roam.db"]
|
||||||
|
:test #file "../../../../test/net/deertopia/publisher/roam-test.db"}
|
||||||
|
:port #profile {:default 8080}}
|
||||||
|
|||||||
@@ -20,5 +20,6 @@
|
|||||||
(when (or (not *use-cache?*) stale?)
|
(when (or (not *use-cache?*) stale?)
|
||||||
(let [r (compute)]
|
(let [r (compute)]
|
||||||
(assert (string? r))
|
(assert (string? r))
|
||||||
|
(fs/create-dirs (fs/parent file))
|
||||||
(spit file r)))
|
(spit file r)))
|
||||||
file)
|
file)
|
||||||
|
|||||||
@@ -14,15 +14,15 @@
|
|||||||
(s/def ::p/state-directory ::doerg/file)
|
(s/def ::p/state-directory ::doerg/file)
|
||||||
(s/def ::p/org-roam-db-path ::doerg/file)
|
(s/def ::p/org-roam-db-path ::doerg/file)
|
||||||
|
|
||||||
(def read-config (doerg-config/make-read-config ::p/config))
|
(def sources
|
||||||
|
[;; Default config.
|
||||||
(def default
|
|
||||||
(read-config
|
|
||||||
;; Default config.
|
|
||||||
(io/resource "net/deertopia/publisher/default-config.edn")
|
(io/resource "net/deertopia/publisher/default-config.edn")
|
||||||
;; Defaults set at build time, if any.
|
;; Defaults set at build time, if any.
|
||||||
(io/resource "net/deertopia/publisher/extra-config.edn")
|
(io/resource "net/deertopia/publisher/extra-config.edn")
|
||||||
;; Config set at runtime.
|
;; Config set at runtime.
|
||||||
(System/getenv "DOERG_PUBLISHER_CONFIG")))
|
(System/getenv "DOERG_PUBLISHER_CONFIG")])
|
||||||
|
|
||||||
|
(def default
|
||||||
|
(doerg-config/read-config ::p/config sources))
|
||||||
|
|
||||||
(def ^:dynamic *cfg* default)
|
(def ^:dynamic *cfg* default)
|
||||||
|
|||||||
@@ -12,13 +12,10 @@
|
|||||||
|
|
||||||
(defonce ^:dynamic *use-db-cache?* true)
|
(defonce ^:dynamic *use-db-cache?* true)
|
||||||
|
|
||||||
(def db-path (-> cfg/*cfg* ::publisher/org-roam-db-path
|
(defn- ds []
|
||||||
fs/expand-home str))
|
(sql/get-datasource
|
||||||
|
{:dbtype "sqlite"
|
||||||
(def db {:dbtype "sqlite"
|
:dbname (-> cfg/*cfg* ::publisher/org-roam-db-path str)}))
|
||||||
:dbname db-path})
|
|
||||||
|
|
||||||
(def ds (sql/get-datasource db))
|
|
||||||
|
|
||||||
|
|
||||||
;;; Elisp sexp (de)serialisation
|
;;; Elisp sexp (de)serialisation
|
||||||
@@ -37,8 +34,14 @@
|
|||||||
|
|
||||||
(defrecord Node [id cache])
|
(defrecord Node [id cache])
|
||||||
|
|
||||||
|
(defn- uuid-exists? [uuid]
|
||||||
|
(sql/execute-one! (ds)
|
||||||
|
["select 1 from nodes where id = ? limit 1"
|
||||||
|
(-> uuid str elisp/print)]))
|
||||||
|
|
||||||
(defn make-node [uuid]
|
(defn make-node [uuid]
|
||||||
(->Node uuid (atom {})))
|
(and (uuid-exists? uuid)
|
||||||
|
(->Node uuid (atom {}))))
|
||||||
|
|
||||||
(defn- fetch-with-cache [node field fetch]
|
(defn- fetch-with-cache [node field fetch]
|
||||||
(if *use-db-cache?*
|
(if *use-db-cache?*
|
||||||
@@ -53,7 +56,7 @@
|
|||||||
node :org-file
|
node :org-file
|
||||||
(fn [node]
|
(fn [node]
|
||||||
(when-some [r (sql/execute-one!
|
(when-some [r (sql/execute-one!
|
||||||
ds
|
(ds)
|
||||||
["select file from nodes where id = ?"
|
["select file from nodes where id = ?"
|
||||||
(-> node :id str elisp/print)])]
|
(-> node :id str elisp/print)])]
|
||||||
(-> r :nodes/file elisp/read-string)))))
|
(-> r :nodes/file elisp/read-string)))))
|
||||||
@@ -84,7 +87,7 @@
|
|||||||
(fetch-with-cache
|
(fetch-with-cache
|
||||||
node :title
|
node :title
|
||||||
#(do (println "fetch")
|
#(do (println "fetch")
|
||||||
(sql/execute-one! ds ["select title from nodes where id = ?"
|
(sql/execute-one! (ds) ["select title from nodes where id = ?"
|
||||||
(elisp/print (:id %))]))))
|
(elisp/print (:id %))]))))
|
||||||
|
|
||||||
|
|
||||||
@@ -94,7 +97,7 @@
|
|||||||
(fetch-with-cache
|
(fetch-with-cache
|
||||||
node :level
|
node :level
|
||||||
#(-> (sql/execute-one!
|
#(-> (sql/execute-one!
|
||||||
ds ["select level from nodes where id = ?"
|
(ds) ["select level from nodes where id = ?"
|
||||||
(print-id %)])
|
(print-id %)])
|
||||||
:nodes/level)))
|
:nodes/level)))
|
||||||
|
|
||||||
@@ -105,7 +108,7 @@
|
|||||||
(fetch-with-cache
|
(fetch-with-cache
|
||||||
node :file
|
node :file
|
||||||
#(-> (sql/execute-one!
|
#(-> (sql/execute-one!
|
||||||
ds ["select file from nodes where id = ?"
|
(ds) ["select file from nodes where id = ?"
|
||||||
(print-id %)])
|
(print-id %)])
|
||||||
:nodes/file
|
:nodes/file
|
||||||
elisp/read-string)))
|
elisp/read-string)))
|
||||||
@@ -114,7 +117,7 @@
|
|||||||
(fetch-with-cache
|
(fetch-with-cache
|
||||||
node :properties
|
node :properties
|
||||||
#(-> (sql/execute-one!
|
#(-> (sql/execute-one!
|
||||||
ds ["select properties from nodes where id = ?"
|
(ds) ["select properties from nodes where id = ?"
|
||||||
(print-id %)])
|
(print-id %)])
|
||||||
:nodes/properties
|
:nodes/properties
|
||||||
elisp/read-alist)))
|
elisp/read-alist)))
|
||||||
@@ -130,7 +133,7 @@
|
|||||||
"Returns a collection of maps {:id …, :title …}."
|
"Returns a collection of maps {:id …, :title …}."
|
||||||
[node]
|
[node]
|
||||||
(for [{id :nodes/id, title :nodes/title}
|
(for [{id :nodes/id, title :nodes/title}
|
||||||
(sql/execute! ds ["select distinct nodes.id, nodes.title from links
|
(sql/execute! (ds) ["select distinct nodes.id, nodes.title from links
|
||||||
inner join nodes
|
inner join nodes
|
||||||
on nodes.id = links.source
|
on nodes.id = links.source
|
||||||
where links.dest = ?"
|
where links.dest = ?"
|
||||||
@@ -150,9 +153,9 @@
|
|||||||
(-> uuid parse-uuid get-node graph-visible?))
|
(-> uuid parse-uuid get-node graph-visible?))
|
||||||
|
|
||||||
(defn get-graph []
|
(defn get-graph []
|
||||||
(let [nodes (sql/execute! ds ["select id, title from nodes"])
|
(let [nodes (sql/execute! (ds) ["select id, title from nodes"])
|
||||||
links (sql/execute!
|
links (sql/execute!
|
||||||
ds
|
(ds)
|
||||||
["select n1.id as source, nodes.id as target from
|
["select n1.id as source, nodes.id as target from
|
||||||
((nodes as n1) join links on n1.id = links.source)
|
((nodes as n1) join links on n1.id = links.source)
|
||||||
join (nodes as n2) on links.dest = nodes.id
|
join (nodes as n2) on links.dest = nodes.id
|
||||||
|
|||||||
@@ -22,11 +22,17 @@
|
|||||||
[net.deertopia.doerg.render :as doerg-render]
|
[net.deertopia.doerg.render :as doerg-render]
|
||||||
[net.deertopia.publisher.cached-file :as cached-file]
|
[net.deertopia.publisher.cached-file :as cached-file]
|
||||||
[babashka.fs :as fs]
|
[babashka.fs :as fs]
|
||||||
[aero.core :as aero]))
|
[aero.core :as aero]
|
||||||
|
[clojure.string :as str]
|
||||||
|
[net.deertopia.doerg :as-alias doerg]
|
||||||
|
[net.deertopia.doerg.config :as doerg-config]))
|
||||||
|
|
||||||
|
|
||||||
;;; Routes
|
;;; Routes
|
||||||
|
|
||||||
|
(def homepage-slug "68XqhHerTWCbE--RYLEdHw")
|
||||||
|
(def not-found-slug "PGDHTvUzQ62Js1Y5db-A8g")
|
||||||
|
|
||||||
(defn hello [req]
|
(defn hello [req]
|
||||||
(-> (hiccup/html {}
|
(-> (hiccup/html {}
|
||||||
[:html
|
[:html
|
||||||
@@ -42,11 +48,37 @@
|
|||||||
response/response
|
response/response
|
||||||
(response/content-type "text/html")))
|
(response/content-type "text/html")))
|
||||||
|
|
||||||
(defn node-by-slug [{{{:keys [slug]} :path} :parameters}]
|
(defn html-dir []
|
||||||
(let [html (-> slug slug/from-string roam/get-node
|
(-> cfg/*cfg* ::publisher/state-directory (fs/file "html")))
|
||||||
roam/org-file doerg-render/to-html)]
|
|
||||||
(-> html response/response
|
(defn not-found [req]
|
||||||
(response/content-type "text/html"))))
|
(response/not-found "not found"))
|
||||||
|
|
||||||
|
(defn org-file->html-file [org-file]
|
||||||
|
(fs/file (html-dir)
|
||||||
|
(-> org-file
|
||||||
|
fs/file-name
|
||||||
|
(fs/strip-ext {:ext "org"})
|
||||||
|
(str ".html"))))
|
||||||
|
|
||||||
|
(defmethod doerg-render/org-link "id"
|
||||||
|
[{:keys [path raw-link children]}]
|
||||||
|
[:span.org-link
|
||||||
|
[:a {:href (str "/n/" (slug/from-uuid path))}
|
||||||
|
(or (seq children) raw-link)]])
|
||||||
|
|
||||||
|
(defn node-by-slug [{{:keys [slug]} :path-params :as req}]
|
||||||
|
(if-some [node (some-> slug slug/from-string roam/get-node)]
|
||||||
|
(let [org-file (roam/org-file node)
|
||||||
|
html-file (org-file->html-file org-file)]
|
||||||
|
(cached-file/cached-file
|
||||||
|
:file html-file
|
||||||
|
:stale? (cached-file/newer-than? org-file html-file)
|
||||||
|
:compute #(doerg-render/to-html org-file))
|
||||||
|
(-> (str html-file)
|
||||||
|
response/file-response
|
||||||
|
(response/content-type "text/html")))
|
||||||
|
(not-found req)))
|
||||||
|
|
||||||
(defn node-by-id [req]
|
(defn node-by-id [req]
|
||||||
(hello req))
|
(hello req))
|
||||||
@@ -60,17 +92,39 @@
|
|||||||
(l/error e "error in fucking somwhere dude")
|
(l/error e "error in fucking somwhere dude")
|
||||||
(handler e request))})))
|
(handler e request))})))
|
||||||
|
|
||||||
|
(defn handle-homepage [req]
|
||||||
|
(-> req
|
||||||
|
(assoc-in [:path-params :slug] homepage-slug)
|
||||||
|
node-by-slug))
|
||||||
|
|
||||||
|
(def doerg-resources
|
||||||
|
#{"Temml-Plex.css" "tuftesque.css" "deerstar.css"})
|
||||||
|
|
||||||
|
(defn handle-resource [{:keys [uri]}]
|
||||||
|
(if-some [[_ resource] (re-matches #"^/resource/ibm-plex-web/(.*)" uri)]
|
||||||
|
(-> resource
|
||||||
|
(response/file-response
|
||||||
|
{:root (-> doerg-config/*cfg* ::doerg/ibm-plex-web str)}))
|
||||||
|
(-> uri
|
||||||
|
(str/replace-first #"^/resource/" "")
|
||||||
|
(response/resource-response
|
||||||
|
{:root "net/deertopia/doerg/public"
|
||||||
|
:allow-symlinks? true}))))
|
||||||
|
|
||||||
|
(defn handle-favicon [_]
|
||||||
|
(response/resource-response "net/deertopia/doerg/favicon.ico"))
|
||||||
|
|
||||||
(def router
|
(def router
|
||||||
(reitit.ring/router
|
(reitit.ring/router
|
||||||
#{["/" {:get hello}]
|
#{["/" #'handle-homepage]
|
||||||
["/n/:slug"
|
["/n/:slug" #'node-by-slug]
|
||||||
{:get {:handler #'node-by-slug
|
["/id/:id" #'node-by-id]
|
||||||
:parameters
|
["/resource/*" #'handle-resource]
|
||||||
{:path {:slug ::slug/slug}}}}]
|
["/myreq" #'hello]
|
||||||
["/id/:id" {:get #'node-by-id}]}
|
["/favicon.ico" #'handle-favicon]}
|
||||||
{:validate reitit.spec/validate
|
{:validate reitit.spec/validate
|
||||||
:exception reitit.dev.pretty/exception
|
:exception reitit.dev.pretty/exception
|
||||||
:spec (s/merge :reitit.spec/default-data)
|
:spec :reitit.spec/default-data
|
||||||
:data
|
:data
|
||||||
{:coercion reitit.coercion.spec/coercion
|
{:coercion reitit.coercion.spec/coercion
|
||||||
:middleware [exception-middleware
|
:middleware [exception-middleware
|
||||||
|
|||||||
BIN
publisher/test/net/deertopia/publisher/roam-test.db
Normal file
BIN
publisher/test/net/deertopia/publisher/roam-test.db
Normal file
Binary file not shown.
@@ -0,0 +1,7 @@
|
|||||||
|
:PROPERTIES:
|
||||||
|
:ID: 23ee464d-b13e-4649-826f-622d0edef24e
|
||||||
|
:DeertopiaVisibility: public
|
||||||
|
:END:
|
||||||
|
#+title: awesome file
|
||||||
|
|
||||||
|
wow!
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
:PROPERTIES:
|
||||||
|
:ID: ebc5ea84-77ab-4d60-9b13-ef9160b11d1f
|
||||||
|
:END:
|
||||||
|
#+title: deertopia.net!!!!!!!!
|
||||||
|
|
||||||
|
homeee
|
||||||
@@ -2,23 +2,64 @@
|
|||||||
(:require [net.deertopia.publisher.server :as sut]
|
(:require [net.deertopia.publisher.server :as sut]
|
||||||
[reitit.ring]
|
[reitit.ring]
|
||||||
[clojure.test :as t]
|
[clojure.test :as t]
|
||||||
[clojure.set :as set]
|
[net.deertopia.publisher.config :as publisher-cfg]
|
||||||
[net.deertopia.publisher.server :as server]
|
[net.deertopia.doerg.config :as doerg-cfg]
|
||||||
[net.deertopia.publisher.config :as cfg]
|
[net.deertopia.publisher :as-alias publisher]
|
||||||
[net.deertopia.publisher :as-alias publisher]))
|
[net.deertopia.doerg :as-alias doerg]
|
||||||
|
[net.deertopia.publisher.roam :as roam]))
|
||||||
|
|
||||||
|
(defn config-fixture [f]
|
||||||
|
(binding [doerg-cfg/*cfg*
|
||||||
|
(doerg-cfg/read-config
|
||||||
|
::doerg/config doerg-cfg/sources
|
||||||
|
:profile :test)
|
||||||
|
publisher-cfg/*cfg*
|
||||||
|
(doerg-cfg/read-config
|
||||||
|
::publisher/config publisher-cfg/sources
|
||||||
|
:profile :test)]
|
||||||
|
(f)))
|
||||||
|
|
||||||
|
(t/use-fixtures
|
||||||
|
:once config-fixture)
|
||||||
|
|
||||||
|
(defn with-server [f]
|
||||||
|
(let [was-already-running? (= :running (sut/status))]
|
||||||
|
(when-not was-already-running?
|
||||||
|
(sut/start!))
|
||||||
|
(f)
|
||||||
|
(when-not was-already-running?
|
||||||
|
(sut/stop!))))
|
||||||
|
|
||||||
|
(defn get-sut [uri]
|
||||||
|
(sut/app {:request-method :get
|
||||||
|
:uri uri}))
|
||||||
|
|
||||||
(t/deftest server-is-running
|
(t/deftest server-is-running
|
||||||
;; 서버가 벌써 시작한 다음에 이 테스트 하면 잘못됩니다.
|
;; 서버는 벌써 시작한 다음에 이 테스트 하면 잘못됩니다.
|
||||||
(assert (not= :running (server/status)))
|
;; (assert (not= :running (sut/status)))
|
||||||
(server/start!)
|
(with-server
|
||||||
(t/is (= :running (server/status)))
|
(fn []
|
||||||
(server/stop!))
|
(t/is (= :running (sut/status)))
|
||||||
|
;; 테스트 데이터베이스를 아직 안 준비한다.
|
||||||
|
#_(t/is (->> (format "http://localhost:%d"
|
||||||
|
(::publisher/port publisher-cfg/*cfg*))
|
||||||
|
slurp
|
||||||
|
string?)))))
|
||||||
|
|
||||||
(t/deftest can-get-real-server-root
|
(comment
|
||||||
;; 서버가 벌써 시작한 다음에 이 테스트 하면 잘못됩니다.
|
;; 테스트 데이터베이스를 아직 안 준비한다.
|
||||||
(assert (not= :running (server/status)))
|
(t/deftest get-nonexistent-node
|
||||||
(server/start!)
|
(let [slug "3Lxvxnb0QrivoU3DX-l_5w"]
|
||||||
(t/is (->> (format "http://localhost:%d" (::publisher/port cfg/*cfg*))
|
(assert (nil? (roam/make-node slug)))
|
||||||
slurp
|
(t/is (= 404
|
||||||
string?))
|
(-> (str "/n/" slug)
|
||||||
(server/stop!))
|
get-sut :status))))))
|
||||||
|
|
||||||
|
(comment
|
||||||
|
;; 테스트 데이터베이스를 아직 안 준비한다.
|
||||||
|
(t/deftest get-homepage
|
||||||
|
(let [resp (-> (str "/n/" sut/homepage-slug)
|
||||||
|
get-sut)]
|
||||||
|
(t/is (= 200 (:status resp)))
|
||||||
|
(t/is (= (-> "/" get-sut :body)
|
||||||
|
(-> resp :body))))))
|
||||||
|
|||||||
Reference in New Issue
Block a user