website/src/lib/cms.lisp

65 lines
2.1 KiB
Common Lisp
Raw Normal View History

2025-05-02 09:39:55 +09:00
(defpackage #:website/lib/cms
2025-04-29 01:26:02 +09:00
(:use #:cl)
(:import-from #:microcms
2025-04-29 19:13:40 +09:00
#:define-list-client
#:define-object-client)
2025-05-25 19:41:59 +09:00
(:import-from #:function-cache
#:defcached
#:clear-cache
#:clear-cache-partial-arguments)
2025-05-02 09:39:55 +09:00
(:import-from #:website/lib/env
2025-04-29 01:26:02 +09:00
#:microcms-service-domain
#:microcms-api-key)
2025-05-25 19:41:59 +09:00
(:export #:fetch-about
#:fetch-works
#:fetch-blog-list
#:fetch-blog-detail
#:clear-about-cache
#:clear-works-cache
#:clear-blog-list-cache
#:clear-blog-detail-cache))
2025-05-04 00:38:07 +09:00
(in-package #:website/lib/cms)
2025-04-29 01:26:02 +09:00
(setf microcms:*service-domain* (microcms-service-domain))
(setf microcms:*api-key* (microcms-api-key))
2025-05-03 13:26:31 +09:00
(define-object-client about)
2025-05-18 08:12:43 +09:00
(define-object-client works)
2025-04-29 01:26:02 +09:00
(define-list-client blog)
2025-05-25 19:41:59 +09:00
(defcached fetch-about (&key draft-key)
(get-about :query (list :draft-key draft-key)))
(defcached fetch-works (&key draft-key)
(get-works :query (list :draft-key draft-key)))
(defcached fetch-blog-list (&key page)
;TODO: pagenation
(declare (ignore page))
(getf (get-blog-list :query '(:fields "id,title,publishedAt"
:limit 100))
:contents))
(defcached fetch-blog-detail (id &key draft-key)
(get-blog-detail id :query (list :draft-key draft-key)))
(defun clear-about-cache (new-draft-key)
(if new-draft-key
(clear-cache-partial-arguments *fetch-about-cache* `(:draft-key ,new-draft-key))
(clear-cache *fetch-about-cache*)))
(defun clear-works-cache (new-draft-key)
(if new-draft-key
(clear-cache-partial-arguments *fetch-works-cache* `(:draft-key ,new-draft-key))
(clear-cache *fetch-works-cache*)))
(defun clear-blog-cache (id old-draft-key new-draft-key)
(labels ((clear-detail-cache (id draft-key)
(clear-cache-partial-arguments *fetch-blog-detail-cache*
`(,id :draft-key ,draft-key))))
(unless new-draft-key
(clear-cache *fetch-blog-list-cache*)
(clear-detail-cache id old-draft-key))
(clear-detail-cache id new-draft-key)))