Write dedicated tags index

parent 13543c69
......@@ -244,10 +244,7 @@
(perun/rss :filterer #(is-of-type? % "posts")
:filename "rss.xml")
;; XXX: Tags atm are not enforced to be valid URLs
;; This could be fixed by writing proper tags in the posts or by
;; building a new feature within Perun.
(perun/tags :renderer 'ok.index/render
(perun/tags :renderer 'ok.tags/render
:filterer #(is-of-type? % "posts")
:out-dir "public/tags")
......
(ns ok.helper)
(ns ok.helper
(:require [clojure.string :as s]))
(defn stylesheet-link-tag [href]
[:link {:rel "stylesheet" :href href}])
......@@ -19,3 +20,63 @@
(if (re-find #"^http" resource-path)
resource-path
(str "https://200ok.ch" resource-path))))
;; Returns the publish date or a fallback if no :date-published is
;; provided. This, however, is always a lie, because the
;; last-modified-time is whenever the page has been built.
(defn date-of-post
"Returns the last-updated-at date of a post"
[post]
(if (:date-published post)
(.format (java.text.SimpleDateFormat. "yyyy-MM-dd")
(:date-published post))
(.format (java.text.SimpleDateFormat. "yyyy-MM-dd")
(java.util.Date.
(.lastModified
(clojure.java.io/file
(str "resources/" (:path post))))))))
(defn- authors
"Get author(s). If there are none, return '200ok'."
[post]
(s/split (or (:authors post) "200ok") #"\s*,\s*"))
(defn author-section
[post]
(for [author (authors post)]
[:section.author {:itemscope true
:itemprop "author"
:itemtype "https://schema.org/Person"}
[:span {:itemprop "name"}
author]]))
(defn date-of-post-section
[post]
[:time {:itemprop "datePublished"}
(date-of-post post)])
(defn word-count-section
[post]
[:span {:itemprop "wordCount"}
(:word-count post)])
(defn time-to-read-section
[post]
[:span {:itemprop "timeRequired"}
(:ttr post)])
(defn subheader-post
"Returns metadata of a post inside a :div.subheader"
[post]
[:div.subheader
[:p.post-meta
(date-of-post-section post)
" - "
(word-count-section post)
" words"
" - "
(time-to-read-section post)
" min read"]
[:div.byline
[:img.author-icon {:src "/img/author.svg"}]
(author-section post)]])
(ns ok.index
"NOTE: this ns still has too much stuff in it"
(:require [clojure.string :as s]
[ok.layout :as layout]
[ok.helper :refer [category-link]]
[ok.helper :as helper]))
[ok.helper :refer [logo-url
author-section
date-of-post-section
word-count-section
time-to-read-section
subheader-post
category-link]]
[ok.layout :as layout]))
;; Returns the publish date or a fallback if no :date-published is
;; provided. This, however, is always a lie, because the
......@@ -38,19 +43,6 @@
[:meta {:itemprop "legalName"
:content "200ok GmbH"}]]])
(defn- authors
"Get author(s). If there are none, return '200ok'."
[post]
(s/split (or (:authors post) "200ok") #"\s*,\s*"))
(defn- author-section
[post]
(for [author (authors post)]
[:section.author {:itemscope true
:itemprop "author"
:itemtype "https://schema.org/Person"}
[:span {:itemprop "name"}
author]]))
(defn- category-section
[post]
......@@ -60,40 +52,6 @@
[:a {:href (category-link (:category post)) }
(:category post)]]))
(defn- date-of-post-section
[post]
[:time {:itemprop "datePublished"}
(date-of-post post)])
(defn- word-count-section
[post]
[:span {:itemprop "wordCount"}
(:word-count post)])
(defn- time-to-read-section
[post]
[:span {:itemprop "timeRequired"}
(:ttr post)])
(defn- subheader-post
"Returns metadata of a post inside a :div.subheader"
[post]
[:div.subheader
[:p.post-meta
(date-of-post-section post)
" - "
(word-count-section post)
" words"
" - "
(time-to-read-section post)
" min read"
(ok-metadata)]
[:div.byline
[:img.author-icon {:src "/img/author.svg"}]
(author-section post)]
;; (category-section post)
])
(defn- separated-tags
"Get tag(s). If there are none, return '200ok'."
[post]
......@@ -150,7 +108,7 @@
[:meta {:itemprop "width"
:content "349"}]
[:meta {:itemprop "url"
:content (helper/logo-url)}]])
:content (logo-url)}]])
(defn render-post
"Renders a post as :article"
......@@ -188,8 +146,6 @@
[:span.badge occurrences]]])
sorted))]]])
(defn- pagination
[page]
;; TODO: Implement `:pages-count` within the `pagination` task of
......
(ns ok.tags
(:require [ok.layout :as layout]
[ok.helper :refer [category-link
author-section
date-of-post-section
word-count-section
time-to-read-section
subheader-post]]))
(defn render-post
"Renders a post list."
[post]
[:article.blog-post {:itemscope true
:itemtype "https://schema.org/BlogPosting"}
[:h3.headline {:itemprop "headline"}
[:a.nunito {:href (:permalink post)
:itemprop "url"}
(:title post)]]
(subheader-post post)])
(defn render [{global-meta :meta posts :entries page :entry}]
(layout/blog global-meta
posts
[:main
[:h1.headline (str "#" (:tag page))]
[:div.content {:id "content"}
(for [post posts]
(render-post post))]]))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment