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
|
||||
(: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)))))))))
|
||||
|
|
|
@ -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"))))))
|
||||
|
|
|
@ -5,7 +5,8 @@
|
|||
(in-package :hp/routes/bio)
|
||||
|
||||
(defparameter *metadata*
|
||||
(list :title "bio"))
|
||||
(list :title "bio"
|
||||
:path "/bio"))
|
||||
|
||||
(defcomp ~page ()
|
||||
(hsx
|
||||
|
|
|
@ -5,7 +5,8 @@
|
|||
(in-package :hp/routes/blog)
|
||||
|
||||
(defparameter *metadata*
|
||||
(list :title "blog"))
|
||||
(list :title "blog"
|
||||
:path "/blog"))
|
||||
|
||||
(defcomp ~page ()
|
||||
(hsx
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -5,7 +5,8 @@
|
|||
(in-package :hp/routes/work)
|
||||
|
||||
(defparameter *metadata*
|
||||
(list :title "work"))
|
||||
(list :title "work"
|
||||
:path "/work"))
|
||||
|
||||
(defcomp ~page ()
|
||||
(hsx
|
||||
|
|
|
@ -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")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue