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)
  (:import-from :murja.middleware.auth :*user*)
  (:export :page :blogpost))

  
(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)))))

	 (when *user*
	   ;; the old editor is in "/blog/post/edit/~d"
	   (:a :href (format nil "/blog/post/editor/~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
    (:ul.page-post-list
     (map 'list
	  (lisp-fixup:compose (lambda (c)
				(with-html
				  (:li c)))
			      #'blogpost)
	  (remove-if (lambda (post)
		       (or (post-hidden? post)
			   (post-unlisted? post)))
		     page)))))