Improve metadata
This commit is contained in:
parent
88ed5f794d
commit
87ea8f601b
7 changed files with 69 additions and 37 deletions
|
@ -1,24 +1,50 @@
|
||||||
(defpackage #:hp/lib/metadata
|
(defpackage #:hp/lib/metadata
|
||||||
(:use #:cl)
|
(:use #:cl
|
||||||
|
#:hsx)
|
||||||
(:import-from #:hp/lib/env
|
(:import-from #:hp/lib/env
|
||||||
#:hp-url)
|
#:hp-url)
|
||||||
(:export #:complete-metadata))
|
(:export #:~metadata))
|
||||||
(in-package #:hp/lib/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)
|
(defun path->url (path)
|
||||||
(concatenate 'string
|
(concatenate 'string
|
||||||
(hp-url)
|
(hp-url)
|
||||||
(and (not (string= path "/")) path)))
|
(and (not (string= path "/")) path)))
|
||||||
|
|
||||||
(defparameter *metadata-template*
|
(defparameter *metadata-template*
|
||||||
(list :title (lambda (title) (format nil "~@[~a - ~]~a" title "skyizwhite.dev"))
|
(let ((%title (lambda (title) (format nil "~@[~a - ~]~a" title "skyizwhite.dev")))
|
||||||
:description "The personal website of Akira Tempaku (paku) - bio, work, blog and more."
|
(%description "The personal website of Akira Tempaku (paku) - bio, work, blog and more."))
|
||||||
:canonical #'path->url
|
(list :title %title
|
||||||
:og-url #'path->url
|
:description %description
|
||||||
:og-type "website"
|
:canonical #'path->url
|
||||||
:og-image (path->url "/img/og.jpg")
|
:og-title %title
|
||||||
:og-image-width 1024
|
:og-description %description
|
||||||
:og-image-height 1024))
|
: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)
|
(defun complete-metadata (metadata)
|
||||||
(loop
|
(loop
|
||||||
|
@ -27,3 +53,23 @@
|
||||||
:append (list key (if (functionp template)
|
:append (list key (if (functionp template)
|
||||||
(funcall template value)
|
(funcall template value)
|
||||||
(or value template)))))
|
(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)))))))))
|
||||||
|
|
|
@ -9,8 +9,6 @@
|
||||||
(:import-from #:hp/lib/env
|
(:import-from #:hp/lib/env
|
||||||
#:hp-url
|
#:hp-url
|
||||||
#:hp-env)
|
#:hp-env)
|
||||||
(:import-from #:hp/lib/metadata
|
|
||||||
#:complete-metadata)
|
|
||||||
(:import-from #:hp/ui/layout
|
(:import-from #:hp/ui/layout
|
||||||
#:~layout))
|
#:~layout))
|
||||||
(in-package #:hp/renderer)
|
(in-package #:hp/renderer)
|
||||||
|
@ -26,6 +24,6 @@
|
||||||
((guard (or (list page metadata)
|
((guard (or (list page metadata)
|
||||||
page)
|
page)
|
||||||
(typep page 'element))
|
(typep page 'element))
|
||||||
(~layout (complete-metadata metadata)
|
(~layout :metadata metadata
|
||||||
page))
|
page))
|
||||||
(_ (error "Invalid response form"))))))
|
(_ (error "Invalid response form"))))))
|
||||||
|
|
|
@ -5,7 +5,8 @@
|
||||||
(in-package :hp/routes/bio)
|
(in-package :hp/routes/bio)
|
||||||
|
|
||||||
(defparameter *metadata*
|
(defparameter *metadata*
|
||||||
(list :title "bio"))
|
(list :title "bio"
|
||||||
|
:path "/bio"))
|
||||||
|
|
||||||
(defcomp ~page ()
|
(defcomp ~page ()
|
||||||
(hsx
|
(hsx
|
||||||
|
|
|
@ -5,7 +5,8 @@
|
||||||
(in-package :hp/routes/blog)
|
(in-package :hp/routes/blog)
|
||||||
|
|
||||||
(defparameter *metadata*
|
(defparameter *metadata*
|
||||||
(list :title "blog"))
|
(list :title "blog"
|
||||||
|
:path "/blog"))
|
||||||
|
|
||||||
(defcomp ~page ()
|
(defcomp ~page ()
|
||||||
(hsx
|
(hsx
|
||||||
|
|
|
@ -6,7 +6,8 @@
|
||||||
|
|
||||||
(defparameter *metadata*
|
(defparameter *metadata*
|
||||||
'(:title "404 Not Found"
|
'(: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 ()
|
(defcomp ~page ()
|
||||||
(hsx
|
(hsx
|
||||||
|
|
|
@ -5,7 +5,8 @@
|
||||||
(in-package :hp/routes/work)
|
(in-package :hp/routes/work)
|
||||||
|
|
||||||
(defparameter *metadata*
|
(defparameter *metadata*
|
||||||
(list :title "work"))
|
(list :title "work"
|
||||||
|
:path "/work"))
|
||||||
|
|
||||||
(defcomp ~page ()
|
(defcomp ~page ()
|
||||||
(hsx
|
(hsx
|
||||||
|
|
|
@ -1,37 +1,21 @@
|
||||||
(defpackage #:hp/ui/layout
|
(defpackage #:hp/ui/layout
|
||||||
(:use #:cl
|
(:use #:cl
|
||||||
#:hsx)
|
#:hsx)
|
||||||
|
(:import-from #:hp/lib/metadata
|
||||||
|
#:~metadata)
|
||||||
(:export #:~layout))
|
(:export #:~layout))
|
||||||
(in-package #:hp/ui/layout)
|
(in-package #:hp/ui/layout)
|
||||||
|
|
||||||
(defun bust-cache (url)
|
(defun bust-cache (url)
|
||||||
(format nil "~a?v=~a" url #.(get-universal-time)))
|
(format nil "~a?v=~a" url #.(get-universal-time)))
|
||||||
|
|
||||||
(defcomp ~layout (&key title
|
(defcomp ~layout (&key metadata children)
|
||||||
description
|
|
||||||
canonical
|
|
||||||
og-url
|
|
||||||
og-type
|
|
||||||
og-image
|
|
||||||
og-image-width
|
|
||||||
og-image-height
|
|
||||||
children)
|
|
||||||
(hsx
|
(hsx
|
||||||
(html :lang "ja"
|
(html :lang "ja"
|
||||||
(head
|
(head
|
||||||
(meta :charset "UTF-8")
|
(meta :charset "UTF-8")
|
||||||
(meta :name "viewport" :content "width=device-width, initial-scale=1")
|
(meta :name "viewport" :content "width=device-width, initial-scale=1")
|
||||||
(title title)
|
(~metadata :metadata metadata)
|
||||||
(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)
|
|
||||||
(link :rel "icon" :type "image/png" :href "/img/favicon-96x96.png" :sizes "96x96")
|
(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 "icon" :type "image/svg+xml" :href "/img/favicon.svg")
|
||||||
(link :rel "shortcut icon" :href "/img/favicon.ico")
|
(link :rel "shortcut icon" :href "/img/favicon.ico")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue