commit
da11623da2
|
@ -16,3 +16,4 @@ profiles.clj
|
||||||
/log
|
/log
|
||||||
*.swp
|
*.swp
|
||||||
resources/posts/
|
resources/posts/
|
||||||
|
/resources/author/
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
{
|
||||||
|
:card {
|
||||||
|
:first-name nil
|
||||||
|
:family-name nil
|
||||||
|
:rel-me []
|
||||||
|
:job-title nil
|
||||||
|
:org nil
|
||||||
|
:photo nil
|
||||||
|
}
|
||||||
|
:password-hash nil
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
{% block card %}
|
||||||
|
|
||||||
|
<div class="h-card">
|
||||||
|
<img class="u-photo" src="{{ card.photo }}" width="200" />
|
||||||
|
<p>{{ card.first-name }} {{ card.family-name }}</p>
|
||||||
|
<ul>
|
||||||
|
{% for contact in card.rel-me %}
|
||||||
|
<li>
|
||||||
|
<a class="u-url" rel="me" href="{{ contact.url}}">
|
||||||
|
{{ contact.description }}
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<article class="h-entry">
|
<article class="h-entry">
|
||||||
|
<div class="author-info">
|
||||||
|
{% include "tiny_h_card.html" %}
|
||||||
|
</div>
|
||||||
<h1 class="p-name">{{post.name}}</h1>
|
<h1 class="p-name">{{post.name}}</h1>
|
||||||
<div class="e-content">
|
<div class="e-content">
|
||||||
<p>{{post.content}}</p>
|
<p>{{post.content}}</p>
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
{% block card %}
|
||||||
|
|
||||||
|
<a class="h-card" href="{{card.url}}">{{card.first-name}} {{card.family-name}}</a>
|
||||||
|
|
||||||
|
{% endblock %}
|
|
@ -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))))
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
(ns shapey-shifty.posts.posts-io
|
(ns shapey-shifty.posts.posts-io
|
||||||
(:require
|
(: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 post-filename "post.json")
|
||||||
(def base-path "resources/posts")
|
(def base-posts-path "resources/posts")
|
||||||
|
|
||||||
(defn create-path-by-date [year month day]
|
(defn create-path-by-date [year month day]
|
||||||
{:year year :month month :day day})
|
{:year year :month month :day day})
|
||||||
|
@ -13,7 +14,7 @@
|
||||||
|
|
||||||
(defn count-posts-in-date [dt-path]
|
(defn count-posts-in-date [dt-path]
|
||||||
(let [path (pathmap-to-path 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
|
(->> final-path
|
||||||
clojure.java.io/file
|
clojure.java.io/file
|
||||||
file-seq
|
file-seq
|
||||||
|
@ -24,14 +25,22 @@
|
||||||
(defn write-post [post dt-path]
|
(defn write-post [post dt-path]
|
||||||
(let [path (pathmap-to-path dt-path)
|
(let [path (pathmap-to-path dt-path)
|
||||||
increment (inc (count-posts-in-date 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)
|
(clojure.java.io/make-parents final-path)
|
||||||
(spit final-path post)))
|
(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]
|
(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)]
|
f (clojure.java.io/file path)]
|
||||||
(when (.exists f)
|
(when (.exists f)
|
||||||
(-> f
|
(-> f
|
||||||
slurp
|
slurp
|
||||||
read-string))))
|
read-string
|
||||||
|
assoc-author
|
||||||
|
))))
|
||||||
|
|
|
@ -7,10 +7,9 @@
|
||||||
[shapey-shifty.posts.core :as posts]
|
[shapey-shifty.posts.core :as posts]
|
||||||
[shapey-shifty.posts.posts-io :as post-io]
|
[shapey-shifty.posts.posts-io :as post-io]
|
||||||
[shapey-shifty.routes.post-router :as post-router]
|
[shapey-shifty.routes.post-router :as post-router]
|
||||||
|
[shapey-shifty.authors.author-core :as author]
|
||||||
[ring.util.http-response :as response]))
|
[ring.util.http-response :as response]))
|
||||||
|
|
||||||
(def p (atom 0))
|
|
||||||
|
|
||||||
(defn home-page [request]
|
(defn home-page [request]
|
||||||
(layout/render request "home.html" {:docs (-> "docs/docs.md" io/resource slurp)}))
|
(layout/render request "home.html" {:docs (-> "docs/docs.md" io/resource slurp)}))
|
||||||
|
|
||||||
|
@ -19,12 +18,16 @@
|
||||||
|
|
||||||
(defn post-view [request]
|
(defn post-view [request]
|
||||||
(let [{:keys [path-params query-params body-params]} 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)
|
post (post-router/get-post year month day n)]
|
||||||
(layout/render request "post.html" {:post (:properties (post-router/get-post year month day n))}))))
|
(layout/render request "post.html" {:post (:properties post)
|
||||||
|
:card (:author post)})))
|
||||||
|
|
||||||
(defn about-page [request]
|
(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 []
|
(defn home-routes []
|
||||||
[""
|
[""
|
||||||
|
@ -32,5 +35,5 @@
|
||||||
middleware/wrap-formats]}
|
middleware/wrap-formats]}
|
||||||
["/" {:get home-page}]
|
["/" {:get home-page}]
|
||||||
["/blog/:year/:month/:day/:n" {:get post-view}]
|
["/blog/:year/:month/:day/:n" {:get post-view}]
|
||||||
["/about" {:get about-page}]])
|
["/about/:name" {:get about-page}]])
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue