From e9fb727d69131de4b7b2662825bc130e2bf0020d Mon Sep 17 00:00:00 2001 From: Solene Rapenne Date: Fri, 12 Oct 2018 11:50:16 +0200 Subject: [PATCH] sort tags list per articles in it --- data/articles.lisp | 3 ++- generator.lisp | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/data/articles.lisp b/data/articles.lisp index 35b10f6..91acc08 100644 --- a/data/articles.lisp +++ b/data/articles.lisp @@ -47,7 +47,8 @@ (post :title "test" - :id "t" :date "20171214" :tag "f" :converter :org-mode) + :id "t" :date "20171214" :tag "cl-yag" :converter :org-mode) + ;; CSS (post :title "CSS For cl-yag" :id "css" :date "20171202" :tag "cl-yag" diff --git a/generator.lisp b/generator.lisp index 27653d1..86aa752 100644 --- a/generator.lisp +++ b/generator.lisp @@ -357,7 +357,10 @@ (ensure-directories-exist directory-path) (save-file index-path (let ((output (load-file "templates/gopher_head.tpl"))) - (loop for tag in (articles-by-tag) + (loop for tag in + ;; sort tags per articles in it + (sort (articles-by-tag) #'> + :key #'(lambda (x) (length (getf x :value)))) do (setf output (string @@ -365,7 +368,15 @@ 'string output (format nil (getf *config* :gopher-format) 1 ;; gopher type, 1 for menus - (getf tag :NAME) + ;; here we create a 72 width char string with title on the left + ;; and number of articles on the right + ;; we truncate the article title if it's too large + (let ((title (format nil "~72a" + (if (< 72 (length (getf tag :NAME))) + (subseq (getf tag :NAME) 0 80) + (getf tag :NAME)))) + (article-number (format nil "~d article~p" (length (getf tag :value)) (length (getf tag :value))))) + (replace title article-number :start1 (- (length title) (length article-number)))) (concatenate 'string (getf *config* :gopher-path) "/" (getf tag :NAME) "/") (getf *config* :gopher-server)