(in-package :germinal-med)
(defun list-entries (feed-file &optional (root *germinal-root*) (server-name *germinal-server-name*))
(let* ((feed-path-directory
(make-pathname :directory
(append
(pathname-directory (fad:pathname-as-directory root))
(cdr (pathname-directory feed-file)))))
(feed-file-absolute (merge-pathnames feed-path-directory (file-namestring feed-file)))
(feed-file-directory-relative (enough-namestring feed-path-directory (fad:pathname-as-directory root)))
(entries))
(with-open-file (in feed-file-absolute :direction :input)
(loop for line = (read-line in nil 'eof)
until (eq line 'eof)
do (when (and (> (length line) 3)
(string= "=> " line :start2 0 :end2 3))
(multiple-value-bind (link/date offset)
(split-sequence:split-sequence #\Space line :start 3 :count 2)
;; check for valid date, otherwise discard
(when (local-time:parse-timestring
(string-trim " []<>()\" " (second link/date))
:fail-on-error nil)
(setf entries (cons (list
(concatenate
'string
"gemini://"
server-name "/"
(namestring (merge-pathnames feed-file-directory-relative (first link/date))))
(local-time:format-timestring
nil
(local-time:parse-timestring (second link/date)))
(string-trim "-: " (subseq line offset))) entries)))))
finally (return (sort entries #'string> :key #'second))))))
(defconstant +atom-header+ "