src/views/components/post.lisp

DOWNLOAD
(defpackage murja.views.components.post
  (:use :cl :murja.newui :cl-hash-util :binding-arrows :murja.models.user )
  (:import-from :murja.middleware.db :*settings*)
  (:import-from :murja.models.post :previouslies :post-id :post-title :creator :created-at :article :previous-post-id :next-post-id :tags)
  (:export :post))

(in-package :murja.views.components.post)

(defun post (post &key show-footer?)
  (let ((creator (creator post)))
    (c :article (:class "post")
       (c :h2 ()
	  (c :a (:href (format nil "/blog/post/~d" (post-id post)))
	     (post-title post)))
       (c :section (:class "meta")
	  (c :img (:class "user_avatar" :src (user-img-location creator)))
	  (c :p () (format nil "By ~a" (user-nickname creator)))
	  (c :p () "Written at"
	     (c :time (:datetime (created-at post))
		(created-at post))))

       (c :section (:class "content" :stop-escape t) (article post))

       
       (when (previouslies post)
	 (component :div (:class "previously")
		    (map 'list
			 (lambda (p)
			   (cl-hash-util:with-keys ("title" "id") p
			     (c :a (:href (format nil "/blog/post/~d" id))
				(format nil "~a, " (gethash "previously_label" *settings*)))))
			 (previouslies post))))

       (when (tags post)
	 (component :ul (:class "tags")
		    (map 'list 
			 (lambda (tag)
			   (c :li ()
			      (c :a (:href (format nil "/blog/tags/~a" tag)
				     :class "tag")
				 (format nil "~a, " tag))))
			 (tags post))))
       
       (when (and show-footer?
		  (or (not (equalp -1 (previous-post-id post)))
		      (not (equalp -1 (next-post-id post)))))
	 (c :footer (:class "linear-post-footer-nav")
	    (unless (equalp -1 (previous-post-id post))
	      (c :a (:href (format nil "/blog/post/~d" (previous-post-id post)))
		 "Older post"))

	    (unless (equalp -1 (next-post-id post))
	      (c :a (:href (format nil "/blog/post/~d" (next-post-id post)))
		 "Newer post")))))))