Miniblog: A command-line static blog system in Common Lisp
Log | Files | Refs | README | LICENSE

commit a489a6c0bc72de91f2a41894eb3a20c56d423f87
parent db01facfd06e1e4cdbdcbb99c4ff7289ce049260
Author: Decay <>
Date:   Fri, 10 Apr 2020 12:33:02 -0700

Fix regeneration for deleted months as well

Also ditch the silly-walk over the entries list and just query the
DB directly.

Msrc/miniblog.lisp | 29+++++++++++++++--------------
1 file changed, 15 insertions(+), 14 deletions(-)

diff --git a/src/miniblog.lisp b/src/miniblog.lisp @@ -87,17 +87,14 @@ :tz *blog-timezone*))) (mapcar #'regenerate-file all))) -(defun new-month-p (entries year month) +(defun entries-in-month (year month) + "Determine number of entries in a given month and year" + (let ((entries-in-month (miniblog.db:get-entries :year year :month month))) + (length entries-in-month))) + +(defun new-month-p (year month) "Determine if there is only one entry in a given month and year" - (let ((entries-in-month - (remove-if - (lambda (entry) - (let* ((year-month (miniblog.content:year-month-of-entry entry)) - (entry-year (car year-month)) - (entry-month (cdr year-month))) - (not (and (eql year entry-year) (eql month entry-month))))) - entries))) - (eql (length entries-in-month) 1))) + (eql (entries-in-month year month) 1)) (defun add-new (regen) (let ((text (miniblog.edit:edit-text))) @@ -114,7 +111,7 @@ (year (car year-month)) (month (cdr year-month)) (entries (miniblog.db:get-entries))) - (if (or regen (new-month-p entries year month)) + (if (or regen (new-month-p year month)) (regenerate-all entries) (regenerate-index-and-given-month entries year month))) (format t "Abandoning post...~%")))) @@ -161,6 +158,10 @@ (regenerate-all entries)))) (format t "No change, abandoning...~%"))))) +(defun removed-month-p (year month) + "Determine if there are 0 entries in the given month and year" + (eql (entries-in-month year month) 0)) + (defun delete-post (id regen) (miniblog.db:with-entry-id entry id (format t "Deleting post ID ~d...~%" id) @@ -171,9 +172,9 @@ (month (timestamp-month created-at :timezone *blog-timezone*)) (entries (miniblog.db:get-entries))) - (if (not regen) - (regenerate-index-and-given-month entries year month) - (regenerate-all entries))))) + (if (or regen (removed-month-p year month)) + (regenerate-all entries) + (regenerate-index-and-given-month entries year month))))) (defun list-posts (start n) (let* ((entries (miniblog.db:get-entries))