diff of 4935bb9e34e589a390188ebda8fb49f111dc782a
4935bb9e34e589a390188ebda8fb49f111dc782a
diff --git a/src/local-lib/lisp-fixup.lisp b/src/local-lib/lisp-fixup.lisp
index 99b5cdd..cd12712 100644
--- a/src/local-lib/lisp-fixup.lisp
+++ b/src/local-lib/lisp-fixup.lisp
@@ -1,6 +1,8 @@
(defpackage lisp-fixup
(:use :cl)
+ (:import-from :cl-hash-util :hash)
(:export :if-modified-since->simpledate-timestamp :*rfc822*
+ :group-by :month->string
:*dev?* :to-secs
:fix-timestamp
:*now*
@@ -164,3 +166,14 @@
(round (/ ms 1000))))
(defvar *now* nil)
+
+
+
+
+(defun group-by (key list)
+ "Groups a list of hashmaps into a resulting hashmap per `key`"
+ (let ((acc (hash)))
+ (dolist (l list)
+ (let ((key-val (gethash key l)))
+ (push l (gethash key-val acc))))
+ acc))
diff --git a/src/murja-newui/newui.lisp b/src/murja-newui/newui.lisp
index a39f117..187fe51 100644
--- a/src/murja-newui/newui.lisp
+++ b/src/murja-newui/newui.lisp
@@ -100,6 +100,9 @@
(defmethod render ((s string))
s)
+(defmethod render ((s t))
+ (prin1-to-string s))
+
(defparameter *single-element-tags* (list :link :meta :input)
"Contains tags that don't expand to <:tag attrs>children</:tag> but instead into <:tag attrs />")
diff --git a/src/posts/post-db.lisp b/src/posts/post-db.lisp
index 5a86780..8a302f3 100644
--- a/src/posts/post-db.lisp
+++ b/src/posts/post-db.lisp
@@ -12,10 +12,11 @@
(defun get-titles-by-year (&key allow-hidden?)
(map 'list
(lambda (title)
-
(when (gethash "Tags" title)
(setf (gethash "Tags" title)
(parse (gethash "Tags" title))))
+ (setf (gethash "Month" title)
+ (lisp-fixup:month->string (gethash "Month" title)))
title)
(get-titles-by-year* allow-hidden?)))
diff --git a/src/views/blog-main.lisp b/src/views/blog-main.lisp
index 6232c14..cb8cd57 100644
--- a/src/views/blog-main.lisp
+++ b/src/views/blog-main.lisp
@@ -16,18 +16,9 @@
(let* ((settings (get-settings))
(page-size (gethash "recent-post-count" settings))
(page 1)
- (page-posts (get-page page page-size))
- (sidebar-titles (get-titles-by-year)))
+ (page-posts (get-page page page-size)))
(root-component
(tabs "Home"
(hash
- ("Home"
- (c :p () "Welcome to murja I guess.... :D"))
- ("Ilpo testaa"
- (c :p () "Kakkos tabi"))
-
- ("Kolmas tabi"
- (c :form ()
- (c :label ()
- "Testi inputti"
- (c :input (:type "text" :value "Koodista tuleva oletushomma"))))))))))
+ ("Home" (c :p () "lol")))))))
+
diff --git a/src/views/components/root.lisp b/src/views/components/root.lisp
index 251476d..e4f3473 100644
--- a/src/views/components/root.lisp
+++ b/src/views/components/root.lisp
@@ -1,19 +1,54 @@
(defpackage murja.views.components.root
- (:use :cl :murja.newui)
+ (:use :cl :murja.newui :binding-arrows)
+ (:import-from :murja.posts.post-db :get-titles-by-year)
(:import-from :murja.middleware.db :*settings*)
(:export :root-component))
(in-package :murja.views.components.root)
+(defun sidebar-tree ()
+ (let* ((sidebar-titles (->>
+ (get-titles-by-year)
+ (lisp-fixup:group-by "Year"))))
+ (component :ul (:id "grouper")
+ (loop for year being the hash-keys of sidebar-titles
+ collecting (c :li ()
+ (c :details ()
+ (c :summary () (format nil "~a (~d)" year (length (gethash year sidebar-titles))))
+ (component :ul ()
+ (let ((by-month (lisp-fixup:group-by "Month" (gethash year sidebar-titles))))
+ (loop for month being the hash-keys of by-month
+ collecting (c :li ()
+ (c :details ()
+ (c :summary () (format nil "~a (~d)" month (length (gethash month by-month))))
+ (component :ul ()
+ (map 'list
+ (lambda (title)
+ (cl-hash-util:with-keys ("Id" "Title") title
+ (c :li () (c :a (:href (format nil "/blog/post/~d" Id)) Title))))
+ (gethash month by-month))))))))))))))
+
(defun root-component (inner-component)
"Returns the root html element of murja with `inner-component` embedded inside it"
+
(c :html ()
- (c :head ()
- (c :link (:href "/resources/murja.css" :rel "stylesheet" :type "text/css"))
- (c :script (:src "https://unpkg.com/ace-custom-element@latest/dist/index.min.js" :type "module"))
- (c :script (:src "/resources/newui.js"))
- (c :meta (:charset "UTF-8")))
- (c :body ()
- (c :header ()
- (c :a (:href "/") (gethash "blog-title" *settings* )))
- inner-component)))
+ (c :head ()
+ (c :link (:href "/resources/murja.css" :rel "stylesheet" :type "text/css"))
+ (c :script (:src "https://unpkg.com/ace-custom-element@latest/dist/index.min.js" :type "module"))
+ (c :script (:src "/resources/newui.js"))
+ (c :meta (:charset "UTF-8")))
+ (c :body ()
+ (c :header ()
+ (c :a (:href "/") (gethash "blog-title" *settings* )))
+
+ (c :div (:class "sidebar-flex")
+ inner-component
+
+ (c :div (:id "sidebar")
+ (c :form () ;; todo lol
+ (c :label () "Username " (c :input (:id "username" :name "username" :data-testid "username-input-field")))
+ (c :label () "Password " (c :input (:id "password" :name "password" :type "password" :data-testid "password-input-field"))))
+
+ (sidebar-tree))))))
+
+