Compare commits
2 Commits
994b67b4f2
...
9f2855c891
| Author | SHA1 | Date |
|---|---|---|
|
|
9f2855c891 | |
|
|
c564dbaa29 |
162
.drone.yml
162
.drone.yml
|
|
@ -15,10 +15,12 @@ steps:
|
||||||
path: /drone/cache/
|
path: /drone/cache/
|
||||||
commands:
|
commands:
|
||||||
- ls -la /drone/cache/.m2
|
- ls -la /drone/cache/.m2
|
||||||
- clj -Sdeps '{:mvn/local-repo "/drone/cache/.m2/repository"}' -P -M:blog:clojure-demos:dev:shadow-cljs-run
|
- clj -Sdeps '{:mvn/local-repo "/drone/cache/.m2/repository" :gitlibs-dir "/drone/cache/.gitlibs"}' -P -M:blog:clojure-demos:dev:shadow-cljs-run:poly
|
||||||
|
|
||||||
# --- Blog ---
|
# Detect which bases changed since the last release tag (v[0-9]*).
|
||||||
- name: build-blog
|
# Deployables here are bases (not projects), so we use changed-bases; a change
|
||||||
|
# to a shared component or to any file outside bases/ affects every base.
|
||||||
|
- name: detect-changes
|
||||||
pull: always
|
pull: always
|
||||||
image: clojure:tools-deps
|
image: clojure:tools-deps
|
||||||
depends_on:
|
depends_on:
|
||||||
|
|
@ -28,81 +30,121 @@ steps:
|
||||||
- name: cache
|
- name: cache
|
||||||
path: /drone/cache/
|
path: /drone/cache/
|
||||||
commands:
|
commands:
|
||||||
- clj -M:blog:shadow-cljs-run release blog
|
- |
|
||||||
|
clj -Sdeps '{:mvn/local-repo "/drone/cache/.m2/repository" :gitlibs-dir "/drone/cache/.gitlibs"}' -M:poly ws get:changes:changed-bases since:release out:changed-bases.json
|
||||||
|
clj -Sdeps '{:mvn/local-repo "/drone/cache/.m2/repository" :gitlibs-dir "/drone/cache/.gitlibs"}' -M:poly ws get:changes:changed-components since:release out:changed-components.json
|
||||||
|
clj -Sdeps '{:mvn/local-repo "/drone/cache/.m2/repository" :gitlibs-dir "/drone/cache/.gitlibs"}' -M:poly ws get:changes:changed-files since:release out:changed-files.json
|
||||||
|
sed -e 's/\[//g' -e 's/\]//g' -e 's/[" ]//g' -e 's/,/\n/g' changed-bases.json > changed-bases.txt
|
||||||
|
sed -e 's/\[//g' -e 's/\]//g' -e 's/[" ]//g' -e 's/,/\n/g' changed-components.json > changed-components.txt
|
||||||
|
sed -e 's/\[//g' -e 's/\]//g' -e 's/[" ]//g' -e 's/,/\n/g' changed-files.json > changed-files.txt
|
||||||
|
if [ -s changed-components.txt ] || grep -v '^bases/' changed-files.txt | grep -q .; then
|
||||||
|
echo all > changed-bases.txt
|
||||||
|
fi
|
||||||
|
echo "changed bases: $(tr '\n' ' ' < changed-bases.txt)"
|
||||||
|
|
||||||
- name: deploy-blog
|
- name: build-and-deploy-blog
|
||||||
pull: True
|
|
||||||
image: appleboy/drone-scp
|
|
||||||
depends_on:
|
|
||||||
- build-blog
|
|
||||||
settings:
|
|
||||||
host: blog.digitaloctave.com
|
|
||||||
port: 22
|
|
||||||
username:
|
|
||||||
from_secret: ssh_user
|
|
||||||
key:
|
|
||||||
from_secret: ssh_key
|
|
||||||
target: /var/www/new-blog/
|
|
||||||
source: /drone/src/bases/do-blog/resources/public/*
|
|
||||||
strip_components: 6
|
|
||||||
|
|
||||||
# --- Clojure Demos ---
|
|
||||||
- name: build-clojure-demos
|
|
||||||
pull: always
|
pull: always
|
||||||
image: clojure:tools-deps
|
image: clojure:tools-deps
|
||||||
depends_on:
|
depends_on:
|
||||||
- fetch-clojure-deps
|
- detect-changes
|
||||||
- fetch-npm-deps
|
|
||||||
volumes:
|
volumes:
|
||||||
- name: cache
|
- name: cache
|
||||||
path: /drone/cache/
|
path: /drone/cache/
|
||||||
commands:
|
environment:
|
||||||
- clj -M:clojure-demos:shadow-cljs-run release clojure-demos
|
SSH_USER:
|
||||||
|
|
||||||
- name: deploy-clojure-demos
|
|
||||||
pull: True
|
|
||||||
image: appleboy/drone-scp
|
|
||||||
depends_on:
|
|
||||||
- build-clojure-demos
|
|
||||||
settings:
|
|
||||||
host: clojure-demos.digitaloctave.com
|
|
||||||
port: 22
|
|
||||||
username:
|
|
||||||
from_secret: ssh_user
|
from_secret: ssh_user
|
||||||
key:
|
SSH_KEY:
|
||||||
from_secret: ssh_key
|
from_secret: ssh_key
|
||||||
target: /var/www/clojure-demos/
|
commands:
|
||||||
source: /drone/src/bases/clojure-demos/resources/public/*
|
- |
|
||||||
strip_components: 6
|
if grep -qx 'all' changed-bases.txt || grep -qx 'do-blog' changed-bases.txt; then
|
||||||
|
echo "Building do-blog"
|
||||||
|
clj -Sdeps '{:mvn/local-repo "/drone/cache/.m2/repository" :gitlibs-dir "/drone/cache/.gitlibs"}' -M:blog:shadow-cljs-run release blog
|
||||||
|
echo "Deploying do-blog"
|
||||||
|
command -v scp >/dev/null 2>&1 || { apt-get update -qq && apt-get install -y -qq openssh-client >/dev/null; }
|
||||||
|
mkdir -p ~/.ssh && printf '%s\n' "$SSH_KEY" > ~/.ssh/id_rsa && chmod 600 ~/.ssh/id_rsa
|
||||||
|
scp -o StrictHostKeyChecking=no -r bases/do-blog/resources/public/* "$SSH_USER@blog.digitaloctave.com:/var/www/new-blog/"
|
||||||
|
else
|
||||||
|
echo "No changes affecting do-blog, skipping build and deploy"
|
||||||
|
fi
|
||||||
|
|
||||||
# --- Portfolio ---
|
- name: build-and-deploy-clojure-demos
|
||||||
- name: build-portfolio
|
|
||||||
pull: always
|
pull: always
|
||||||
image: clojure:tools-deps
|
image: clojure:tools-deps
|
||||||
depends_on:
|
depends_on:
|
||||||
- fetch-clojure-deps
|
- build-and-deploy-blog
|
||||||
- fetch-npm-deps
|
|
||||||
volumes:
|
volumes:
|
||||||
- name: cache
|
- name: cache
|
||||||
path: /drone/cache/
|
path: /drone/cache/
|
||||||
commands:
|
environment:
|
||||||
- clj -M:dev:shadow-cljs-run release ui
|
SSH_USER:
|
||||||
|
|
||||||
- name: deploy-portfolio
|
|
||||||
pull: True
|
|
||||||
image: appleboy/drone-scp
|
|
||||||
depends_on:
|
|
||||||
- build-portfolio
|
|
||||||
settings:
|
|
||||||
host: digitaloctave.com
|
|
||||||
port: 22
|
|
||||||
username:
|
|
||||||
from_secret: ssh_user
|
from_secret: ssh_user
|
||||||
key:
|
SSH_KEY:
|
||||||
from_secret: ssh_key
|
from_secret: ssh_key
|
||||||
target: /var/www/portfolio/
|
commands:
|
||||||
source: /drone/src/development/resources/public/*
|
- |
|
||||||
strip_components: 5
|
if grep -qx 'all' changed-bases.txt || grep -qx 'clojure-demos' changed-bases.txt; then
|
||||||
|
echo "Building clojure-demos"
|
||||||
|
clj -Sdeps '{:mvn/local-repo "/drone/cache/.m2/repository" :gitlibs-dir "/drone/cache/.gitlibs"}' -M:clojure-demos:shadow-cljs-run release clojure-demos
|
||||||
|
echo "Deploying clojure-demos"
|
||||||
|
command -v scp >/dev/null 2>&1 || { apt-get update -qq && apt-get install -y -qq openssh-client >/dev/null; }
|
||||||
|
mkdir -p ~/.ssh && printf '%s\n' "$SSH_KEY" > ~/.ssh/id_rsa && chmod 600 ~/.ssh/id_rsa
|
||||||
|
scp -o StrictHostKeyChecking=no -r bases/clojure-demos/resources/public/* "$SSH_USER@clojure-demos.digitaloctave.com:/var/www/clojure-demos/"
|
||||||
|
else
|
||||||
|
echo "No changes affecting clojure-demos, skipping build and deploy"
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: build-and-deploy-portfolio
|
||||||
|
pull: always
|
||||||
|
image: clojure:tools-deps
|
||||||
|
depends_on:
|
||||||
|
- build-and-deploy-clojure-demos
|
||||||
|
volumes:
|
||||||
|
- name: cache
|
||||||
|
path: /drone/cache/
|
||||||
|
environment:
|
||||||
|
SSH_USER:
|
||||||
|
from_secret: ssh_user
|
||||||
|
SSH_KEY:
|
||||||
|
from_secret: ssh_key
|
||||||
|
commands:
|
||||||
|
- |
|
||||||
|
if grep -qx 'all' changed-bases.txt || grep -qx 'portfolio' changed-bases.txt; then
|
||||||
|
echo "Building portfolio"
|
||||||
|
clj -Sdeps '{:mvn/local-repo "/drone/cache/.m2/repository" :gitlibs-dir "/drone/cache/.gitlibs"}' -M:dev:shadow-cljs-run release ui
|
||||||
|
echo "Deploying portfolio"
|
||||||
|
command -v scp >/dev/null 2>&1 || { apt-get update -qq && apt-get install -y -qq openssh-client >/dev/null; }
|
||||||
|
mkdir -p ~/.ssh && printf '%s\n' "$SSH_KEY" > ~/.ssh/id_rsa && chmod 600 ~/.ssh/id_rsa
|
||||||
|
scp -o StrictHostKeyChecking=no -r development/resources/public/* "$SSH_USER@digitaloctave.com:/var/www/portfolio/"
|
||||||
|
else
|
||||||
|
echo "No changes affecting portfolio, skipping build and deploy"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Tag a new release so the next build only builds changes since this tag.
|
||||||
|
# Only runs on push events (never on the tag event it creates, avoiding a loop).
|
||||||
|
- name: tag-release
|
||||||
|
pull: always
|
||||||
|
image: clojure:tools-deps
|
||||||
|
depends_on:
|
||||||
|
- build-and-deploy-portfolio
|
||||||
|
when:
|
||||||
|
event: [push]
|
||||||
|
commands:
|
||||||
|
- |
|
||||||
|
if [ ! -s changed-bases.txt ]; then
|
||||||
|
echo "Nothing changed, skipping release tag"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
git config user.email "ci@drone.local"
|
||||||
|
git config user.name "Drone CI"
|
||||||
|
if [ -n "$DRONE_NETRC_MACHINE" ]; then
|
||||||
|
printf 'machine %s login %s password %s\n' "$DRONE_NETRC_MACHINE" "$DRONE_NETRC_USERNAME" "$DRONE_NETRC_PASSWORD" > ~/.netrc
|
||||||
|
chmod 600 ~/.netrc
|
||||||
|
fi
|
||||||
|
VERSION=$(( $(git tag -l 'v[0-9]*' | wc -l) + 1 ))
|
||||||
|
echo "Tagging release v$VERSION"
|
||||||
|
git tag -a "v$VERSION" -m "[skip ci] Release v$VERSION"
|
||||||
|
git push origin "v$VERSION"
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
- name: cache
|
- name: cache
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,13 @@
|
||||||
artifacts
|
artifacts
|
||||||
projects/**/pom.xml
|
projects/**/pom.xml
|
||||||
|
|
||||||
|
# do-blog static pages (generated by com.oly.static-sites.do-blog.ssr)
|
||||||
|
/bases/do-blog/resources/public/index.html
|
||||||
|
/bases/do-blog/resources/public/about/
|
||||||
|
/bases/do-blog/resources/public/archive/
|
||||||
|
/bases/do-blog/resources/public/chess/
|
||||||
|
/bases/do-blog/resources/public/posts/
|
||||||
|
|
||||||
# nrepl
|
# nrepl
|
||||||
.nrepl-port
|
.nrepl-port
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -271,7 +271,42 @@
|
||||||
|
|
||||||
|
|
||||||
(defn grouped-lists-page [data]
|
(defn grouped-lists-page [data]
|
||||||
[articles
|
(ui/grouped-articles-list {:title "Clojure on the JVM"
|
||||||
|
:groups
|
||||||
|
[{:title "Clojure on the JVM"
|
||||||
|
:articles [{:title "Clojure"
|
||||||
|
:description "The original language running on the jvm with access to the java eco system"
|
||||||
|
:icon-image "https://clojure.org/images/clojure-logo-120b.png"
|
||||||
|
:page "clojure-basics"}
|
||||||
|
{:title "Clojurescript"
|
||||||
|
:description "Clojure running in the browser or on top of node, with access to the js eco system."
|
||||||
|
:icon-image "https://clojurescript.org/images/cljs-logo-60b.png"
|
||||||
|
:page "clojurescript-basics"}
|
||||||
|
{:title "ClojureCLR"
|
||||||
|
:description "Clojure running on microsofts CLR with access to .net ecosystem"
|
||||||
|
:icon-image "https://clojure.org/images/clojure-logo-120b.png"
|
||||||
|
:page "clojureclr-basics"}
|
||||||
|
{:title "ClojureDart"
|
||||||
|
:description "Clojure for dart, use clojure to build apps using flutter"
|
||||||
|
:page "clojuredart-info"}]}
|
||||||
|
{:title "Clojure for GO Lang"
|
||||||
|
:articles [ {:title "Let GO"
|
||||||
|
:description "Clojure for go, use clojure to build apps using go runtime"
|
||||||
|
:page "clojureletgo-info"}]}
|
||||||
|
{:title "Clojure for python"
|
||||||
|
:articles [ {:title "Let GO"
|
||||||
|
:description "Clojure for go, use clojure to build apps using go runtime"
|
||||||
|
:page "clojureletgo-info"}]}
|
||||||
|
{:title "Clojure native"
|
||||||
|
:articles [ {:title "Ferret"
|
||||||
|
:description "Clojure for go, use clojure to build apps using go runtime"
|
||||||
|
:page "clojureletgo-info"}]}
|
||||||
|
|
||||||
|
]}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
#_[articles
|
||||||
{:title (-> data :title)
|
{:title (-> data :title)
|
||||||
:body (-> data :intro)
|
:body (-> data :intro)
|
||||||
:articles
|
:articles
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,22 @@
|
||||||
(ns com.oly.static-sites.clojure-demos.routes
|
(ns com.oly.static-sites.clojure-demos.routes
|
||||||
(:require [spec-tools.data-spec :as ds]))
|
(:require [spec-tools.data-spec :as ds]))
|
||||||
|
|
||||||
|
{:title "Clojure Demos"
|
||||||
|
:groups [{:title "Dialects & Interop"
|
||||||
|
:articles [{:title "Clojure"
|
||||||
|
:description "The original language running on the jvm with access to the java eco system"
|
||||||
|
:img-src "https://clojure.org/images/clojure-logo-120b.png"}
|
||||||
|
{:title "Clojurescript"
|
||||||
|
:description "Clojure running in the browser or on top of node, with access to the js eco system."
|
||||||
|
:img-src "https://clojurescript.org/images/cljs-logo-60b.png"}]}
|
||||||
|
{:title "DSL's"
|
||||||
|
:articles [{:title "Hiccup HTML Demo"
|
||||||
|
:description "Hiccup is a DSL for generating HTML it uses data structures over strings to generate html"
|
||||||
|
:icon-image "https://miro.medium.com/max/1400/1*CEYFj5R57UFyCXts2nsBqA.png"}
|
||||||
|
{:title "Honey SQL Demo"
|
||||||
|
:description "Similar to honey but for SQL allows you to split apart your complex queries into parts and compose them together."
|
||||||
|
:icon-image "https://miro.medium.com/max/1400/1*CEYFj5R57UFyCXts2nsBqA.png"}]}]}
|
||||||
|
|
||||||
|
|
||||||
;; put constant data here
|
;; put constant data here
|
||||||
(def site-data
|
(def site-data
|
||||||
|
|
@ -10,26 +26,27 @@
|
||||||
:pages {:dialects {:title "Dialects & Interop"
|
:pages {:dialects {:title "Dialects & Interop"
|
||||||
:intro "Clojure has the ability to run on multiple technology stacks, this allows code reuse and consistency regardless of which eco system you want to make use of."
|
:intro "Clojure has the ability to run on multiple technology stacks, this allows code reuse and consistency regardless of which eco system you want to make use of."
|
||||||
:key :dialects
|
:key :dialects
|
||||||
:demos [{:title "Clojure"
|
:demos [{:title "CLojure"
|
||||||
:description "The original language running on the jvm with access to the java eco system"
|
:articles [{:title "Clojure"
|
||||||
:icon-image "https://clojure.org/images/clojure-logo-120b.png"
|
:description "The original language running on the jvm with access to the java eco system"
|
||||||
:page "clojure-basics"}
|
:icon-image "https://clojure.org/images/clojure-logo-120b.png"
|
||||||
{:title "Clojurescript"
|
:page "clojure-basics"}
|
||||||
:description "Clojure running in the browser or on top of node, with access to the js eco system."
|
{:title "Clojurescript"
|
||||||
:icon-image "https://clojurescript.org/images/cljs-logo-60b.png"
|
:description "Clojure running in the browser or on top of node, with access to the js eco system."
|
||||||
:page "clojurescript-basics"}
|
:icon-image "https://clojurescript.org/images/cljs-logo-60b.png"
|
||||||
{:title "ClojureCLR"
|
:page "clojurescript-basics"}
|
||||||
:description "Clojure running on microsofts CLR with access to .net ecosystem"
|
{:title "ClojureCLR"
|
||||||
:icon-image "https://clojure.org/images/clojure-logo-120b.png"
|
:description "Clojure running on microsofts CLR with access to .net ecosystem"
|
||||||
:page "clojureclr-basics"}
|
:icon-image "https://clojure.org/images/clojure-logo-120b.png"
|
||||||
{:title "ClojureDart"
|
:page "clojureclr-basics"}
|
||||||
:description "Clojure for dart, use clojure to build apps using flutter"
|
{:title "ClojureDart"
|
||||||
:page "clojuredart-info"}
|
:description "Clojure for dart, use clojure to build apps using flutter"
|
||||||
{:title "LetGO"
|
:page "clojuredart-info"}
|
||||||
:description "Clojure for go, use clojure to build apps using go runtime"
|
{:title "Let GO"
|
||||||
:page "clojureletgo-info"}
|
:description "Clojure for go, use clojure to build apps using go runtime"
|
||||||
|
:page "clojureletgo-info"}
|
||||||
|
|
||||||
]
|
]}]
|
||||||
|
|
||||||
}
|
}
|
||||||
:dsl {:title "DSL's"
|
:dsl {:title "DSL's"
|
||||||
|
|
@ -125,7 +142,7 @@
|
||||||
|
|
||||||
["/dialects/"
|
["/dialects/"
|
||||||
{:name :dialects
|
{:name :dialects
|
||||||
:view :list}]
|
:view :grouped-lists}]
|
||||||
|
|
||||||
["/examples/"
|
["/examples/"
|
||||||
{:name :examples
|
{:name :examples
|
||||||
|
|
|
||||||
|
|
@ -3,15 +3,13 @@
|
||||||
org.clojure/core.async {:mvn/version "1.6.673"}
|
org.clojure/core.async {:mvn/version "1.6.673"}
|
||||||
org.clojure/clojurescript {:mvn/version "1.11.60"}
|
org.clojure/clojurescript {:mvn/version "1.11.60"}
|
||||||
|
|
||||||
reagent/reagent {:mvn/version "1.1.1"}
|
no.cjohansen/replicant {:mvn/version "2026.07.1"}
|
||||||
tick/tick {:mvn/version "0.5.0"}
|
tick/tick {:mvn/version "0.5.0"}
|
||||||
metosin/reitit {:mvn/version "0.5.18"}
|
metosin/reitit {:mvn/version "0.5.18"}
|
||||||
|
|
||||||
cljs-ajax/cljs-ajax {:mvn/version "0.8.4"}
|
cljs-ajax/cljs-ajax {:mvn/version "0.8.4"}
|
||||||
|
|
||||||
datascript/datascript {:mvn/version "1.4.0"}
|
datascript/datascript {:mvn/version "1.4.0"}
|
||||||
olymk2/tachyon-reagent {:git/url "https://gitlab.com/olymk2/tachyon-reagent.git"
|
|
||||||
:sha "e422af7b41266f7bc90ab78a24fb93f32be61385"}
|
|
||||||
olymk2/cl-eorg {:git/url "https://gitlab.com/olymk2/cl-org.git"
|
olymk2/cl-eorg {:git/url "https://gitlab.com/olymk2/cl-org.git"
|
||||||
:sha "13e57f11da75516844922fe28bfd6aa7692b7c34"}
|
:sha "13e57f11da75516844922fe28bfd6aa7692b7c34"}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,9 @@
|
||||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.8.2/css/all.min.css" />
|
<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" />
|
<link rel="stylesheet" href="https://unpkg.com/tachyons@4.12.0/css/tachyons.min.css" />
|
||||||
<script src="https://cdn.tailwindcss.com"></script>
|
<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">
|
<style type="text/css" media="screen">
|
||||||
#loading {
|
#loading {
|
||||||
-webkit-animation: rotation 2s infinite linear;
|
-webkit-animation: rotation 2s infinite linear;
|
||||||
|
|
@ -25,7 +28,9 @@
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body class="ma0 pa0 h-100">
|
<body class="ma0 pa0 h-100">
|
||||||
<div id="app" class="ma0 pa0 h-100">
|
<!-- 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-->
|
||||||
<section id="startup" class="h-100">
|
<section id="startup" class="h-100">
|
||||||
<noscript>
|
<noscript>
|
||||||
You need to enable JavaScript to run this app.
|
You need to enable JavaScript to run this app.
|
||||||
|
|
@ -38,7 +43,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
</div>
|
<!--/app--></div>
|
||||||
<script src="/js/base.js" type="text/javascript"></script>
|
<script src="/js/base.js" type="text/javascript"></script>
|
||||||
<script src="/js/app.js" type="text/javascript"></script>
|
<script src="/js/app.js" type="text/javascript"></script>
|
||||||
</body>
|
</body>
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
#+TITLE: Chocolate melt pudding
|
||||||
|
#+DATE: 2025-10-31 12:00:00 UTC
|
||||||
|
#+HTML_DOCTYPE: <!DOCTYPE html>
|
||||||
|
#+DESCRIPTION: puddings
|
||||||
|
#+FILETAGS: recipe:puddings
|
||||||
|
#+CATEGORY: recipe
|
||||||
|
#+SLUG: chocolate-melt-pudding
|
||||||
|
|
||||||
|
|
||||||
|
* Info
|
||||||
|
Serves 4
|
||||||
|
|
||||||
|
* Ingredients
|
||||||
|
- 110g (4 oz) pudding rice
|
||||||
|
- 25g (1 oz) granulated sugar
|
||||||
|
- 25g (1 oz) margarine or butter
|
||||||
|
- 12L (2 pt) milk
|
||||||
|
- ground cinnamon, nutmeg or vanilla extract (optional)
|
||||||
|
* Instructions
|
||||||
|
1. Use some of the butter to grease the bowl of the slow cooker.
|
||||||
|
2. Add milk, rice, sugar and remaining butter and either ground cinnamon, nutmeg or vanilla extract.
|
||||||
|
3. Give the contents a stir and replace the lid.
|
||||||
|
4. Turn the slow cooker onto high and cook for 3-4 hours or until the rice as absorbed the liquid.
|
||||||
|
5. Stir around halfway through.
|
||||||
|
|
@ -1,253 +1,83 @@
|
||||||
(ns com.oly.static-sites.do-blog.core
|
(ns com.oly.static-sites.do-blog.core
|
||||||
(:require [ajax.core :refer [GET text-response-format]]
|
(:require [ajax.core :refer [GET text-response-format]]
|
||||||
[com.oly.static-sites.do-blog.theme :refer [tachyon-theme]]
|
|
||||||
[cl-eorg.html :refer [org->to-hiccup]]
|
|
||||||
[cl-eorg.parser :as parser]
|
|
||||||
[cljs.reader :as reader]
|
[cljs.reader :as reader]
|
||||||
[datascript.core :as d]
|
[clojure.walk :as walk]
|
||||||
[clojure.string :as str]
|
[replicant.dom :as r]
|
||||||
[reagent.core :as r]
|
|
||||||
[reagent.dom :as dom]
|
|
||||||
[reitit.frontend :as rf]
|
|
||||||
[reitit.frontend.easy :as rfe]
|
[reitit.frontend.easy :as rfe]
|
||||||
[tachyons.cards :refer [profile-card]]
|
[com.oly.static-sites.do-blog.routes :refer [router normalize-match]]
|
||||||
[clojure.core.async :refer [<! >! chan go]]
|
[com.oly.static-sites.do-blog.views :as views]
|
||||||
[tick.core :as t]
|
|
||||||
[tick.timezone]
|
|
||||||
[tick.locale-en-us]
|
|
||||||
;; [cljsjs.js-joda-timezone]
|
|
||||||
;; [henryw374.js-joda-locale_en-us]
|
|
||||||
[com.oly.static-sites.do-blog.pages.components.core :refer [ui-tags title-text-image article-list-author-media-flipped]]
|
|
||||||
[com.oly.static-sites.do-blog.pages.helpers.database
|
[com.oly.static-sites.do-blog.pages.helpers.database
|
||||||
:refer [state document conn schema latest-article search-articles]]
|
:refer [state load-index! latest-article org->document]]
|
||||||
;; [com.oly.static-sites.ui-hiccup.interface :refer [board square]]
|
[com.oly.static-sites.do-blog.pages.chess-board :as chess]
|
||||||
;; [com.oly.static-sites.do-blog.pages.chess.render :refer [draw-board]]
|
[com.oly.static-sites.do-blog.pages.chess.state :as chess-state]
|
||||||
;; [com.oly.static-sites.do-blog.pages.chess.state :refer [start-state]]
|
[com.oly.static-sites.do-blog.pages.chess.vstate :as viking-state])
|
||||||
[com.oly.static-sites.do-blog.pages.home :refer [home-page]]
|
(:require-macros [cl-eorg.macros :refer [org-doc->move-process]]))
|
||||||
[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.chess-board :refer [chess-page]]
|
|
||||||
[com.oly.static-sites.do-blog.pages.about :refer [about-page]])
|
|
||||||
(:require-macros [cl-eorg.macros :refer [org-doc->move-process inline-filelist-map]]))
|
|
||||||
|
|
||||||
|
|
||||||
;(set! js/JSJoda (.use js/JSJoda js/JSJodaLocale))
|
|
||||||
|
|
||||||
(inline-filelist-map "bases/do-blog/resources/documents/")
|
|
||||||
|
|
||||||
|
;; Copy org documents into public/ and write org-meta-index.edn at compile time.
|
||||||
(org-doc->move-process
|
(org-doc->move-process
|
||||||
"bases/do-blog/resources/documents/"
|
"bases/do-blog/resources/documents/"
|
||||||
"bases/do-blog/resources/public/documents/")
|
"bases/do-blog/resources/public/documents/")
|
||||||
|
|
||||||
(d/listen!
|
;; Rendering
|
||||||
conn
|
|
||||||
(fn [tx-report]
|
|
||||||
;; Only update if data was modified
|
|
||||||
(when (:tx-data tx-report)
|
|
||||||
(swap! state update :new-data inc))))
|
|
||||||
|
|
||||||
(defn convert-date [text]
|
(defn render! []
|
||||||
(when text
|
;; Nothing to render until the first route has resolved; until then the
|
||||||
(let [parts (-> text
|
;; static (server generated) HTML stays in place.
|
||||||
clojure.string/trim
|
(when (:route @state)
|
||||||
(clojure.string/split #" "))]
|
(r/render (js/document.getElementById "app") (views/app @state))))
|
||||||
(-> (t/date (first parts))))))
|
|
||||||
|
|
||||||
|
;; Event handling for data driven handlers, e.g. [[:search/set-terms :event.target/value]]
|
||||||
|
|
||||||
(defn href
|
(defn interpolate [event actions]
|
||||||
"Build up path to document"
|
(walk/postwalk
|
||||||
[doc]
|
(fn [x]
|
||||||
(str (rfe/href :posts {:path ""}) (:relative-path doc)))
|
(case x
|
||||||
|
:event.target/value (.. event -target -value)
|
||||||
|
x))
|
||||||
|
actions))
|
||||||
|
|
||||||
(defn fetch-document-cb [doc callback]
|
(defn handle-action [[action & args]]
|
||||||
(GET (str "/documents/" doc)
|
(case action
|
||||||
{:response-format (text-response-format)
|
:search/set-terms (swap! state assoc-in [:search :terms] (first args))
|
||||||
:handler callback}))
|
(js/console.warn "Unknown action" (pr-str action))))
|
||||||
|
|
||||||
(defn org-dsl-render
|
(defn dispatch [{:replicant/keys [dom-event]} actions]
|
||||||
"Render and store parsed documents"
|
(run! handle-action (interpolate dom-event actions)))
|
||||||
[doc]
|
|
||||||
(swap! state assoc-in [:document :body] (parser/parse doc))
|
|
||||||
(swap! state assoc-in [:document :hiccup] (into [:div] (vec (rest (org->to-hiccup tachyon-theme (-> @state :document :body))))))
|
|
||||||
(swap! state assoc-in [:document :details] (parser/filter-root-nodes [] (-> @state :document :body))))
|
|
||||||
|
|
||||||
(defn render-doc-from-path [path]
|
;; Navigation
|
||||||
(if path
|
|
||||||
(let [comm (r/atom (chan))]
|
|
||||||
(fetch-document-cb path #(go (>! @comm %)))
|
|
||||||
(go (reset! document (<! @comm))
|
|
||||||
(swap! state assoc :search {:terms nil :results []})
|
|
||||||
(org-dsl-render @document)))
|
|
||||||
(prn (str "render from path nothing found ") path)))
|
|
||||||
|
|
||||||
|
(defn fetch-text [path on-success]
|
||||||
|
(GET path {:response-format (text-response-format)
|
||||||
|
:handler on-success
|
||||||
|
:error-handler #(js/console.error "Failed to fetch" path (clj->js %))}))
|
||||||
|
|
||||||
(def router
|
(defn show-route! [match & {:as extra}]
|
||||||
(rf/router
|
(swap! state merge {:route match :search {:terms ""}} extra))
|
||||||
[["/"
|
|
||||||
{:name :homepage
|
|
||||||
:init 'switch-to-latest
|
|
||||||
:view #'home-page}]
|
|
||||||
["/archive/{*tag}"
|
|
||||||
{:name :archive
|
|
||||||
:view #'archive-page}]
|
|
||||||
["/tags/{*path}"
|
|
||||||
{:name :tags
|
|
||||||
:view 'post
|
|
||||||
:parameters {:path string?}}]
|
|
||||||
["/chess"
|
|
||||||
{:name :chess
|
|
||||||
:view #'chess-page}]
|
|
||||||
["/about"
|
|
||||||
{:name :about
|
|
||||||
:view #'about-page}]
|
|
||||||
#_["/book/{*path}"
|
|
||||||
{:name :book
|
|
||||||
:view 'book
|
|
||||||
:parameters {:path string?}}]
|
|
||||||
["/posts/{*path}"
|
|
||||||
{:name :posts
|
|
||||||
:view #'article-page
|
|
||||||
:state render-doc-from-path
|
|
||||||
:parameters {:path string?}}]]))
|
|
||||||
|
|
||||||
(defn switch-to-latest
|
(defn show-document! [match relative-path]
|
||||||
[path-params]
|
(if relative-path
|
||||||
(-> (latest-article)
|
(fetch-text (str "/documents/" relative-path)
|
||||||
(render-doc-from-path)))
|
#(show-route! match :document (org->document %)))
|
||||||
|
(js/console.warn "No document found for" (pr-str (:path match)))))
|
||||||
|
|
||||||
(defn select-initial-page
|
(defn on-navigate [raw-match]
|
||||||
[path-params]
|
(when-let [match (normalize-match raw-match)]
|
||||||
(if path-params
|
(case (-> match :data :name)
|
||||||
(render-doc-from-path path-params)
|
:homepage (show-document! match (latest-article))
|
||||||
(-> (latest-article)
|
:posts (show-document! match (-> match :path-params :path))
|
||||||
(render-doc-from-path))))
|
:chess (do (chess/start! match)
|
||||||
|
(show-route! match))
|
||||||
|
(show-route! match))))
|
||||||
|
|
||||||
(defn ui-search [search]
|
(defn ^:dev/after-load reload! []
|
||||||
[:div
|
(render!))
|
||||||
[:input.w-100.center.input-reset.ba.b--black-20.pa2.mb2
|
|
||||||
{:type "text"
|
|
||||||
:placeholder "Search"
|
|
||||||
:on-change (fn [evt]
|
|
||||||
(swap! state assoc :search {:active true})
|
|
||||||
(swap! state assoc :search {:terms (-> evt .-target .-value)}))}]])
|
|
||||||
|
|
||||||
(defn ui-sidebar [{:keys [sidebar body]}]
|
|
||||||
(let [search (r/atom "")]
|
|
||||||
(fn [{:keys [sidebar body]}]
|
|
||||||
[:div.h-100.flex.items-stretch
|
|
||||||
[:div.dn.db-l.pa3.bg-blue {:style {:flex-basis "20rem" :flex-grow "1"}} sidebar]
|
|
||||||
[:div.ma3.pa3 {:style {:flex-basis "0" :flex-grow "999"}}
|
|
||||||
[ui-search search]
|
|
||||||
body]])))
|
|
||||||
|
|
||||||
#_(defn ui-tags [meta]
|
|
||||||
[:div (map-indexed
|
|
||||||
(fn [idx tag]
|
|
||||||
[:span.mr2 {:key idx}
|
|
||||||
[pill-grow
|
|
||||||
{:href (rfe/href :archive {:tag tag})
|
|
||||||
:text tag}]])
|
|
||||||
(-> meta :filetags extract-tags))])
|
|
||||||
|
|
||||||
#_(defn title-text-image [{:keys [title content] :as optional} tags]
|
|
||||||
[:article.lh-copy.f4.mt-0
|
|
||||||
[:h1.f2 title]
|
|
||||||
(when tags
|
|
||||||
[ui-tags tags])
|
|
||||||
(when (:img-src optional)
|
|
||||||
[:img.w-100.f5.measure {:src (:img-src optional) :alt (:img-alt optional)}])
|
|
||||||
content])
|
|
||||||
|
|
||||||
(defn layout [content]
|
|
||||||
(let [search (r/cursor state [:search :terms])
|
|
||||||
active-search (r/cursor state [:search :active])
|
|
||||||
org-index (r/cursor state [:index])]
|
|
||||||
(fn [content]
|
|
||||||
|
|
||||||
[:<>
|
|
||||||
[:link {:rel "stylesheet" :href "https://unpkg.com/tachyons@4.12.0/css/tachyons.min.css"}]
|
|
||||||
[:link {:rel "stylesheet" :href "https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.15.3/css/fontawesome.min.css"}]
|
|
||||||
[:style
|
|
||||||
".font{font-family: \"Roboto Slab\",serif !important;}"
|
|
||||||
".r90{transition: all 3s; transform-style: preserve-3d; transform-origin: top left; transform: rotate3d(0,1,0,180deg); backface-visibility: visible;}
|
|
||||||
|
|
||||||
|
|
||||||
.r180-back{transition: all 3s; transform-style: preserve-3d; transform-origin: top left; transform: rotate3d(0,1,0,180deg); backface-visibility: visible;}
|
|
||||||
.r180-front{transition: all 3s; transform-style: preserve-3d; transform-origin: top left; transform: rotate3d(0,1,0,180deg); backface-visibility: hidden;}
|
|
||||||
.r0{transition: all 3s; transform-style: preserve-3d; transform-origin: top left; transform: rotate3d(0,1,0,0deg); backface-visibility: visible;}"]
|
|
||||||
[:div.font.h-100
|
|
||||||
[ui-sidebar
|
|
||||||
{:body [:div (when (true? @active-search)
|
|
||||||
[article-list-author-media-flipped
|
|
||||||
"Articles"
|
|
||||||
(search-articles {:search @search})])
|
|
||||||
content
|
|
||||||
]
|
|
||||||
:sidebar [:div
|
|
||||||
[profile-card {:name "Oly" :tagline "Earthling, Software Engineer" :img-src "/images/default/me.png"}]
|
|
||||||
[:ul.list.pl0.measure.center
|
|
||||||
[:li.lh-copy.pv3.b--black-30.ba.bt-0.bl-0.br-0
|
|
||||||
[:a.black.f3.link.hover-green
|
|
||||||
{:href (rfe/href :homepage)} "Home"]]
|
|
||||||
[:li.lh-copy.pv3.b--black-30.ba.bt-0.bl-0.br-0
|
|
||||||
[:a.black.f3.link.hover-green
|
|
||||||
{:href (rfe/href :archive {:tag ""})} "Past articles"]]
|
|
||||||
[:li.lh-copy.pv3.b--black-30.ba.bt-0.bl-0.br-0
|
|
||||||
[:a.black.f3.link.hover-green
|
|
||||||
{:href (rfe/href :chess)} "Chess"]]
|
|
||||||
[:li.lh-copy.pv3.b--black-30.ba.bt-0.bl-0.br-0
|
|
||||||
[:a.black.f3.link.hover-green
|
|
||||||
{:href (rfe/href :about)} "About"]]
|
|
||||||
#_[:li.lh-copy.pv3.b--black-30.ba.bt-0.bl-0.br-0
|
|
||||||
[:a.black.f3.link.hover-green
|
|
||||||
{:href (rfe/href :book {:path ""})} "Book test"]]]]}]]])))
|
|
||||||
|
|
||||||
(defn ^:dev/after-load reagent-render [hiccup]
|
|
||||||
(swap! state update :refresh inc)
|
|
||||||
(dom/render [hiccup] (js/document.getElementById "app")))
|
|
||||||
|
|
||||||
|
|
||||||
(defn render-page []
|
|
||||||
(let [current-page (r/cursor state [:current-route])
|
|
||||||
update (r/cursor state [:refresh])]
|
|
||||||
;; load in the latest document
|
|
||||||
(fn []
|
|
||||||
@update
|
|
||||||
(swap! state assoc :search {:active false})
|
|
||||||
(when (-> @current-page :data :init)
|
|
||||||
((-> @current-page :data :init) nil)
|
|
||||||
((-> @current-page :data :init) (-> @current-page :parameters :path :path)))
|
|
||||||
(when (-> @current-page :data :state)
|
|
||||||
((-> @current-page :data :state) (-> @current-page :parameters :path :path)))
|
|
||||||
[layout [(-> @current-page :data :view) (-> @current-page)]])))
|
|
||||||
|
|
||||||
(defn init []
|
(defn init []
|
||||||
(rfe/start!
|
(r/set-dispatch! dispatch)
|
||||||
router
|
(add-watch state ::render (fn [_ _ _ _] (render!)))
|
||||||
(fn [m]
|
(add-watch chess-state/game-state ::render (fn [_ _ _ _] (render!)))
|
||||||
(prn m)
|
(add-watch viking-state/game-state ::render (fn [_ _ _ _] (render!)))
|
||||||
(swap! state assoc
|
(fetch-text "/documents/org-meta-index.edn"
|
||||||
:current-route m)
|
(fn [response]
|
||||||
(switch-to-latest (-> @state :current-route :parameters :path :path))
|
(load-index! (reader/read-string response))
|
||||||
)
|
(rfe/start! router on-navigate {:use-fragment false}))))
|
||||||
{:use-fragment false})
|
|
||||||
|
|
||||||
(GET "/documents/org-meta-index.edn"
|
|
||||||
{:handler (fn [response]
|
|
||||||
(->> (reader/read-string response)
|
|
||||||
;; filter out missing dates
|
|
||||||
(filter (fn [doc] (some? (:date doc))))
|
|
||||||
(mapv #(assoc % :tags (into [] (:filetags %))))
|
|
||||||
(mapv #(assoc % :date (convert-date (:date %))))
|
|
||||||
(swap! state assoc :index))
|
|
||||||
(d/reset-conn! conn (d/empty-db schema))
|
|
||||||
(d/transact! conn (:index @state))
|
|
||||||
(select-initial-page (-> @state :current-route :parameters :path :path)))})
|
|
||||||
(reagent-render render-page))
|
|
||||||
|
|
||||||
;;(comment )
|
|
||||||
;; (-> @state :document)
|
|
||||||
;; (latest-article)
|
|
||||||
|
|
||||||
; (switch-to-latest)
|
|
||||||
;; (org->to-hiccup tachyon-theme (-> @state :document :body))
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
(ns com.oly.static-sites.do-blog.pages.about)
|
||||||
|
|
||||||
|
(defn about-page [_state]
|
||||||
|
[:div "hi2"])
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
(ns com.oly.static-sites.do-blog.pages.about)
|
|
||||||
|
|
||||||
(defn about-page [{:keys [path-params] :as route}]
|
|
||||||
(fn [{:keys [path-params] :as route}]
|
|
||||||
[:div "hi2"]))
|
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
(ns com.oly.static-sites.do-blog.pages.archive
|
||||||
|
(:require [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]]))
|
||||||
|
|
||||||
|
(defn archive-page [{:keys [route search]}]
|
||||||
|
(let [articles (search-articles (merge {:search (:terms search)}
|
||||||
|
(:path-params route)))]
|
||||||
|
[: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))]]})})]))
|
||||||
|
|
@ -1,21 +0,0 @@
|
||||||
(ns com.oly.static-sites.do-blog.pages.archive
|
|
||||||
(:require [reagent.core :as r]
|
|
||||||
[reitit.frontend.easy :as rfe]
|
|
||||||
[tachyons.definition-lists :refer [simple]]
|
|
||||||
[com.oly.static-sites.do-blog.pages.helpers.utils :refer [format-date]]
|
|
||||||
[com.oly.static-sites.do-blog.pages.helpers.database :refer [search-articles state]]))
|
|
||||||
|
|
||||||
(defn archive-page [{:keys [path-params] :as route}]
|
|
||||||
(let [search (r/cursor state [:search :terms])
|
|
||||||
org-index (r/reaction (search-articles (merge {:search @search} path-params)))]
|
|
||||||
(fn [{:keys [path-params] :as route}]
|
|
||||||
[:div {:key "search"}
|
|
||||||
[:h1 "Past articles"]
|
|
||||||
[simple
|
|
||||||
{:list
|
|
||||||
(map-indexed (fn [idx doc]
|
|
||||||
{:text [:div [:a.f4.lh-copy {:href (str (rfe/href :posts {:path ""}) (:relative-path doc))
|
|
||||||
:key idx}
|
|
||||||
(str (format-date (:date doc))
|
|
||||||
#_(convert-date (:date doc)) " " (:title doc))]]})
|
|
||||||
@org-index)}]])))
|
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
(ns com.oly.static-sites.do-blog.pages.article
|
||||||
|
(:require [com.oly.static-sites.do-blog.pages.components.core :refer [title-text-image]]))
|
||||||
|
|
||||||
|
(defn article-page [{:keys [document]}]
|
||||||
|
(title-text-image
|
||||||
|
{:title (-> document :details :title)
|
||||||
|
:content (-> document :hiccup)}
|
||||||
|
(-> document :details)))
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
(ns com.oly.static-sites.do-blog.pages.article
|
|
||||||
(:require [reagent.core :as r]
|
|
||||||
[reitit.frontend.easy :as rfe]
|
|
||||||
[com.oly.static-sites.do-blog.pages.helpers.utils :refer [format-date]]
|
|
||||||
[com.oly.static-sites.do-blog.pages.helpers.database :refer [search-articles state]]
|
|
||||||
[com.oly.static-sites.do-blog.pages.components.core :refer [ui-tags title-text-image article-list-author-media-flipped]]))
|
|
||||||
|
|
||||||
|
|
||||||
(defn article-page [{:keys [path-params] :as route}]
|
|
||||||
(let [document (r/cursor state [:document])]
|
|
||||||
(fn [{:keys [path-params] :as route}]
|
|
||||||
[:<>
|
|
||||||
[title-text-image
|
|
||||||
{:title (-> @document :details :title)
|
|
||||||
:content (-> @document :hiccup)}
|
|
||||||
(-> @document :details)]])))
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
(ns com.oly.static-sites.do-blog.pages.chess.state
|
(ns com.oly.static-sites.do-blog.pages.chess.state)
|
||||||
(:require [reagent.core :as r]))
|
|
||||||
|
|
||||||
(def white-circle "○ ")
|
(def white-circle "○ ")
|
||||||
(def white-square "⬜")
|
(def white-square "⬜")
|
||||||
|
|
@ -33,7 +32,7 @@
|
||||||
;(def alternate-color (alternate-black-white))
|
;(def alternate-color (alternate-black-white))
|
||||||
(def board {:tile-size [8 8]})
|
(def board {:tile-size [8 8]})
|
||||||
(defonce game-state
|
(defonce game-state
|
||||||
(r/atom {:player-one {}
|
(atom {:player-one {}
|
||||||
:player-two {}
|
:player-two {}
|
||||||
:board []}))
|
:board []}))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,11 @@
|
||||||
(ns com.oly.static-sites.do-blog.pages.chess.vstate
|
(ns com.oly.static-sites.do-blog.pages.chess.vstate)
|
||||||
(:require [reagent.core :as r]))
|
|
||||||
|
|
||||||
|
|
||||||
(def black-viking-rook "♜")
|
(def black-viking-rook "♜")
|
||||||
(def black-viking-king "♚")
|
(def black-viking-king "♚")
|
||||||
|
|
||||||
(defonce game-state
|
(defonce game-state
|
||||||
(r/atom {:player-one {}
|
(atom {:player-one {}
|
||||||
:player-two {}
|
:player-two {}
|
||||||
:board []}))
|
:board []}))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@
|
||||||
[com.oly.static-sites.do-blog.pages.chess.state
|
[com.oly.static-sites.do-blog.pages.chess.state
|
||||||
:refer [find-piece game-state start-state translate-char->piece]]
|
:refer [find-piece game-state start-state translate-char->piece]]
|
||||||
[com.oly.static-sites.do-blog.pages.chess.vstate :as v]
|
[com.oly.static-sites.do-blog.pages.chess.vstate :as v]
|
||||||
|
[com.oly.static-sites.do-blog.views :as views]
|
||||||
[com.oly.static-sites.ui-hiccup.interface :refer [board]]))
|
[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?widgetId=dochess
|
||||||
|
|
@ -181,30 +182,36 @@
|
||||||
(enhance-board click-square)
|
(enhance-board click-square)
|
||||||
(place-pieces-on-board start-state click-square))}))
|
(place-pieces-on-board start-state click-square))}))
|
||||||
|
|
||||||
(defn chess-page [{:keys [path-params query-params] :as route}]
|
(defn start!
|
||||||
|
"Reset the boards when navigating to the chess page."
|
||||||
|
[{:keys [query-params]}]
|
||||||
(if (:pieces query-params)
|
(if (:pieces query-params)
|
||||||
(chess-board-setup (chars->map (:pieces query-params)))
|
(chess-board-setup (chars->map (:pieces query-params)))
|
||||||
(chess-board-setup start-state))
|
(chess-board-setup start-state)))
|
||||||
(fn [{:keys [path-params] :as route}]
|
|
||||||
[: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)))]])
|
|
||||||
|
|
||||||
[:div (board 8 (-> @game-state :board))]
|
(defn chess-page [_state]
|
||||||
[:div "Viking chess board"]
|
[:div
|
||||||
[:div (board 11 (-> @v/game-state :board))]]))
|
(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)))]])
|
||||||
|
|
||||||
|
[:div (board 8 (-> @game-state :board))]
|
||||||
|
[:div "Viking chess board"]
|
||||||
|
[:div (board 11 (-> @v/game-state :board))]])
|
||||||
|
|
||||||
|
(defmethod views/page :chess [state]
|
||||||
|
(chess-page state))
|
||||||
|
|
||||||
(comment
|
(comment
|
||||||
(board-test 5)
|
(board-test 5)
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,60 @@
|
||||||
|
(ns com.oly.static-sites.do-blog.pages.components.core
|
||||||
|
"Pure hiccup components, shared between the browser and static generation.
|
||||||
|
Components are plain functions: call them, don't put them in a vector head."
|
||||||
|
(:require [com.oly.static-sites.do-blog.routes :refer [archive-href post-href]]
|
||||||
|
[com.oly.static-sites.do-blog.pages.helpers.utils :refer [extract-tags format-date]]))
|
||||||
|
|
||||||
|
;; Ported from tachyon-reagent
|
||||||
|
(defn pill-grow [{:keys [href text]}]
|
||||||
|
[:a.f6.grow.no-underline.br-pill.ph3.pv2.mb2.dib.white.bg-black {:href href}
|
||||||
|
text])
|
||||||
|
|
||||||
|
(defn profile-card [{:keys [img-src img-alt name tagline]}]
|
||||||
|
[:article.mw5.center.bg-white.br3.pa3.pa4-ns.mv3.ba.b--black-10
|
||||||
|
[:div.tc
|
||||||
|
[:img.br-100.h4.w4.dib.ba.b--black-05.pa2
|
||||||
|
{:src img-src
|
||||||
|
:alt img-alt}]
|
||||||
|
[: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)]
|
||||||
|
[:span.mr2 {:replicant/key tag}
|
||||||
|
(pill-grow {:href (archive-href tag)
|
||||||
|
:text tag})])])
|
||||||
|
|
||||||
|
(defn article-list-author-media-flipped [title articles]
|
||||||
|
[:section.mw7.center
|
||||||
|
(when title [:h2.athelas.ph3.ph0-l title])
|
||||||
|
(for [{:keys [title relative-path description date author alt thumbnail]} articles]
|
||||||
|
[:article.pv4.bb.b--black-10.ph3.ph0-l
|
||||||
|
{:replicant/key relative-path}
|
||||||
|
[:div.flex.flex-column.flex-row-ns
|
||||||
|
[:div.w-100.w-60-ns.pr3-ns.order-2.order-1-ns
|
||||||
|
[:a {:href (post-href relative-path)}
|
||||||
|
[:h1.f3.athelas.mt0.lh-title title]]
|
||||||
|
[:p.f5.f4-l.lh-copy.athelas description]]
|
||||||
|
(when thumbnail
|
||||||
|
[:div.pl3-ns.order-1.order-2-ns.mb4.mb0-ns.w-100.w-40-ns
|
||||||
|
[:img.db {:src thumbnail
|
||||||
|
:alt alt}]])]
|
||||||
|
[:p.f6.lh-copy.gray.mv0 (when author (str "By " author))
|
||||||
|
(when date [:time.f6.db.gray (format-date date)])]])])
|
||||||
|
|
||||||
|
(defn title-text-image [{:keys [title content] :as optional} tags]
|
||||||
|
[:article.lh-copy.f4.mt-0
|
||||||
|
[:h1.f2 title]
|
||||||
|
(when tags
|
||||||
|
(ui-tags tags))
|
||||||
|
(when (:img-src optional)
|
||||||
|
[:img.w-100.f5.measure {:src (:img-src optional) :alt (:img-alt optional)}])
|
||||||
|
content])
|
||||||
|
|
@ -1,41 +0,0 @@
|
||||||
(ns com.oly.static-sites.do-blog.pages.components.core
|
|
||||||
(:require [reitit.frontend.easy :as rfe]
|
|
||||||
[tachyons.buttons :refer [pill-grow]]
|
|
||||||
[com.oly.static-sites.do-blog.pages.helpers.utils :refer [extract-tags format-date]]
|
|
||||||
))
|
|
||||||
|
|
||||||
(defn ui-tags [meta]
|
|
||||||
[:div (map-indexed
|
|
||||||
(fn [idx tag]
|
|
||||||
[:span.mr2 {:key idx}
|
|
||||||
[pill-grow
|
|
||||||
{:href (rfe/href :archive {:tag tag})
|
|
||||||
:text tag}]])
|
|
||||||
(-> meta :filetags extract-tags))])
|
|
||||||
|
|
||||||
(defn article-list-author-media-flipped [title articles]
|
|
||||||
[:section.mw7.center
|
|
||||||
(when title [:h2.athelas.ph3.ph0-l title])
|
|
||||||
(map-indexed (fn [idx {:keys [title relative-path description date author src alt thumbnail] :as article}]
|
|
||||||
[:article.pv4.bb.b--black-10.ph3.ph0-l
|
|
||||||
{:keys idx}
|
|
||||||
[:div.flex.flex-column.flex-row-ns
|
|
||||||
[:div.w-100.w-60-ns.pr3-ns.order-2.order-1-ns
|
|
||||||
[:a {:href (str (rfe/href :posts {:path ""}) relative-path)}
|
|
||||||
[:h1.f3.athelas.mt0.lh-title title]]
|
|
||||||
[:p.f5.f4-l.lh-copy.athelas description]]
|
|
||||||
(when thumbnail [:div.pl3-ns.order-1.order-2-ns.mb4.mb0-ns.w-100.w-40-ns
|
|
||||||
[:img.db {:src thumbnail
|
|
||||||
:alt alt}]])]
|
|
||||||
[:p.f6.lh-copy.gray.mv0 (when author (str "By " author))
|
|
||||||
(when date [:time.f6.db.gray (format-date date)])]])
|
|
||||||
articles)])
|
|
||||||
|
|
||||||
(defn title-text-image [{:keys [title content] :as optional} tags]
|
|
||||||
[:article.lh-copy.f4.mt-0
|
|
||||||
[:h1.f2 title]
|
|
||||||
(when tags
|
|
||||||
[ui-tags tags])
|
|
||||||
(when (:img-src optional)
|
|
||||||
[:img.w-100.f5.measure {:src (:img-src optional) :alt (:img-alt optional)}])
|
|
||||||
content])
|
|
||||||
|
|
@ -0,0 +1,74 @@
|
||||||
|
(ns com.oly.static-sites.do-blog.pages.helpers.database
|
||||||
|
(:require [clojure.string :as str]
|
||||||
|
[datascript.core :as d]
|
||||||
|
[cl-eorg.html :refer [org->to-hiccup]]
|
||||||
|
[cl-eorg.parser :as parser]
|
||||||
|
[com.oly.static-sites.do-blog.theme :refer [tachyon-theme]]
|
||||||
|
[com.oly.static-sites.do-blog.pages.helpers.utils :refer [ltrim-slash convert-date]]))
|
||||||
|
|
||||||
|
(defonce schema {:tags {:db/cardinality :db.cardinality/many}})
|
||||||
|
(defonce conn (d/create-conn schema))
|
||||||
|
|
||||||
|
(defonce state
|
||||||
|
(atom {:route nil
|
||||||
|
:search {:terms ""}
|
||||||
|
:document {:details nil :hiccup nil}}))
|
||||||
|
|
||||||
|
(def db-search
|
||||||
|
'{:find [(pull ?e [*])]
|
||||||
|
:in [$]
|
||||||
|
:where
|
||||||
|
[[?e :title ?title]
|
||||||
|
[(get-else $ ?e :description :nil) ?description]
|
||||||
|
[?e :date ?date]
|
||||||
|
[(get-else $ ?e :thumbnail :nil) ?thumbnail]
|
||||||
|
[?e :relative-path ?path]]})
|
||||||
|
|
||||||
|
(defn db-search-filter
|
||||||
|
"Add where clauses to the datalog query when supplied"
|
||||||
|
[{:keys [search tag]}]
|
||||||
|
(let [re-search (when-not (str/blank? search)
|
||||||
|
(re-pattern (str "(?i)" search)))]
|
||||||
|
(cond-> db-search
|
||||||
|
(not (str/blank? tag))
|
||||||
|
(update-in [:where] #(conj % ['?e :tags tag]))
|
||||||
|
re-search
|
||||||
|
(update-in [:where] #(conj % [`(~'re-find ~re-search ~'?title)])))))
|
||||||
|
|
||||||
|
(defn search-articles [search]
|
||||||
|
(->> (d/q (db-search-filter search) @conn)
|
||||||
|
(flatten)
|
||||||
|
(sort-by :date)
|
||||||
|
reverse
|
||||||
|
(map #(assoc % :relative-path (ltrim-slash (:relative-path %))))))
|
||||||
|
|
||||||
|
(defn latest-article
|
||||||
|
"Relative path of the most recent article."
|
||||||
|
[]
|
||||||
|
(->> (search-articles {:search ""})
|
||||||
|
first
|
||||||
|
:relative-path))
|
||||||
|
|
||||||
|
(defn prepare-index
|
||||||
|
"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 %))))))
|
||||||
|
|
||||||
|
(defn load-index!
|
||||||
|
"Replace the article database with the parsed index entries."
|
||||||
|
[entries]
|
||||||
|
(let [index (prepare-index entries)]
|
||||||
|
(d/reset-conn! conn (d/empty-db schema))
|
||||||
|
(d/transact! conn index)
|
||||||
|
index))
|
||||||
|
|
||||||
|
(defn org->document
|
||||||
|
"Parse org text into the document map used by the views."
|
||||||
|
[text]
|
||||||
|
(let [body (parser/parse text)]
|
||||||
|
{:hiccup (into [:div] (rest (org->to-hiccup tachyon-theme body)))
|
||||||
|
:details (parser/filter-root-nodes [] body)}))
|
||||||
|
|
@ -1,62 +0,0 @@
|
||||||
(ns com.oly.static-sites.do-blog.pages.helpers.database
|
|
||||||
(:require [clojure.string :as str]
|
|
||||||
[reagent.core :as r]
|
|
||||||
[datascript.core :as d]
|
|
||||||
[com.oly.static-sites.do-blog.pages.helpers.utils :refer [ltrim-slash]]))
|
|
||||||
|
|
||||||
(defonce schema {:tags {:db/cardinality :db.cardinality/many}})
|
|
||||||
(defonce conn (d/create-conn schema))
|
|
||||||
(defonce document (r/atom {}))
|
|
||||||
(defonce state
|
|
||||||
(r/atom {:index []
|
|
||||||
:refresh 1
|
|
||||||
:search {:terms ""
|
|
||||||
:results []}
|
|
||||||
:document {:details nil :body nil}
|
|
||||||
:latest nil
|
|
||||||
:current-doc ""
|
|
||||||
:new-data 0
|
|
||||||
:current-key :org-01}))
|
|
||||||
|
|
||||||
;(def not-empty? (complement empty?))
|
|
||||||
|
|
||||||
(def db-search
|
|
||||||
'{:find [(pull ?e [*])]
|
|
||||||
:in [$]
|
|
||||||
:where
|
|
||||||
[[?e :title ?title]
|
|
||||||
[(get-else $ ?e :description :nil) ?description]
|
|
||||||
[?e :date ?date]
|
|
||||||
[(get-else $ ?e :thumbnail :nil) ?thumbnail]
|
|
||||||
[?e :relative-path ?path]]})
|
|
||||||
|
|
||||||
(defn check-match [re-patt title]
|
|
||||||
(re-find re-patt title))
|
|
||||||
|
|
||||||
(defn db-search-filter
|
|
||||||
"Add where clauses to the datalog query when supplied"
|
|
||||||
[{:keys [search tag]}]
|
|
||||||
(let [re-search (if (not (str/blank? search)) #_(js/RegEx (str "(?i)" search))
|
|
||||||
(re-pattern (str "(?i)" search)) nil)]
|
|
||||||
(cond-> db-search
|
|
||||||
(not (str/blank? tag))
|
|
||||||
(update-in [:where] #(conj % ['?e :tags tag]))
|
|
||||||
re-search
|
|
||||||
(update-in [:where] #(conj % [`(~'re-find ~re-search ~'?title)])))))
|
|
||||||
|
|
||||||
(defn search-articles [search]
|
|
||||||
(->>
|
|
||||||
(d/q (db-search-filter search) @conn)
|
|
||||||
(flatten)
|
|
||||||
(sort-by :date)
|
|
||||||
reverse
|
|
||||||
(map #(assoc %1 :relative-path (ltrim-slash (:relative-path %1))))))
|
|
||||||
|
|
||||||
(defn latest-article
|
|
||||||
"Just return the first item from search articles."
|
|
||||||
[]
|
|
||||||
(->> (search-articles {:search ""})
|
|
||||||
first
|
|
||||||
:relative-path))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +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]))
|
||||||
|
|
||||||
|
(defonce date-format (t/formatter "yyyy-MMM-dd"))
|
||||||
|
|
||||||
|
(defn format-date [date]
|
||||||
|
(when date
|
||||||
|
(t/format date-format date)))
|
||||||
|
|
||||||
|
(defn convert-date
|
||||||
|
"Convert an org date string like \"2020-06-27 12:00:00 UTC\" to a tick date."
|
||||||
|
[text]
|
||||||
|
(when-not (str/blank? text)
|
||||||
|
(-> text str/trim (str/split #" ") first t/date)))
|
||||||
|
|
||||||
|
(defn ltrim-slash "Trim a leading slash" [text] (str/replace text #"^/" ""))
|
||||||
|
|
||||||
|
(defn extract-tags
|
||||||
|
"Org filetags come either as \":a:b:\" strings or as a collection."
|
||||||
|
[tags]
|
||||||
|
(cond
|
||||||
|
(string? tags) (->> (str/split tags #":") (remove str/blank?) vec)
|
||||||
|
(coll? tags) (vec tags)
|
||||||
|
:else []))
|
||||||
|
|
@ -1,19 +0,0 @@
|
||||||
(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]))
|
|
||||||
|
|
||||||
(defonce date-format (t/formatter "yyyy-MMM-dd"))
|
|
||||||
|
|
||||||
(defn format-date [text]
|
|
||||||
(when text
|
|
||||||
(t/format date-format text)))
|
|
||||||
|
|
||||||
(defn ltrim-slash "Right trim a leading slash" [text] (str/replace text #"^/" ""))
|
|
||||||
|
|
||||||
(defn extract-tags [text]
|
|
||||||
(->> (clojure.string/split text #_(:filetags %) #":")
|
|
||||||
(reduce (fn [m a] (conj m a)) [])
|
|
||||||
vec))
|
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
(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))])
|
||||||
|
|
@ -1,21 +0,0 @@
|
||||||
(ns com.oly.static-sites.do-blog.pages.home
|
|
||||||
(:require [reagent.core :as r]
|
|
||||||
[reitit.frontend.easy :as rfe]
|
|
||||||
[com.oly.static-sites.do-blog.pages.helpers.utils :refer [format-date]]
|
|
||||||
[com.oly.static-sites.do-blog.pages.helpers.database :refer [search-articles state]]
|
|
||||||
[com.oly.static-sites.do-blog.pages.components.core :refer [ui-tags title-text-image article-list-author-media-flipped]]))
|
|
||||||
|
|
||||||
(defn home-page [{:keys [path] :as route}]
|
|
||||||
(let [search (r/cursor state [:search :terms])
|
|
||||||
latest (r/cursor state [:document])]
|
|
||||||
(fn []
|
|
||||||
[:<>
|
|
||||||
[:div
|
|
||||||
(if (empty? @search)
|
|
||||||
[title-text-image
|
|
||||||
{:title (-> @latest :details :title)
|
|
||||||
:content (-> @latest :hiccup)}
|
|
||||||
(-> @latest :details)]
|
|
||||||
[article-list-author-media-flipped
|
|
||||||
"Articles"
|
|
||||||
(search-articles {:search @search})])]])))
|
|
||||||
|
|
@ -0,0 +1,43 @@
|
||||||
|
(ns com.oly.static-sites.do-blog.routes
|
||||||
|
"Route table shared by the browser app and the static HTML generator.
|
||||||
|
|
||||||
|
Every page is generated as <path>/index.html, so URLs end in a slash
|
||||||
|
(static file servers redirect /foo to /foo/ when foo is a directory)."
|
||||||
|
(:require [clojure.string :as str]
|
||||||
|
[reitit.core :as rc]))
|
||||||
|
|
||||||
|
(def routes
|
||||||
|
[["/" {:name :homepage}]
|
||||||
|
["/archive/{*tag}" {:name :archive}]
|
||||||
|
["/chess/" {:name :chess}]
|
||||||
|
["/about/" {:name :about}]
|
||||||
|
["/posts/{*path}" {:name :posts}]])
|
||||||
|
|
||||||
|
(def router (rc/router routes))
|
||||||
|
|
||||||
|
(defn href
|
||||||
|
"Path for a named route, usable both in the browser and on the JVM."
|
||||||
|
([route-name] (href route-name nil))
|
||||||
|
([route-name params]
|
||||||
|
(some-> (rc/match-by-name router route-name params)
|
||||||
|
(rc/match->path))))
|
||||||
|
|
||||||
|
(defn- with-slash [path]
|
||||||
|
(if (str/ends-with? path "/") path (str path "/")))
|
||||||
|
|
||||||
|
(defn post-href [relative-path]
|
||||||
|
(with-slash (str "/posts/" relative-path)))
|
||||||
|
|
||||||
|
(defn archive-href [tag]
|
||||||
|
(with-slash (str "/archive/" tag)))
|
||||||
|
|
||||||
|
(defn normalize-match
|
||||||
|
"Strip trailing slashes from catch-all path params."
|
||||||
|
[match]
|
||||||
|
(when match
|
||||||
|
(update match :path-params update-vals #(str/replace % #"/+$" ""))))
|
||||||
|
|
||||||
|
(defn match-path
|
||||||
|
"Resolve a path to a normalized route match."
|
||||||
|
[path]
|
||||||
|
(normalize-match (rc/match-by-path router path)))
|
||||||
|
|
@ -0,0 +1,83 @@
|
||||||
|
(ns com.oly.static-sites.do-blog.ssr
|
||||||
|
"Generate static HTML for every blog route using the same views as the
|
||||||
|
browser app. The client takes over when the JavaScript loads.
|
||||||
|
|
||||||
|
The page shell comes from resources/do-blog/index.template.html; every page,
|
||||||
|
including public/index.html, is generated output.
|
||||||
|
|
||||||
|
Run after the shadow-cljs build has written documents/org-meta-index.edn:
|
||||||
|
clj -M:blog -m com.oly.static-sites.do-blog.ssr"
|
||||||
|
(:require [clojure.edn :as edn]
|
||||||
|
[clojure.java.io :as io]
|
||||||
|
[clojure.string :as str]
|
||||||
|
[replicant.string :as rs]
|
||||||
|
[com.oly.static-sites.do-blog.routes :refer [match-path post-href archive-href href]]
|
||||||
|
[com.oly.static-sites.do-blog.views :as views]
|
||||||
|
[com.oly.static-sites.do-blog.pages.helpers.database
|
||||||
|
:refer [load-index! latest-article org->document]]
|
||||||
|
[com.oly.static-sites.do-blog.pages.helpers.utils :refer [extract-tags]]))
|
||||||
|
|
||||||
|
(def default-public-dir "bases/do-blog/resources/public")
|
||||||
|
(def default-template "bases/do-blog/resources/do-blog/index.template.html")
|
||||||
|
|
||||||
|
(def app-content #"(?s)<!--app-->.*?<!--/app-->")
|
||||||
|
|
||||||
|
(defn render-into-template [template html]
|
||||||
|
(str/replace template 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))))
|
||||||
|
|
||||||
|
(defn page-state [url document]
|
||||||
|
{:route (match-path url)
|
||||||
|
:search {:terms ""}
|
||||||
|
:document document})
|
||||||
|
|
||||||
|
(defn pages
|
||||||
|
"Every [url state] pair to generate."
|
||||||
|
[public-dir index]
|
||||||
|
(let [doc (memoize #(read-document public-dir %))
|
||||||
|
latest (latest-article)
|
||||||
|
tags (->> index (mapcat (comp extract-tags :filetags)) distinct)]
|
||||||
|
(concat
|
||||||
|
[["/" (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)]]
|
||||||
|
(for [tag tags
|
||||||
|
:let [url (archive-href tag)]]
|
||||||
|
[url (page-state url nil)])
|
||||||
|
(for [{:keys [relative-path]} index
|
||||||
|
:let [path (str/replace relative-path #"^/" "")
|
||||||
|
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 generate!
|
||||||
|
([] (generate! default-public-dir default-template))
|
||||||
|
([public-dir template-file]
|
||||||
|
(let [template (slurp template-file)
|
||||||
|
index (load-index! (edn/read-string (slurp (io/file public-dir "documents" "org-meta-index.edn"))))
|
||||||
|
results (doall
|
||||||
|
(for [[url state] (pages public-dir index)]
|
||||||
|
(try
|
||||||
|
(let [file (url->file public-dir url)]
|
||||||
|
(io/make-parents file)
|
||||||
|
(spit file (render-into-template template (rs/render (views/app state))))
|
||||||
|
{:url url})
|
||||||
|
(catch Exception e
|
||||||
|
{:url url :error (ex-message e)}))))
|
||||||
|
errors (filter :error results)]
|
||||||
|
(println "Generated" (- (count results) (count errors)) "pages into" public-dir)
|
||||||
|
(doseq [{:keys [url error]} errors]
|
||||||
|
(println " FAILED" url "-" error))
|
||||||
|
results)))
|
||||||
|
|
||||||
|
(defn -main [& [public-dir template-file]]
|
||||||
|
(let [errors (filter :error (generate! (or public-dir default-public-dir)
|
||||||
|
(or template-file default-template)))]
|
||||||
|
(shutdown-agents)
|
||||||
|
(System/exit (if (seq errors) 1 0))))
|
||||||
|
|
@ -1,10 +1,11 @@
|
||||||
(ns com.oly.static-sites.do-blog.theme)
|
(ns com.oly.static-sites.do-blog.theme
|
||||||
|
(:require [clojure.set :as set]
|
||||||
|
[clojure.string :as str]))
|
||||||
|
|
||||||
(defn link-handler [v d]
|
(defn link-handler [v & _]
|
||||||
(if (-> v second :img)
|
(if (-> v second :img)
|
||||||
(conj [:img] (-> (dissoc (clojure.set/rename-keys (second v) {:href :src}) :img)
|
(conj [:img] (-> (dissoc (set/rename-keys (second v) {:href :src}) :img)
|
||||||
(update :src #(clojure.string/replace % #"\.\./" "")) )
|
(update :src #(str/replace % #"\.\./" ""))))
|
||||||
)
|
|
||||||
(conj [:a] (second v))))
|
(conj [:a] (second v))))
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -57,5 +58,4 @@
|
||||||
:LINE :p.f5.f4-ns.lh-copy.mt0
|
:LINE :p.f5.f4-ns.lh-copy.mt0
|
||||||
:BULLETS-ORDERED :ol
|
:BULLETS-ORDERED :ol
|
||||||
:BULLETS :ul
|
:BULLETS :ul
|
||||||
:BULLET :li
|
:BULLET :li})
|
||||||
})
|
|
||||||
|
|
@ -0,0 +1,63 @@
|
||||||
|
(ns com.oly.static-sites.do-blog.views
|
||||||
|
"Top level view: a pure function from app state to hiccup.
|
||||||
|
Rendered with replicant.dom in the browser and replicant.string on the JVM."
|
||||||
|
(:require [clojure.string :as str]
|
||||||
|
[com.oly.static-sites.do-blog.routes :refer [href]]
|
||||||
|
[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]]))
|
||||||
|
|
||||||
|
(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))
|
||||||
|
(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 ui-search [terms]
|
||||||
|
[:div
|
||||||
|
[:input.w-100.center.input-reset.ba.b--black-20.pa2.mb2
|
||||||
|
{:type "text"
|
||||||
|
:placeholder "Search"
|
||||||
|
: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]])
|
||||||
|
|
||||||
|
(defn sidebar []
|
||||||
|
[:div
|
||||||
|
(profile-card {:name "Oly"
|
||||||
|
:tagline "Earthling, Software Engineer"
|
||||||
|
:img-src "/images/default/me.png"})
|
||||||
|
[: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")]])
|
||||||
|
|
||||||
|
(defn layout [{:keys [search]} content]
|
||||||
|
(let [terms (:terms search)]
|
||||||
|
[:div.font.h-100
|
||||||
|
[:div.h-100.flex.items-stretch
|
||||||
|
[:div.dn.db-l.pa3.bg-blue {:style {:flex-basis "20rem" :flex-grow "1"}}
|
||||||
|
(sidebar)]
|
||||||
|
[:div.ma3.pa3 {:style {:flex-basis "0" :flex-grow "999"}}
|
||||||
|
(ui-search terms)
|
||||||
|
(if (str/blank? terms)
|
||||||
|
content
|
||||||
|
(article-list-author-media-flipped
|
||||||
|
"Articles"
|
||||||
|
(search-articles {:search terms})))]]]))
|
||||||
|
|
||||||
|
(defn app [state]
|
||||||
|
(layout state (page state)))
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
{:paths []
|
||||||
|
:tasks {blog-watch (shell "clj -M:blog:shadow-cljs-run watch blog")
|
||||||
|
|
||||||
|
blog-generate {:doc "Render static HTML for every blog page (needs documents/org-meta-index.edn from a blog build)"
|
||||||
|
:task (shell "clj -M:blog -m com.oly.static-sites.do-blog.ssr")}
|
||||||
|
|
||||||
|
blog-release {:doc "Release build of the blog JS, then generate the static HTML"
|
||||||
|
:task (do (shell "clj -M:blog:shadow-cljs-run release blog")
|
||||||
|
(run 'blog-generate))}}}
|
||||||
|
|
@ -10,7 +10,7 @@
|
||||||
(if (= (-> piece :colour) :white) " white white-80" " black black-80" )
|
(if (= (-> piece :colour) :white) " white white-80" " black black-80" )
|
||||||
|
|
||||||
)
|
)
|
||||||
:on-click #(on-click % sq)}
|
:on {:click #(when on-click (on-click % sq))}}
|
||||||
[:p.v-mid.ma0.pa0.f2 (-> piece :character)]])
|
[:p.v-mid.ma0.pa0.f2 (-> piece :character)]])
|
||||||
|
|
||||||
(defn board [size items]
|
(defn board [size items]
|
||||||
|
|
|
||||||
10
deps.edn
10
deps.edn
|
|
@ -15,26 +15,26 @@
|
||||||
thheller/shadow-cljs {:mvn/version "3.3.6"}
|
thheller/shadow-cljs {:mvn/version "3.3.6"}
|
||||||
;;refactor-nrepl/refactor-nrepl {:mvn/version "3.9.0"}
|
;;refactor-nrepl/refactor-nrepl {:mvn/version "3.9.0"}
|
||||||
;;cider/cider-nrepl {:mvn/version "0.43.1"}
|
;;cider/cider-nrepl {:mvn/version "0.43.1"}
|
||||||
no.cjohansen/portfolio {:mvn/version "2026.03.1"}
|
no.cjohansen/portfolio {:mvn/version "2026.03.1"}
|
||||||
djblue/portal {:mvn/version "0.48.0"}}}
|
reagent/reagent {:mvn/version "1.1.1"}
|
||||||
|
djblue/portal {:mvn/version "0.48.0"}}}
|
||||||
|
|
||||||
:blog {:extra-paths ["components/ui-hiccup/src"
|
:blog {:extra-paths ["components/ui-hiccup/src"
|
||||||
"components/ui-tachyon/src"
|
"components/ui-tachyon/src"
|
||||||
"development/src" "bases/do-blog/src"
|
"development/src" "bases/do-blog/src"
|
||||||
"bases/do-blog/test"]
|
"bases/do-blog/test"]
|
||||||
:extra-deps {
|
:extra-deps {
|
||||||
|
org.clojure/clojure {:mvn/version "1.12.0"}
|
||||||
org.clojure/core.async {:mvn/version "1.6.673"}
|
org.clojure/core.async {:mvn/version "1.6.673"}
|
||||||
org.clojure/clojurescript {:mvn/version "1.12.134"}
|
org.clojure/clojurescript {:mvn/version "1.12.134"}
|
||||||
|
|
||||||
reagent/reagent {:mvn/version "1.1.1"}
|
no.cjohansen/replicant {:mvn/version "2026.07.1"}
|
||||||
tick/tick {:mvn/version "0.5.0"}
|
tick/tick {:mvn/version "0.5.0"}
|
||||||
metosin/reitit {:mvn/version "0.5.18"}
|
metosin/reitit {:mvn/version "0.5.18"}
|
||||||
|
|
||||||
cljs-ajax/cljs-ajax {:mvn/version "0.8.4"}
|
cljs-ajax/cljs-ajax {:mvn/version "0.8.4"}
|
||||||
|
|
||||||
datascript/datascript {:mvn/version "1.4.0"}
|
datascript/datascript {:mvn/version "1.4.0"}
|
||||||
olymk2/tachyon-reagent {:git/url "https://gitlab.com/olymk2/tachyon-reagent.git"
|
|
||||||
:sha "e422af7b41266f7bc90ab78a24fb93f32be61385"}
|
|
||||||
olymk2/cl-eorg {:git/url "https://gitlab.com/olymk2/cl-org.git"
|
olymk2/cl-eorg {:git/url "https://gitlab.com/olymk2/cl-org.git"
|
||||||
:sha "13e57f11da75516844922fe28bfd6aa7692b7c34"}
|
:sha "13e57f11da75516844922fe28bfd6aa7692b7c34"}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@
|
||||||
:clojure-demos {:output-dir "bases/clojure-demos/resources/public/js"
|
:clojure-demos {:output-dir "bases/clojure-demos/resources/public/js"
|
||||||
;:asset-path "."
|
;:asset-path "."
|
||||||
:target :browser
|
:target :browser
|
||||||
:compiler-options {:infer-externs :auto :output-feature-set :es6 :externs ["datascript/externs.js"]
|
:compiler-options {:infer-externs :auto :output-feature-set :es2018 :externs ["datascript/externs.js"]
|
||||||
:warnings {:undeclared-var false}}
|
:warnings {:undeclared-var false}}
|
||||||
:modules {:base {:entries []}
|
:modules {:base {:entries []}
|
||||||
:app {:init-fn com.oly.static-sites.clojure-demos.core/startup!
|
:app {:init-fn com.oly.static-sites.clojure-demos.core/startup!
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue