generators/gopher.lisp (4706 bytes)
1 2 (in-package #:cl-yag) 3 4 (defun generate-rss-gopher(article) 5 (format nil "gopher://~a:~d/0~a/article-~a.txt" 6 (getf *config* :gopher-server) 7 (getf *config* :gopher-port) 8 (getf *config* :gopher-path) 9 (article-id article))) 10 11 ;; generate a gopher index file 12 (defun generate-gopher-index(articles) 13 (let ((output (load-file "templates/gopher_head.tpl"))) 14 (dolist (article articles) 15 (setf output 16 (string 17 (concatenate 'string output 18 (format nil (getf *config* :gopher-format) 19 0 ;;;; gopher type, 0 for text files 20 ;; here we create a 80 width char string with title on the left 21 ;; and date on the right 22 ;; we truncate the article title if it's too large 23 (let ((title (format nil "~80a" 24 (if (< 80 (length (article-title article))) 25 (subseq (article-title article) 0 80) 26 (article-title article))))) 27 (replace title (article-rawdate article) :start1 (- (length title) (length (article-rawdate article))))) 28 (concatenate 'string 29 (getf *config* :gopher-path) "/article-" (article-id article) ".txt") 30 (getf *config* :gopher-server) 31 (getf *config* :gopher-port) 32 ))))) 33 output)) 34 35 ;; we do all the gopher hole 36 (defun create-gopher-hole() 37 38 ;;(generate-file-rss) 39 (save-file "output/gopher/rss.xml" (generate-rss #'generate-rss-gopher)) 40 41 ;; produce the gophermap file 42 (save-file (concatenate 'string "output/gopher/" (getf *config* :gopher-index)) 43 (generate-gopher-index *articles*)) 44 45 ;; produce a tag list menu 46 (let* ((directory-path "output/gopher/_tags_/") 47 (index-path (concatenate 'string directory-path (getf *config* :gopher-index)))) 48 (ensure-directories-exist directory-path) 49 (save-file index-path 50 (let ((output (load-file "templates/gopher_head.tpl"))) 51 (loop for tag in 52 ;; sort tags per articles in it 53 (sort (articles-by-tag) #'> 54 :key #'(lambda (x) (length (getf x :value)))) 55 do 56 (setf output 57 (string 58 (concatenate 59 'string output 60 (format nil (getf *config* :gopher-format) 61 1 ;; gopher type, 1 for menus 62 ;; here we create a 72 width char string with title on the left 63 ;; and number of articles on the right 64 ;; we truncate the article title if it's too large 65 (let ((title (format nil "~72a" 66 (if (< 72 (length (getf tag :NAME))) 67 (subseq (getf tag :NAME) 0 80) 68 (getf tag :NAME)))) 69 (article-number (format nil "~d article~p" (length (getf tag :value)) (length (getf tag :value))))) 70 (replace title article-number :start1 (- (length title) (length article-number)))) 71 (concatenate 'string 72 (getf *config* :gopher-path) "/" (getf tag :NAME) "/") 73 (getf *config* :gopher-server) 74 (getf *config* :gopher-port) 75 ))))) 76 output))) 77 78 ;; produce each tag gophermap index 79 (loop for tag in (articles-by-tag) do 80 (let* ((directory-path (concatenate 'string "output/gopher/" (getf tag :NAME) "/")) 81 (index-path (concatenate 'string directory-path (getf *config* :gopher-index))) 82 (articles-with-tag (loop for article in *articles* 83 when (member (article-id article) (getf tag :VALUE) :test #'equal) 84 collect article))) 85 (ensure-directories-exist directory-path) 86 (save-file index-path (generate-gopher-index articles-with-tag)))) 87 88 ;; produce each article file (adding some headers) 89 (loop for article in *articles* 90 do 91 (with-converter 92 (let ((id (article-id article))) 93 (save-file (format nil "output/gopher/article-~d.txt" id) 94 (format nil "Title: ~a~%Author: ~a~%Date: ~a~%Tags: ~a~%============~%~%~a" 95 (article-title article) 96 (article-author article) 97 (date-format (getf *config* :date-format) (article-date article)) 98 (article-tag article) 99 (load-file (format nil "data/~d~d" id (converter-extension converter-object)))))))))