diff --git a/src/lib/metadata.lisp b/src/lib/metadata.lisp index 6e708e0..4e841cb 100644 --- a/src/lib/metadata.lisp +++ b/src/lib/metadata.lisp @@ -1,24 +1,50 @@ (defpackage #:hp/lib/metadata - (:use #:cl) + (:use #:cl + #:hsx) (:import-from #:hp/lib/env #:hp-url) - (:export #:complete-metadata)) + (:export #:~metadata)) (in-package #:hp/lib/metadata) +(defun create-metadata (&key title + description + path + canonical + type + image + error) + (list :title title + :description description + :canonical (or canonical path) + :og-title title + :og-description description + :og-url path + :og-type type + :og-image (getf image :url) + :og-image-width (getf image :width) + :og-image-height (getf image :height) + :error error)) + (defun path->url (path) (concatenate 'string (hp-url) (and (not (string= path "/")) path))) (defparameter *metadata-template* - (list :title (lambda (title) (format nil "~@[~a - ~]~a" title "skyizwhite.dev")) - :description "The personal website of Akira Tempaku (paku) - bio, work, blog and more." - :canonical #'path->url - :og-url #'path->url - :og-type "website" - :og-image (path->url "/img/og.jpg") - :og-image-width 1024 - :og-image-height 1024)) + (let ((%title (lambda (title) (format nil "~@[~a - ~]~a" title "skyizwhite.dev"))) + (%description "The personal website of Akira Tempaku (paku) - bio, work, blog and more.")) + (list :title %title + :description %description + :canonical #'path->url + :og-title %title + :og-description %description + :og-url #'path->url + :og-type "website" + :og-site-name "skyizwhite.dev" + :og-image (path->url "/img/og.jpg") + :og-image-width 1024 + :og-image-height 1024 + :error nil))) (defun complete-metadata (metadata) (loop @@ -27,3 +53,23 @@ :append (list key (if (functionp template) (funcall template value) (or value template))))) + +(defcomp ~metadata (&key metadata) + (let ((%metadata (complete-metadata (apply #'create-metadata metadata)))) + (hsx + (<> + (title (getf %metadata :title)) + (meta :name "description" :content (getf %metadata :description)) + (and + (not (getf %metadata :error)) + (hsx + (<> + (meta :property "og:title" :content (getf %metadata :og-title)) + (meta :property "og:description" :content (getf %metadata :og-description)) + (meta :property "og:url" :content (getf %metadata :og-url)) + (meta :property "og:type" :content (getf %metadata :og-type)) + (meta :property "og:site_name" :content (getf %metadata :og-site-name)) + (meta :property "og:image" :content (getf %metadata :og-image)) + (meta :property "og:image:width" :content (getf %metadata :og-image-width)) + (meta :property "og:image:height" :content (getf %metadata :og-image-height)) + (link :rel "canonical" :href (getf %metadata :canonical))))))))) diff --git a/src/renderer.lisp b/src/renderer.lisp index b3bc7d8..a6d826a 100644 --- a/src/renderer.lisp +++ b/src/renderer.lisp @@ -9,8 +9,6 @@ (:import-from #:hp/lib/env #:hp-url #:hp-env) - (:import-from #:hp/lib/metadata - #:complete-metadata) (:import-from #:hp/ui/layout #:~layout)) (in-package #:hp/renderer) @@ -26,6 +24,6 @@ ((guard (or (list page metadata) page) (typep page 'element)) - (~layout (complete-metadata metadata) + (~layout :metadata metadata page)) (_ (error "Invalid response form")))))) diff --git a/src/routes/bio.lisp b/src/routes/bio.lisp index 71e5411..5002a65 100644 --- a/src/routes/bio.lisp +++ b/src/routes/bio.lisp @@ -5,7 +5,8 @@ (in-package :hp/routes/bio) (defparameter *metadata* - (list :title "bio")) + (list :title "bio" + :path "/bio")) (defcomp ~page () (hsx diff --git a/src/routes/blog.lisp b/src/routes/blog.lisp index 7c13289..5760d3e 100644 --- a/src/routes/blog.lisp +++ b/src/routes/blog.lisp @@ -5,7 +5,8 @@ (in-package :hp/routes/blog) (defparameter *metadata* - (list :title "blog")) + (list :title "blog" + :path "/blog")) (defcomp ~page () (hsx diff --git a/src/routes/not-found.lisp b/src/routes/not-found.lisp index 9d95265..b05f179 100644 --- a/src/routes/not-found.lisp +++ b/src/routes/not-found.lisp @@ -6,7 +6,8 @@ (defparameter *metadata* '(:title "404 Not Found" - :description "The page you are looking for may have been deleted or the URL might be incorrect.")) + :description "The page you are looking for may have been deleted or the URL might be incorrect." + :error t)) (defcomp ~page () (hsx diff --git a/src/routes/work.lisp b/src/routes/work.lisp index fa96819..b538b06 100644 --- a/src/routes/work.lisp +++ b/src/routes/work.lisp @@ -5,7 +5,8 @@ (in-package :hp/routes/work) (defparameter *metadata* - (list :title "work")) + (list :title "work" + :path "/work")) (defcomp ~page () (hsx diff --git a/src/ui/layout.lisp b/src/ui/layout.lisp index dfd7c6c..3fb3947 100644 --- a/src/ui/layout.lisp +++ b/src/ui/layout.lisp @@ -1,37 +1,21 @@ (defpackage #:hp/ui/layout (:use #:cl #:hsx) + (:import-from #:hp/lib/metadata + #:~metadata) (:export #:~layout)) (in-package #:hp/ui/layout) (defun bust-cache (url) (format nil "~a?v=~a" url #.(get-universal-time))) -(defcomp ~layout (&key title - description - canonical - og-url - og-type - og-image - og-image-width - og-image-height - children) +(defcomp ~layout (&key metadata children) (hsx (html :lang "ja" (head (meta :charset "UTF-8") (meta :name "viewport" :content "width=device-width, initial-scale=1") - (title title) - (meta :name "description" :content description) - (meta :property "og:title" :content title) - (meta :property "og:description" :content description) - (meta :property "og:url" :content og-url) - (meta :property "og:type" :content og-type) - (meta :property "og:site_name" :content "skyizwhite.dev") - (meta :property "og:image" :content og-image) - (meta :property "og:image:width" :content og-image-width) - (meta :property "og:image:height" :content og-image-height) - (link :rel "canonical" :href canonical) + (~metadata :metadata metadata) (link :rel "icon" :type "image/png" :href "/img/favicon-96x96.png" :sizes "96x96") (link :rel "icon" :type "image/svg+xml" :href "/img/favicon.svg") (link :rel "shortcut icon" :href "/img/favicon.ico")