This commit is contained in:
Akira Tempaku 2024-01-30 00:48:47 +09:00
commit 72ef5ae639
12 changed files with 174 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
.qlot

3
README.md Normal file
View file

@ -0,0 +1,3 @@
# homepage (WIP)
My homepage built with HTMX and Common Lisp

8
hp-tests.asd Normal file
View file

@ -0,0 +1,8 @@
(defsystem "hp-tests"
:defsystem-depends-on ("wild-package-inferred-system")
:class "winfer:wild-package-inferred-system"
:pathname "tests"
:depends-on ("fiveam"
"hp-tests/**/*")
:perform (test-op (o c)
(symbol-call :fiveam :run-all-tests)))

8
hp.asd Normal file
View file

@ -0,0 +1,8 @@
(defsystem "hp"
:description "My personal project template for Common Lisp"
:author "paku <paku@skyizwhite.dev>"
:defsystem-depends-on ("wild-package-inferred-system")
:class "winfer:wild-package-inferred-system"
:pathname "src"
:depends-on ("hp/main")
:in-order-to ((test-op (test-op "hp-tests"))))

7
qlfile Normal file
View file

@ -0,0 +1,7 @@
ql wild-package-inferred-system
ql fiveam
ql alexandria
ql lack
ql clack
ql cl-jingle
ql markup

32
qlfile.lock Normal file
View file

@ -0,0 +1,32 @@
("quicklisp" .
(:class qlot/source/dist:source-dist
:initargs (:distribution "https://beta.quicklisp.org/dist/quicklisp.txt" :%version :latest)
:version "2023-10-21"))
("wild-package-inferred-system" .
(:class qlot/source/ql:source-ql
:initargs (:%version :latest)
:version "ql-2023-10-21"))
("fiveam" .
(:class qlot/source/ql:source-ql
:initargs (:%version :latest)
:version "ql-2023-10-21"))
("alexandria" .
(:class qlot/source/ql:source-ql
:initargs (:%version :latest)
:version "ql-2023-10-21"))
("lack" .
(:class qlot/source/ql:source-ql
:initargs (:%version :latest)
:version "ql-2023-10-21"))
("clack" .
(:class qlot/source/ql:source-ql
:initargs (:%version :latest)
:version "ql-2023-10-21"))
("cl-jingle" .
(:class qlot/source/ql:source-ql
:initargs (:%version :latest)
:version "ql-2023-10-21"))
("markup" .
(:class qlot/source/ql:source-ql
:initargs (:%version :latest)
:version "ql-2023-10-21"))

View file

@ -0,0 +1,16 @@
(defpackage #:hp/components/layout
(:use #:cl)
(:import-from #:markup)
(:export #:layout))
(in-package #:hp/components/layout)
(markup:enable-reader)
(markup:deftag layout (children)
<html>
<head>
<title>skyizwhite.dev</title>
<script src="https://unpkg.com/htmx.org@1.3.1"></script>
</head>
<body>,@(progn children)</body>
</html>)

24
src/main.lisp Normal file
View file

@ -0,0 +1,24 @@
(defpackage :hp
(:nicknames #:hp/main)
(:use #:cl)
(:import-from #:clack)
(:import-from #:lack)
(:import-from #:hp/pages/**/*
#:*index-app*)
(:export #:start-app
#:stop-app))
(in-package :hp)
(defparameter *handler* nil)
(defun start-app ()
(unless *handler*
(setf *handler* (clack:clackup (lack:builder *index-app*)
:address "localhost"
:port 3000))))
(defun stop-app ()
(when *handler*
(clack:stop *handler*)
(setf *handler* nil)
t))

45
src/pages/index.lisp Normal file
View file

@ -0,0 +1,45 @@
(defpackage #:hp/pages/index
(:use #:cl)
(:import-from #:jingle)
(:import-from #:markup)
(:import-from #:hp/components/layout
#:layout)
(:import-from #:hp/utils
#:render-html
#:register-routes)
(:export #:*index-app*))
(in-package #:hp/pages/index)
(markup:enable-reader)
(defparameter *counter* 0)
(markup:deftag counter (&key value)
<div id="counter">,(progn value)</div>)
(defun index-page (params)
(declare (ignore params))
(render-html
<layout>
<counter value=*counter* />
<button hx-target="#counter" hx-post="/decrease"> - </button>
<button hx-target="#counter" hx-post="/increase"> + </button>
</layout>))
(defun increase (params)
(declare (ignore params))
(render-html
<counter value=(incf *counter*) />))
(defun decrease (params)
(declare (ignore params))
(render-html
<counter value=(decf *counter*) />))
(defparameter *index-app* (jingle:make-app))
(register-routes
*index-app*
`((:method :GET :path "/" :handler ,#'index-page)
(:method :POST :path "/increase" :handler ,#'increase)
(:method :POST :path "/decrease" :handler ,#'decrease)))

19
src/utils.lisp Normal file
View file

@ -0,0 +1,19 @@
(defpackage #:hp/utils
(:use #:cl)
(:import-from #:markup)
(:import-from #:jingle)
(:export #:register-routes
#:render-html))
(in-package #:hp/utils)
(defun register-routes (app routes)
(loop :for item :in routes
:for path = (getf item :path)
:for handler = (getf item :handler)
:for method = (getf item :method)
:do (setf (jingle:route app path :method method) handler)))
(defmacro render-html (&body body)
`(jingle:with-html-response
(markup:write-html
,@body)))

1
static/htmx.min.js vendored Normal file

File diff suppressed because one or more lines are too long

10
tests/example.lisp Normal file
View file

@ -0,0 +1,10 @@
(defpackage #:hp-tests/example
(:use #:cl
#:fiveam))
(in-package #:hp-tests/example)
(def-suite example-test)
(in-suite example-test)
(test adder-test
(is (= (+ 1 1) 2)))