convert to using replicant in place of reagent.
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
This commit is contained in:
parent
c1b081dde8
commit
d5a96e3190
|
|
@ -4,7 +4,6 @@
|
|||
org.clojure/clojurescript {:mvn/version "1.11.60"}
|
||||
|
||||
no.cjohansen/replicant {:mvn/version "2026.07.1"}
|
||||
tick/tick {:mvn/version "0.5.0"}
|
||||
metosin/reitit {:mvn/version "0.5.18"}
|
||||
|
||||
cljs-ajax/cljs-ajax {:mvn/version "0.8.4"}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
<head>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
||||
<meta charset="UTF-8">
|
||||
<title>Digital Octave</title>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.8.2/css/all.min.css" />
|
||||
<link rel="stylesheet" href="https://unpkg.com/tachyons@4.12.0/css/tachyons.min.css" />
|
||||
<script src="https://cdn.tailwindcss.com"></script>
|
||||
|
|
|
|||
|
|
@ -4,8 +4,13 @@
|
|||
<head>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
||||
<meta charset="UTF-8">
|
||||
<title>Page not found · Digital Octave</title>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.8.2/css/all.min.css" />
|
||||
<link rel="stylesheet" href="https://unpkg.com/tachyons@4.12.0/css/tachyons.min.css" />
|
||||
<script src="https://cdn.tailwindcss.com"></script>
|
||||
<style type="text/css">
|
||||
.font { font-family: "Roboto Slab", serif !important; }
|
||||
</style>
|
||||
<style type="text/css" media="screen">
|
||||
#loading {
|
||||
-webkit-animation: rotation 2s infinite linear;
|
||||
|
|
@ -24,21 +29,11 @@
|
|||
</head>
|
||||
|
||||
<body class="ma0 pa0 h-100">
|
||||
<div id="app" class="ma0 pa0 h-100">
|
||||
<section id="startup" class="h-100">
|
||||
<noscript>
|
||||
You need to enable JavaScript to run this app.
|
||||
</noscript>
|
||||
<div class="h-100 w-100 flex justify-around items-center v-mid">
|
||||
<div class="v-mid tc">
|
||||
<p class="f2 button is-warning is-loading">Initiating Blog</p>
|
||||
<i id="loading" class="f-6 fas fa-circle-notch"></i>
|
||||
<p>Application is loading, if nothing happens ensure javascript is enabled.</p>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
<script src="/cljs-out/main.js" type="text/javascript"></script>
|
||||
<!-- Everything between the app markers is replaced by the static generator
|
||||
(com.oly.static-sites.do-blog.ssr). -->
|
||||
<div id="app" class="ma0 pa0 h-100"><!--app--><div class="font h-100"><nav class="db dn-l bg-blue pa3"><a href="/" class="white f4 b link db mb2">Digital Octave</a><a href="/" class="black dib mr3 f5 link hover-green">Home</a><a href="/archive/" class="black dib mr3 f5 link hover-green">Past articles</a><a href="/chess/" class="black dib mr3 f5 link hover-green">Chess</a><a href="/about/" class="black dib mr3 f5 link hover-green">About</a></nav><div class="h-100 flex items-stretch"><div style="flex-basis: 20rem; flex-grow: 1;" class="dn db-l pa3 bg-blue"><div><article class="mw5 center bg-white br3 pa3 pa4-ns mv3 ba b--black-10"><div class="tc"><img src="/images/default/me.png" alt="Photo of Oly" class="br-100 h4 w4 dib ba b--black-05 pa2"><h1 class="f3 mb2">Oly</h1><h2 class="f5 fw4 gray mt0">Earthling, Software Engineer</h2></div></article><ul class="list pl0 measure center"><li class="lh-copy pv3 b--black-30 ba bt-0 bl-0 br-0"><a href="/" class="black f3 link hover-green">Home</a></li><li class="lh-copy pv3 b--black-30 ba bt-0 bl-0 br-0"><a href="/archive/" class="black f3 link hover-green">Past articles</a></li><li class="lh-copy pv3 b--black-30 ba bt-0 bl-0 br-0"><a href="/chess/" class="black f3 link hover-green">Chess</a></li><li class="lh-copy pv3 b--black-30 ba bt-0 bl-0 br-0"><a href="/about/" class="black f3 link hover-green">About</a></li></ul></div></div><div style="flex-basis: 0; flex-grow: 999;" class="ma3 pa3"><div><input type="text" placeholder="Search" value class="w-100 center input-reset ba b--black-20 pa2 mb2"></div><div class="measure lh-copy"><h1 class="f2">Page not found</h1><p>Sorry, there is nothing at this address. It may have moved, or the link may be wrong.</p><p><a href="/" class="link blue hover-green">Go to the latest article</a> or <a href="/archive/" class="link blue hover-green">browse past articles</a>.</p></div></div></div></div><!--/app--></div>
|
||||
<script src="/js/base.js" type="text/javascript"></script>
|
||||
<script src="/js/app.js" type="text/javascript"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -23,8 +23,9 @@
|
|||
(defn render! []
|
||||
;; Nothing to render until the first route has resolved; until then the
|
||||
;; static (server generated) HTML stays in place.
|
||||
(when (:route @state)
|
||||
(r/render (js/document.getElementById "app") (views/app @state))))
|
||||
(when-let [current (when (:route @state) @state)]
|
||||
(set! js/document.title (views/page-title current))
|
||||
(r/render (js/document.getElementById "app") (views/app current))))
|
||||
|
||||
;; Event handling for data driven handlers, e.g. [[:search/set-terms :event.target/value]]
|
||||
|
||||
|
|
@ -46,28 +47,47 @@
|
|||
|
||||
;; Navigation
|
||||
|
||||
(defn fetch-text [path on-success]
|
||||
(defn fetch-text [path on-success on-error]
|
||||
(GET path {:response-format (text-response-format)
|
||||
:handler on-success
|
||||
:error-handler #(js/console.error "Failed to fetch" path (clj->js %))}))
|
||||
:error-handler (fn [error]
|
||||
(js/console.error "Failed to fetch" path (clj->js error))
|
||||
(on-error error))}))
|
||||
|
||||
(defn show-route! [match & {:as extra}]
|
||||
(swap! state merge {:route match :search {:terms ""}} extra))
|
||||
(swap! state merge
|
||||
{:route match :search {:terms ""} :loading nil :not-found? false}
|
||||
extra))
|
||||
|
||||
(defn show-document! [match relative-path]
|
||||
(defn show-not-found! [match]
|
||||
(show-route! (or match {:data {:name :not-found}
|
||||
:path js/location.pathname})
|
||||
:document nil
|
||||
:not-found? true))
|
||||
|
||||
(defn show-document!
|
||||
"Fetch and show an org document. The current page stays visible with a
|
||||
loading indicator until it arrives; responses for a page we have since
|
||||
navigated away from are dropped."
|
||||
[match relative-path]
|
||||
(if relative-path
|
||||
(let [path (:path match)
|
||||
current? #(= path (:loading @state))]
|
||||
(swap! state assoc :loading path)
|
||||
(fetch-text (str "/documents/" relative-path)
|
||||
#(show-route! match :document (org->document %)))
|
||||
(js/console.warn "No document found for" (pr-str (:path match)))))
|
||||
#(when (current?) (show-route! match :document (org->document %)))
|
||||
#(when (current?) (show-not-found! match))))
|
||||
(show-not-found! match)))
|
||||
|
||||
(defn on-navigate [raw-match]
|
||||
(when-let [match (normalize-match raw-match)]
|
||||
(if-let [match (normalize-match raw-match)]
|
||||
(case (-> match :data :name)
|
||||
:homepage (show-document! match (latest-article))
|
||||
:posts (show-document! match (-> match :path-params :path))
|
||||
:chess (do (chess/start! match)
|
||||
(show-route! match))
|
||||
(show-route! match))))
|
||||
(show-route! match))
|
||||
(show-not-found! nil)))
|
||||
|
||||
(defn ^:dev/after-load reload! []
|
||||
(render!))
|
||||
|
|
|
|||
|
|
@ -1,4 +1,28 @@
|
|||
(ns com.oly.static-sites.do-blog.pages.about)
|
||||
(ns com.oly.static-sites.do-blog.pages.about
|
||||
(:require [com.oly.static-sites.do-blog.routes :refer [archive-href]]
|
||||
[com.oly.static-sites.do-blog.pages.helpers.database :refer [search-articles]]
|
||||
[com.oly.static-sites.do-blog.pages.components.core :refer [pill-grow]]))
|
||||
|
||||
(defn top-tags
|
||||
"The most used tags across all articles, most frequent first."
|
||||
[articles n]
|
||||
(->> articles
|
||||
(mapcat :tags)
|
||||
(remove #{"draft"})
|
||||
frequencies
|
||||
(sort-by (fn [[tag freq]] [(- freq) tag]))
|
||||
(take n)
|
||||
(map first)))
|
||||
|
||||
(defn about-page [_state]
|
||||
[:div "hi2"])
|
||||
(let [articles (search-articles {})]
|
||||
[:div.measure.lh-copy
|
||||
[:h1.f2 "About"]
|
||||
[:p "Hi, I'm Oly: earthling and software engineer."]
|
||||
[:p (str "This site collects " (count articles)
|
||||
" articles: notes, tutorials, reviews and recipes, written in org mode.")]
|
||||
[:h2.f4 "Popular topics"]
|
||||
[:div
|
||||
(for [tag (top-tags articles 12)]
|
||||
[:span.mr2 {:replicant/key tag}
|
||||
(pill-grow {:href (archive-href tag) :text tag})])]]))
|
||||
|
|
|
|||
|
|
@ -1,17 +1,18 @@
|
|||
(ns com.oly.static-sites.do-blog.pages.archive
|
||||
(:require [com.oly.static-sites.do-blog.routes :refer [post-href]]
|
||||
(:require [clojure.string :as str]
|
||||
[com.oly.static-sites.do-blog.routes :refer [post-href]]
|
||||
[com.oly.static-sites.do-blog.pages.helpers.utils :refer [format-date]]
|
||||
[com.oly.static-sites.do-blog.pages.helpers.database :refer [search-articles]]
|
||||
[com.oly.static-sites.do-blog.pages.components.core :refer [definition-list]]))
|
||||
[com.oly.static-sites.do-blog.pages.helpers.database :refer [search-articles]]))
|
||||
|
||||
(defn archive-page [{:keys [route search]}]
|
||||
(let [articles (search-articles (merge {:search (:terms search)}
|
||||
(:path-params route)))]
|
||||
(defn archive-page [{:keys [route]}]
|
||||
(let [tag (-> route :path-params :tag)
|
||||
articles (search-articles {:tag tag})]
|
||||
[:div
|
||||
[:h1 "Past articles"]
|
||||
(definition-list
|
||||
{:list
|
||||
(for [doc articles]
|
||||
{:text [:div
|
||||
[:a.f4.lh-copy {:href (post-href (:relative-path doc))}
|
||||
(str (format-date (:date doc)) " " (:title doc))]]})})]))
|
||||
[:h1.f2 (if (str/blank? tag) "Past articles" (str "Articles tagged " tag))]
|
||||
(if (seq articles)
|
||||
[:ul.list.pl0.lh-copy
|
||||
(for [{:keys [relative-path date title]} articles]
|
||||
[:li.mb2 {:replicant/key relative-path}
|
||||
[:time.gray.f6.mr2 {:datetime date} (format-date date)]
|
||||
[:a.f4.link.blue.hover-green {:href (post-href relative-path)} title]])]
|
||||
[:p.lh-copy "No articles found."])]))
|
||||
|
|
|
|||
|
|
@ -12,12 +12,6 @@
|
|||
[com.oly.static-sites.do-blog.views :as views]
|
||||
[com.oly.static-sites.ui-hiccup.interface :refer [board]]))
|
||||
|
||||
;;/addwidget https://blog-test.digitaloctave.com/chess?widgetId=dochess
|
||||
;;/addwidget https://blog-test.digitaloctave.com/chess?roomI=!YOyzcCyoomnjylcOFP:matrix.org&widgetId=dochess
|
||||
(def widget (atom {}))
|
||||
|
||||
#_(def game-state-viking (r/atom {:board viking-start-state}))
|
||||
|
||||
|
||||
(defn chars->map [text]
|
||||
(when (= 0 (mod (count text) 4))
|
||||
|
|
@ -191,23 +185,12 @@
|
|||
|
||||
(defn chess-page [_state]
|
||||
[:div
|
||||
(let [[pos piece] (get-selected-square game-state)]
|
||||
[:div
|
||||
[:div (str @widget)]
|
||||
[:div (if (-> @game-state :player-one :selected)
|
||||
"Whites turn"
|
||||
"Black turn")]
|
||||
[:div "Player one " (str (mapv :type (-> @game-state :player-one :pieces)))]
|
||||
[:div "Player two " (str (mapv :type (-> @game-state :player-two :pieces)))]
|
||||
[:div (str "pos = " pos)]
|
||||
[:div (str (:type piece))]
|
||||
[:div (str piece)]
|
||||
[:div (str "move = " (fetch-selected-piece-moves
|
||||
[pos piece]
|
||||
(-> @game-state :board)))]])
|
||||
|
||||
[:h1.f2 "Chess"]
|
||||
[:p.f4.b (if (-> @game-state :player-one :selected)
|
||||
"White's turn"
|
||||
"Black's turn")]
|
||||
[:div (board 8 (-> @game-state :board))]
|
||||
[:div "Viking chess board"]
|
||||
[:h2.f3.mt4 "Viking chess"]
|
||||
[:div (board 11 (-> @v/game-state :board))]])
|
||||
|
||||
(defmethod views/page :chess [state]
|
||||
|
|
|
|||
|
|
@ -18,13 +18,6 @@
|
|||
[:h1.f3.mb2 name]
|
||||
[:h2.f5.fw4.gray.mt0 tagline]]])
|
||||
|
||||
(defn definition-list [{:keys [list]}]
|
||||
[:dl.lh-title.pa4.mt0
|
||||
(mapcat (fn [{:keys [title text]}]
|
||||
[[:dt.f6.b title]
|
||||
[:dd.ml0 text]])
|
||||
list)])
|
||||
|
||||
(defn ui-tags [meta]
|
||||
[:div
|
||||
(for [tag (-> meta :filetags extract-tags)]
|
||||
|
|
|
|||
|
|
@ -58,10 +58,10 @@
|
|||
"Clean up the raw org-meta-index entries ready for datascript."
|
||||
[entries]
|
||||
(->> entries
|
||||
;; filter out missing dates
|
||||
(filter (fn [doc] (some? (:date doc))))
|
||||
(mapv #(assoc % :tags (vec (:filetags %))))
|
||||
(mapv #(assoc % :date (convert-date (:date %))))))
|
||||
(map #(assoc % :tags (vec (:filetags %))
|
||||
:date (convert-date (:date %))))
|
||||
;; filter out missing or unparseable dates
|
||||
(filterv :date)))
|
||||
|
||||
(defn load-index!
|
||||
"Replace the article database with the parsed index entries."
|
||||
|
|
|
|||
|
|
@ -1,21 +1,28 @@
|
|||
(ns com.oly.static-sites.do-blog.pages.helpers.utils
|
||||
(:require
|
||||
[clojure.string :as str]
|
||||
[tick.core :as t]
|
||||
[tick.locale-en-us]
|
||||
[tick.timezone]))
|
||||
(:require [clojure.string :as str]))
|
||||
|
||||
(defonce date-format (t/formatter "yyyy-MMM-dd"))
|
||||
;; Dates are kept as ISO "yyyy-MM-dd" strings: they sort correctly as text and
|
||||
;; avoid pulling a date library (and its timezone data) into the bundle.
|
||||
|
||||
(defn format-date [date]
|
||||
(when date
|
||||
(t/format date-format date)))
|
||||
(def ^:private month-names
|
||||
["Jan" "Feb" "Mar" "Apr" "May" "Jun" "Jul" "Aug" "Sep" "Oct" "Nov" "Dec"])
|
||||
|
||||
(defn convert-date
|
||||
"Convert an org date string like \"2020-06-27 12:00:00 UTC\" to a tick date."
|
||||
"Convert an org date string like \"2020-06-27 12:00:00 UTC\" to \"2020-06-27\".
|
||||
Returns nil when the text does not start with a valid date."
|
||||
[text]
|
||||
(when-not (str/blank? text)
|
||||
(-> text str/trim (str/split #" ") first t/date)))
|
||||
(when (string? text)
|
||||
(when-let [[_ year month day] (re-find #"^\s*(\d{4})-(\d{2})-(\d{2})" text)]
|
||||
(let [m (parse-long month)
|
||||
d (parse-long day)]
|
||||
(when (and (<= 1 m 12) (<= 1 d 31))
|
||||
(str year "-" month "-" day))))))
|
||||
|
||||
(defn format-date
|
||||
"Format an ISO date string as \"2020-Jun-27\"."
|
||||
[date]
|
||||
(when-let [[_ year month day] (some->> date (re-find #"^(\d{4})-(\d{2})-(\d{2})"))]
|
||||
(str year "-" (month-names (dec (parse-long month))) "-" day)))
|
||||
|
||||
(defn ltrim-slash "Trim a leading slash" [text] (str/replace text #"^/" ""))
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +0,0 @@
|
|||
(ns com.oly.static-sites.do-blog.pages.home
|
||||
(:require [com.oly.static-sites.do-blog.pages.components.core :refer [title-text-image]]))
|
||||
|
||||
(defn home-page [{:keys [document]}]
|
||||
[:div
|
||||
(title-text-image
|
||||
{:title (-> document :details :title)
|
||||
:content (-> document :hiccup)}
|
||||
(-> document :details))])
|
||||
|
|
@ -21,10 +21,17 @@
|
|||
(def default-template "bases/do-blog/resources/do-blog/index.template.html")
|
||||
|
||||
(def app-content #"(?s)<!--app-->.*?<!--/app-->")
|
||||
(def title-tag #"(?s)<title>.*?</title>")
|
||||
|
||||
(defn render-into-template [template html]
|
||||
(str/replace template app-content
|
||||
(str/re-quote-replacement (str "<!--app-->" html "<!--/app-->"))))
|
||||
(defn escape-html [text]
|
||||
(str/escape (str text) {\& "&" \< "<" \> ">" \" """}))
|
||||
|
||||
(defn render-into-template [template title html]
|
||||
(-> template
|
||||
(str/replace title-tag
|
||||
(str/re-quote-replacement (str "<title>" (escape-html title) "</title>")))
|
||||
(str/replace app-content
|
||||
(str/re-quote-replacement (str "<!--app-->" html "<!--/app-->")))))
|
||||
|
||||
(defn read-document [public-dir relative-path]
|
||||
(org->document (slurp (io/file public-dir "documents" relative-path))))
|
||||
|
|
@ -41,7 +48,8 @@
|
|||
latest (latest-article)
|
||||
tags (->> index (mapcat (comp extract-tags :filetags)) distinct)]
|
||||
(concat
|
||||
[["/" (page-state "/" (doc latest))]
|
||||
[["/404.html" {:route nil :search {:terms ""} :not-found? true}]
|
||||
["/" (page-state "/" (doc latest))]
|
||||
[(href :about) (page-state (href :about) nil)]
|
||||
[(href :chess) (page-state (href :chess) nil)]
|
||||
[(archive-href "") (page-state (archive-href "") nil)]]
|
||||
|
|
@ -53,8 +61,13 @@
|
|||
url (post-href path)]]
|
||||
[url (page-state url (doc path))]))))
|
||||
|
||||
(defn url->file [public-dir url]
|
||||
(io/file public-dir (str (str/replace url #"^/" "") "index.html")))
|
||||
(defn url->file
|
||||
"Directory style URLs map to <url>/index.html, explicit .html URLs as is."
|
||||
[public-dir url]
|
||||
(let [path (str/replace url #"^/" "")]
|
||||
(io/file public-dir (if (str/ends-with? path ".html")
|
||||
path
|
||||
(str path "index.html")))))
|
||||
|
||||
(defn generate!
|
||||
([] (generate! default-public-dir default-template))
|
||||
|
|
@ -66,7 +79,9 @@
|
|||
(try
|
||||
(let [file (url->file public-dir url)]
|
||||
(io/make-parents file)
|
||||
(spit file (render-into-template template (rs/render (views/app state))))
|
||||
(spit file (render-into-template template
|
||||
(views/page-title state)
|
||||
(rs/render (views/app state))))
|
||||
{:url url})
|
||||
(catch Exception e
|
||||
{:url url :error (ex-message e)}))))
|
||||
|
|
|
|||
|
|
@ -6,21 +6,63 @@
|
|||
[com.oly.static-sites.do-blog.pages.helpers.database :refer [search-articles]]
|
||||
[com.oly.static-sites.do-blog.pages.components.core
|
||||
:refer [profile-card article-list-author-media-flipped]]
|
||||
[com.oly.static-sites.do-blog.pages.home :refer [home-page]]
|
||||
[com.oly.static-sites.do-blog.pages.article :refer [article-page]]
|
||||
[com.oly.static-sites.do-blog.pages.archive :refer [archive-page]]
|
||||
[com.oly.static-sites.do-blog.pages.about :refer [about-page]]))
|
||||
|
||||
(def site-name "Digital Octave")
|
||||
|
||||
(defn page-title
|
||||
"Document title for the current state, shared by the browser and the
|
||||
static generator."
|
||||
[{:keys [route document not-found?]}]
|
||||
(let [tag (-> route :path-params :tag)
|
||||
title (if not-found?
|
||||
"Page not found"
|
||||
(case (-> route :data :name)
|
||||
:homepage nil
|
||||
:posts (-> document :details :title)
|
||||
:archive (if (str/blank? tag) "Past articles" (str "Articles tagged " tag))
|
||||
:chess "Chess"
|
||||
:about "About"
|
||||
"Page not found"))]
|
||||
(if (str/blank? title)
|
||||
site-name
|
||||
(str title " · " site-name))))
|
||||
|
||||
(defmulti page
|
||||
"Render the body for the current route. Browser-only pages (e.g. chess)
|
||||
add their own methods."
|
||||
(fn [state] (-> state :route :data :name)))
|
||||
|
||||
(defmethod page :homepage [state] (home-page state))
|
||||
;; The homepage shows the latest article, so both render a document.
|
||||
(defmethod page :homepage [state] (article-page state))
|
||||
(defmethod page :posts [state] (article-page state))
|
||||
(defmethod page :archive [state] (archive-page state))
|
||||
(defmethod page :about [state] (about-page state))
|
||||
(defmethod page :default [_state] [:div])
|
||||
|
||||
(defn not-found-page []
|
||||
[:div.measure.lh-copy
|
||||
[:h1.f2 "Page not found"]
|
||||
[:p "Sorry, there is nothing at this address. It may have moved, or the link may be wrong."]
|
||||
[:p
|
||||
[:a.link.blue.hover-green {:href (href :homepage)} "Go to the latest article"]
|
||||
" or "
|
||||
[:a.link.blue.hover-green {:href (href :archive {:tag ""})} "browse past articles"]
|
||||
"."]])
|
||||
|
||||
(defmethod page :default [_state] (not-found-page))
|
||||
|
||||
;; The chess board is browser only (pages/chess_board.cljs registers the real
|
||||
;; method); the static page gets a placeholder until the JavaScript loads.
|
||||
#?(:clj (defmethod page :chess [_state]
|
||||
[:p.lh-copy "Loading the chess board…"]))
|
||||
|
||||
(defn loading-bar [loading]
|
||||
(when loading
|
||||
[:div.fixed.top-0.left-0.w-100.bg-green.white.f6.tc.pa1.z-999
|
||||
{:role "status"}
|
||||
"Loading…"]))
|
||||
|
||||
(defn ui-search [terms]
|
||||
[:div
|
||||
|
|
@ -30,27 +72,51 @@
|
|||
:value (or terms "")
|
||||
:on {:input [[:search/set-terms :event.target/value]]}}]])
|
||||
|
||||
(defn nav-link [route-name params text]
|
||||
[:li.lh-copy.pv3.b--black-30.ba.bt-0.bl-0.br-0
|
||||
[:a.black.f3.link.hover-green {:href (href route-name params)} text]])
|
||||
(def nav-items
|
||||
[{:route :homepage :text "Home"}
|
||||
{:route :archive :params {:tag ""} :text "Past articles"}
|
||||
{:route :chess :text "Chess"}
|
||||
{:route :about :text "About"}])
|
||||
|
||||
(defn sidebar []
|
||||
(defn active?
|
||||
"Is the nav item for the route currently shown?"
|
||||
[current-route item]
|
||||
(= (:route item) (-> current-route :data :name)))
|
||||
|
||||
(defn sidebar [current-route]
|
||||
[:div
|
||||
(profile-card {:name "Oly"
|
||||
:tagline "Earthling, Software Engineer"
|
||||
:img-src "/images/default/me.png"})
|
||||
:img-src "/images/default/me.png"
|
||||
:img-alt "Photo of Oly"})
|
||||
[:ul.list.pl0.measure.center
|
||||
(nav-link :homepage nil "Home")
|
||||
(nav-link :archive {:tag ""} "Past articles")
|
||||
(nav-link :chess nil "Chess")
|
||||
(nav-link :about nil "About")]])
|
||||
(for [{:keys [route params text] :as item} nav-items]
|
||||
[:li.lh-copy.pv3.b--black-30.ba.bt-0.bl-0.br-0 {:replicant/key route}
|
||||
[:a.f3.link.hover-green
|
||||
{:href (href route params)
|
||||
:class (if (active? current-route item) "white" "black")}
|
||||
text]])]])
|
||||
|
||||
(defn layout [{:keys [search]} content]
|
||||
(defn top-bar
|
||||
"Compact navigation for small screens, where the sidebar is hidden."
|
||||
[current-route]
|
||||
[:nav.db.dn-l.bg-blue.pa3
|
||||
[:a.white.f4.b.link.db.mb2 {:href (href :homepage)} site-name]
|
||||
(for [{:keys [route params text] :as item} nav-items]
|
||||
[:a.dib.mr3.f5.link.hover-green
|
||||
{:replicant/key route
|
||||
:href (href route params)
|
||||
:class (if (active? current-route item) "white b" "black")}
|
||||
text])])
|
||||
|
||||
(defn layout [{:keys [route search loading]} content]
|
||||
(let [terms (:terms search)]
|
||||
[:div.font.h-100
|
||||
(loading-bar loading)
|
||||
(top-bar route)
|
||||
[:div.h-100.flex.items-stretch
|
||||
[:div.dn.db-l.pa3.bg-blue {:style {:flex-basis "20rem" :flex-grow "1"}}
|
||||
(sidebar)]
|
||||
(sidebar route)]
|
||||
[:div.ma3.pa3 {:style {:flex-basis "0" :flex-grow "999"}}
|
||||
(ui-search terms)
|
||||
(if (str/blank? terms)
|
||||
|
|
@ -60,4 +126,6 @@
|
|||
(search-articles {:search terms})))]]]))
|
||||
|
||||
(defn app [state]
|
||||
(layout state (page state)))
|
||||
(layout state (if (:not-found? state)
|
||||
(not-found-page)
|
||||
(page state))))
|
||||
|
|
|
|||
Loading…
Reference in New Issue