diff --git a/src/gui/client/main-window.lisp b/src/gui/client/main-window.lisp index aa81430..baa7261 100644 --- a/src/gui/client/main-window.lisp +++ b/src/gui/client/main-window.lisp @@ -780,7 +780,8 @@ path))) (ev:with-enqueued-process-and-unblock () (clean-gemtext main-window) - (collect-ir-lines path gui-goodies:*main-frame* parsed-lines))) + (collect-ir-lines path gui-goodies:*main-frame* parsed-lines) + (render-toc main-window path))) (if force-rendering (let ((lines (cev:enqueue-request-and-wait-results :gemini-slurp-local-file 1 diff --git a/src/gui/server/public-api-gemini-stream.lisp b/src/gui/server/public-api-gemini-stream.lisp index 12e33fd..dc3d6fe 100644 --- a/src/gui/server/public-api-gemini-stream.lisp +++ b/src/gui/server/public-api-gemini-stream.lisp @@ -410,10 +410,15 @@ (let ((status (gemini-stream-status iri))) (eq status :completed))) -(defun build-gemini-toc (iri width) +(defun parsed-lines-from-remore-iri (iri) + (a:when-let ((stream-wrapper (gw:find-db-stream-url iri))) + (gw:parsed-lines stream-wrapper))) + +(defun parsed-lines-from-local-path (path) + (gemini-parser:parse-gemini-file (fs:slurp-file path))) + +(defun parsed-lines->toc (parsed-lines width) (a:when-let* ((ordered-headers-tag '(:h1 :h2 :h3)) - (stream-wrapper (gw:find-db-stream-url iri)) - (parsed-lines (gw:parsed-lines stream-wrapper)) (headers (remove-if-not (lambda (a) (member (html-utils:tag a) ordered-headers-tag)) parsed-lines))) @@ -466,6 +471,12 @@ :text (ellipsize text width))) toc))))) +(defun build-gemini-toc (iri width) + (a:when-let* ((parsed-lines (if (fs:file-exists-p iri) + (parsed-lines-from-local-path iri) + (parsed-lines-from-remore-iri iri)))) + (parsed-lines->toc parsed-lines width))) + (defclass gemini-toc (box) ()) (defun encode-flat-array-of-plists (list stream)