From d26ee9923d0f04c6e971366f472e42469d843f3f Mon Sep 17 00:00:00 2001 From: Charlotte Allen Date: Mon, 27 Jan 2020 23:58:10 -0800 Subject: [PATCH 1/3] Add basic author config --- .gitignore | 1 + resources/author/sample_user | 8 ++++++++ 2 files changed, 9 insertions(+) create mode 100644 resources/author/sample_user diff --git a/.gitignore b/.gitignore index 8885ace..dd72772 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,4 @@ profiles.clj /log *.swp resources/posts/ +/resources/author/ diff --git a/resources/author/sample_user b/resources/author/sample_user new file mode 100644 index 0000000..946a3b5 --- /dev/null +++ b/resources/author/sample_user @@ -0,0 +1,8 @@ +{ + :first-name nil + :family-name nil + :rel-me [] + :job-title nil + :org nil + :photo nil +} From 0d8a203c3c8cac2b174c9845d42d1d2a6910f2db Mon Sep 17 00:00:00 2001 From: Charlotte Allen Date: Tue, 28 Jan 2020 16:23:05 -0800 Subject: [PATCH 2/3] Add means to record and display an author --- resources/author/sample_user | 15 +++++++----- resources/html/h_card.html | 18 ++++++++++++++ src/clj/shapey_shifty/authors/author_core.clj | 24 +++++++++++++++++++ src/clj/shapey_shifty/routes/home.clj | 12 ++++++---- 4 files changed, 59 insertions(+), 10 deletions(-) create mode 100644 resources/html/h_card.html create mode 100644 src/clj/shapey_shifty/authors/author_core.clj diff --git a/resources/author/sample_user b/resources/author/sample_user index 946a3b5..9f1a777 100644 --- a/resources/author/sample_user +++ b/resources/author/sample_user @@ -1,8 +1,11 @@ { - :first-name nil - :family-name nil - :rel-me [] - :job-title nil - :org nil - :photo nil + :card { + :first-name nil + :family-name nil + :rel-me [] + :job-title nil + :org nil + :photo nil + } + :password-hash nil } diff --git a/resources/html/h_card.html b/resources/html/h_card.html new file mode 100644 index 0000000..c76989f --- /dev/null +++ b/resources/html/h_card.html @@ -0,0 +1,18 @@ +{% block card %} + +
+ +

{{ card.first-name }} {{ card.family-name }}

+ +
+ +{% endblock %} + diff --git a/src/clj/shapey_shifty/authors/author_core.clj b/src/clj/shapey_shifty/authors/author_core.clj new file mode 100644 index 0000000..94a9297 --- /dev/null +++ b/src/clj/shapey_shifty/authors/author_core.clj @@ -0,0 +1,24 @@ +(ns shapey-shifty.authors.author-core + (:require [clojure.edn :as edn] + [clojure.java.io :as io])) + +(def base-path "resources/author") + +(defn create-author [] + {:card nil :password-hash nil}) + +(defn load-author [author-name] + (let [path (format "%s/%s" base-path author-name) + file (io/file path)] + (when (.exists file) + (->> file + slurp + edn/read-string)))) + +(defn load-all-authors [] + (->> base-path + io/file + file-seq + (filter #(.isFile %)) + (map #(->> % slurp edn/read-string)))) + diff --git a/src/clj/shapey_shifty/routes/home.clj b/src/clj/shapey_shifty/routes/home.clj index 9334e72..6ba1d7e 100644 --- a/src/clj/shapey_shifty/routes/home.clj +++ b/src/clj/shapey_shifty/routes/home.clj @@ -7,6 +7,7 @@ [shapey-shifty.posts.core :as posts] [shapey-shifty.posts.posts-io :as post-io] [shapey-shifty.routes.post-router :as post-router] + [shapey-shifty.authors.author-core :as author] [ring.util.http-response :as response])) (def p (atom 0)) @@ -19,12 +20,15 @@ (defn post-view [request] (let [{:keys [path-params query-params body-params]} request - {:keys [year month day n]} path-params] + {:keys [year month day n]} path-params] (do (reset! p request) - (layout/render request "post.html" {:post (:properties (post-router/get-post year month day n))})))) + (layout/render request "post.html" {:post (:properties (post-router/get-post year month day n))})))) (defn about-page [request] - (layout/render request "about.html")) + (layout/render request "h_card.html" + { + :card (:card (author/load-author (get-in request [:path-params :name]))) + })) (defn home-routes [] ["" @@ -32,5 +36,5 @@ middleware/wrap-formats]} ["/" {:get home-page}] ["/blog/:year/:month/:day/:n" {:get post-view}] - ["/about" {:get about-page}]]) + ["/about/:name" {:get about-page}]]) From 0676034b7d83047d4c94c4c9f63c3f4cb3d68c51 Mon Sep 17 00:00:00 2001 From: Charlotte Allen Date: Tue, 28 Jan 2020 17:42:18 -0800 Subject: [PATCH 3/3] Implement tiny h-card for posts --- resources/html/post.html | 3 +++ resources/html/tiny_h_card.html | 5 +++++ src/clj/shapey_shifty/posts/posts_io.clj | 23 ++++++++++++++++------- src/clj/shapey_shifty/routes/home.clj | 9 ++++----- 4 files changed, 28 insertions(+), 12 deletions(-) create mode 100644 resources/html/tiny_h_card.html diff --git a/resources/html/post.html b/resources/html/post.html index eed501c..5f992a4 100644 --- a/resources/html/post.html +++ b/resources/html/post.html @@ -1,6 +1,9 @@ {% extends "base.html" %} {% block content %}
+
+ {% include "tiny_h_card.html" %} +

{{post.name}}

{{post.content}}

diff --git a/resources/html/tiny_h_card.html b/resources/html/tiny_h_card.html new file mode 100644 index 0000000..6bced6d --- /dev/null +++ b/resources/html/tiny_h_card.html @@ -0,0 +1,5 @@ +{% block card %} + +{{card.first-name}} {{card.family-name}} + +{% endblock %} diff --git a/src/clj/shapey_shifty/posts/posts_io.clj b/src/clj/shapey_shifty/posts/posts_io.clj index fd0112a..13ca6a1 100644 --- a/src/clj/shapey_shifty/posts/posts_io.clj +++ b/src/clj/shapey_shifty/posts/posts_io.clj @@ -1,9 +1,10 @@ (ns shapey-shifty.posts.posts-io (:require - [shapey-shifty.posts.core :as core])) + [shapey-shifty.posts.core :as core] + [shapey-shifty.authors.author-core :as author])) (def post-filename "post.json") -(def base-path "resources/posts") +(def base-posts-path "resources/posts") (defn create-path-by-date [year month day] {:year year :month month :day day}) @@ -13,7 +14,7 @@ (defn count-posts-in-date [dt-path] (let [path (pathmap-to-path dt-path) - final-path (format "%s/%s" base-path path)] + final-path (format "%s/%s" base-posts-path path)] (->> final-path clojure.java.io/file file-seq @@ -24,14 +25,22 @@ (defn write-post [post dt-path] (let [path (pathmap-to-path dt-path) increment (inc (count-posts-in-date dt-path)) - final-path (format "%s/%s/%d/%s" base-path path increment post-filename)] + final-path (format "%s/%s/%d/%s" base-posts-path path increment post-filename)] (clojure.java.io/make-parents final-path) (spit final-path post))) +(defn assoc-author [post] + (let [filename (get-in post [:properties :author]) + author (author/load-author filename) + card (get author :card)] + (assoc post :author card))) + (defn read-post [dt-path n] - (let [path (format "%s/%s/%s/%s" base-path (pathmap-to-path dt-path) n post-filename) + (let [path (format "%s/%s/%s/%s" base-posts-path (pathmap-to-path dt-path) n post-filename) f (clojure.java.io/file path)] (when (.exists f) (-> f - slurp - read-string)))) + slurp + read-string + assoc-author + )))) diff --git a/src/clj/shapey_shifty/routes/home.clj b/src/clj/shapey_shifty/routes/home.clj index 6ba1d7e..6999519 100644 --- a/src/clj/shapey_shifty/routes/home.clj +++ b/src/clj/shapey_shifty/routes/home.clj @@ -10,8 +10,6 @@ [shapey-shifty.authors.author-core :as author] [ring.util.http-response :as response])) -(def p (atom 0)) - (defn home-page [request] (layout/render request "home.html" {:docs (-> "docs/docs.md" io/resource slurp)})) @@ -20,9 +18,10 @@ (defn post-view [request] (let [{:keys [path-params query-params body-params]} request - {:keys [year month day n]} path-params] - (do (reset! p request) - (layout/render request "post.html" {:post (:properties (post-router/get-post year month day n))})))) + {:keys [year month day n]} path-params + post (post-router/get-post year month day n)] + (layout/render request "post.html" {:post (:properties post) + :card (:author post)}))) (defn about-page [request] (layout/render request "h_card.html"