src/view/components/blogpost.lisp

DOWNLOAD
(defpackage murja.view.components.blogpost
  (:use :cl :binding-arrows :spinneret :murja.model.post :murja.model.user :cl-hash-util)
  (:export :page))

  
(in-package :murja.view.components.blogpost)

(defun previously (prev)
  (with-keys ("id" "title") prev
    (with-html
      (:li 
       (:a :title title :href (format nil "/blog/post/~d" id) "Previously")))))

(defun tag (tag)
  (with-html
    (:li
     (:a :href (format nil "/blog/tags/~a" tag) tag))))

(defun blogpost (post)
  (with-slots (id title creator created-at content previouslies tags) post
    (assert creator)
    (let ((img-location (user-img-location creator))
	  (nickname (user-nickname creator)))
      (assert img-location)
      (with-html
	(:div.post
	 (:a :href (format nil "/blog/post/~d" id) title)
	 (:div.meta
	  (:img.user_avatar :src img-location)
	  (:p ("By ~a" nickname))
	  (:p ("Written at ~a" (let ((lisp-fixup:*rfc822* t))
				 (lisp-fixup:fix-timestamp created-at)))))

	 ;; TODO
	 ;; (:a :href ("/blog/post/edit/~d" id) "Edit this post")
	 (:article.content
	  (:raw 
	   content))
	 (:ul.previously
	  (map 'list #'previously previouslies))
	 (:ul.tags
	  (map 'list #'tag tags))
	 (:div)))))) ;; next and previous post ?????????

(defun page (page)
  (with-html
    (:div (:h* "Page chrome")
	  (:ul.page-post-list
	   (map 'list
		(lisp-fixup:compose (lambda (c)
				      (with-html
					(:li c)))
				    #'blogpost)
		page)))))