Add per-tag browsing on gopher

This commit is contained in:
Solene Rapenne 2018-10-12 11:22:34 +02:00
parent 4a5228a380
commit 142b84ab78
4 changed files with 93 additions and 57 deletions

View File

@ -3,7 +3,7 @@ LISP= ecl
all: dirs html
html: $(HTML) css
$(LISP) -load generator.lisp
$(LISP) --load generator.lisp
dirs:
mkdir -p "output/html/static"

View File

@ -17,9 +17,9 @@
:gopher-path "/user" ;; absolute path of your gopher directory
:gopher-server "my.website" ;; hostname of the gopher server
:gopher-port "70" ;; tcp port of the gopher server, 70 usually
:gopher-format "[0|~a|~a/article-~d.txt|~a|~a]~%~%" ;; menu format (geomyidae)
:gopher-format "[~d|~a|~a|~a|~a]~%" ;; menu format (geomyidae)
:gopher-index "index.gph" ;; menu file (geomyidae)
;; :gopher-format "0~a ~a/article-~d.txt ~a ~a~%~%" ;; menu format (gophernicus and others)
;; :gopher-format "~d~a ~a ~a ~a~%" ;; menu format (gophernicus and others)
;; :gopher-index "gophermap" ;; menu file (gophernicus and others)
))

View File

@ -175,6 +175,30 @@
`(progn
(save-file ,name (generate-layout ,@data))))
;; generate a gopher index file
(defun generate-gopher-index(articles)
(let ((output (load-file "templates/gopher_head.tpl")))
(dolist (article articles)
(setf output
(string
(concatenate 'string output
(format nil (getf *config* :gopher-format)
0 ;;;; gopher type, 0 for text files
;; here we create a 80 width char string with title on the left
;; and date on the right
;; we truncate the article title if it's too large
(let ((title (format nil "~80a"
(if (< 80 (length (article-title article)))
(subseq (article-title article) 0 80)
(article-title article)))))
(replace title (article-rawdate article) :start1 (- (length title) (length (article-rawdate article)))))
(concatenate 'string
(getf *config* :gopher-path) "/article-" (article-id article) ".txt")
(getf *config* :gopher-server)
(getf *config* :gopher-port)
)))))
output))
;; generate the list of tags
(defun articles-by-tag()
(let ((tag-list))
@ -325,28 +349,39 @@
;; produce the gophermap file
(save-file (concatenate 'string "output/gopher/" (getf *config* :gopher-index))
(generate-gopher-index *articles*))
;; produce a tag list menu
(let* ((directory-path "output/gopher/_tags_/")
(index-path (concatenate 'string directory-path (getf *config* :gopher-index))))
(ensure-directories-exist directory-path)
(save-file index-path
(let ((output (load-file "templates/gopher_head.tpl")))
(dolist (article *articles*)
(loop for tag in (articles-by-tag)
do
(setf output
(string
(concatenate 'string output
(concatenate
'string output
(format nil (getf *config* :gopher-format)
;; here we create a 80 width char string with title on the left
;; and date on the right
;; we truncate the article title if it's too large
(let ((title (format nil "~80a"
(if (< 80 (length (article-title article)))
(subseq (article-title article) 0 80)
(article-title article)))))
(replace title (article-rawdate article) :start1 (- (length title) (length (article-rawdate article)))))
(getf *config* :gopher-path)
(article-id article)
1 ;; gopher type, 1 for menus
(getf tag :NAME)
(concatenate 'string
(getf *config* :gopher-path) "/" (getf tag :NAME) "/")
(getf *config* :gopher-server)
(getf *config* :gopher-port)
)))))
output))
output)))
;; produce each tag gophermap index
(loop for tag in (articles-by-tag) do
(let* ((directory-path (concatenate 'string "output/gopher/" (getf tag :NAME) "/"))
(index-path (concatenate 'string directory-path (getf *config* :gopher-index)))
(articles-with-tag (loop for article in *articles*
when (member (article-id article) (getf tag :VALUE) :test #'equal)
collect article)))
(ensure-directories-exist directory-path)
(save-file index-path (generate-gopher-index articles-with-tag))))
;; produce each article file (only a copy/paste in fact)
(loop for article in *articles*

View File

@ -2,6 +2,7 @@ Hello, this is the head of your gophermap page, you can
customize it how you want !
[0|RSS Feed|/~me/rss.xml|server|port]
[1|Browse by tag|/~me/_tags_/|server|port]
-----------------------------------------------------------------