diff options
| -rw-r--r-- | .github/workflows/deploy.yml | 66 | ||||
| -rw-r--r-- | .gitignore | 17 | ||||
| -rw-r--r-- | deps.edn | 3 | ||||
| -rwxr-xr-x | index.sh | 47 | ||||
| -rw-r--r-- | src/core.clj | 62 |
5 files changed, 148 insertions, 47 deletions
diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..eb4048a --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,66 @@ +name: Build and Deploy to GitHub Pages + +on: + push: + branches: [ main ] + workflow_dispatch: + +permissions: + contents: read + pages: write + id-token: write + +concurrency: + group: "pages" + cancel-in-progress: false + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Java + uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: '17' + + - name: Cache Clojure dependencies + uses: actions/cache@v4 + with: + path: | + ~/.m2/repository + ~/.gitlibs + ~/.deps.clj + key: ${{ runner.os }}-clojure-${{ hashFiles('**/deps.edn') }} + restore-keys: | + ${{ runner.os }}-clojure- + + - name: Install Clojure CLI tools + uses: DeLaGuardo/setup-clojure@12.5 + with: + cli: 1.11.1.1429 + + - name: Build site + run: clojure -M -m core + + - name: Setup Pages + uses: actions/configure-pages@v5 + + - name: Upload artifact + uses: actions/upload-pages-artifact@v3 + with: + path: 'target/html' + + deploy: + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + runs-on: ubuntu-latest + needs: build + steps: + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v4 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b877d15 --- /dev/null +++ b/.gitignore @@ -0,0 +1,17 @@ +.DS_Store +.idea +*.log +tmp/ + +/target +/classes +/checkouts +profiles.clj +pom.xml +pom.xml.asc +*.jar +*.class +/.lein-* +/.nrepl-port +/.prepl-port +/.cpcache diff --git a/deps.edn b/deps.edn new file mode 100644 index 0000000..0a0f25b --- /dev/null +++ b/deps.edn @@ -0,0 +1,3 @@ +{:paths ["" "src" "resources"] + :deps {org.clojure/clojure {:mvn/version "1.12.0"} + io.github.borkdude/html {:mvn/version "0.2.2"}}} diff --git a/index.sh b/index.sh deleted file mode 100755 index 3133a2a..0000000 --- a/index.sh +++ /dev/null @@ -1,47 +0,0 @@ -#!/bin/zsh - -SCRIPT_FILE="$0" -SCRIPT_CONTENT=$(<"$SCRIPT_FILE") - -http_response() { - local content_length=$(wc -c < "$SCRIPT_FILE") - printf "HTTP/1.1 200 OK\r\n" - printf "Content-Type: text/plain\r\n" - printf "Content-Length: %d\r\n" "$content_length" - printf "Connection: close\r\n" - printf "\r\n" - printf "%s" "$SCRIPT_CONTENT" -} - -handle_client() { - while tcp_read; do - line=${TCP_LINE%$'\r'} - [[ -z "$line" ]] && break - done - - tcp_send "$(http_response)" - - tcp_close -} - -# Load zsh's TCP module and functions -zmodload zsh/net/tcp -autoload -U tcp_open tcp_read tcp_send tcp_close - -# Clean up background processes on exit -cleanup() { - jobs -p | xargs -r kill - tcp_close -a - exit 0 -} -trap cleanup INT TERM - -# Create listening socket once -ztcp -l 8082 -server_fd=$REPLY - -while true; do - if tcp_open -a $server_fd; then - handle_client - fi -done diff --git a/src/core.clj b/src/core.clj new file mode 100644 index 0000000..f13531e --- /dev/null +++ b/src/core.clj @@ -0,0 +1,62 @@ +(ns core + (:require [borkdude.html :refer [html]] + [clojure.java.io :as io] + [clojure.string :as str])) + +(defn template [body] + (html [:html [:head] [:body [:<> body]]])) + +(defn home [] + (template + (html + [:h1 "home"]))) + +(defn about [] + (template + (html + [:h1 "about"]))) + +(defn this-life + "blog post about this life" + [] + (template + (html + [:h1 "This life"]))) + +(defn something-else + "blog post about something else" + [] + (template + (html + [:h1 "Something else"]))) + +(something-else) + +(def pages + {"/" home + "/about2" about + "/blog/this-life" this-life + "/blog/something-else" something-else}) + +(defn clean [] + (let [target-dir (io/file "target")] + (when (.exists target-dir) + (doseq [file (file-seq target-dir) + :when (.isFile file)] + (io/delete-file file)) + (doseq [dir (reverse (filter #(.isDirectory %) (file-seq target-dir))) + :when (not= dir target-dir)] + (.delete dir))))) + +(defn compile [] + (doseq [[path page-fn] pages] + (let [target-path (if (= path "/") + "target/html/index.html" + (str "target/html" path "/index.html")) + target-file (io/file target-path)] + (io/make-parents target-file) + (spit target-file (str (page-fn)))))) + +(defn -main [] + (clean) + (compile)) |
