Starting Gemlog Entries Faster Part 2 (publ. 2024-02-14)

For indexing the post quickly, I came up with this function:

(defun index-gemlog-post (index-path index-header-string &optional time)
  (let* ((post-file-name (buffer-file-name))
         (post-nondirectory (file-name-nondirectory post-file-name))
         (post-directory (file-name-directory post-file-name))
         (index-directory (file-name-directory index-path))
         (time (if time time (current-time)))
         (datestring (format-time-string "%Y-%m-%d" time)))
    (if (not (equal post-directory index-directory))
        (error "File %S does not appear to be in the same directory as index %S"
               post-file-name index-path))
    (let ((entry-string
           (concat
            "=> " post-nondirectory " " datestring " ")))
      (find-file index-path) ;; enough error handling?
      (beginning-of-buffer)
      (search-forward index-header-string)
      (forward-char 2)
      (insert entry-string ?\n))))</pre><p>Currently it does not figure out the title on its own. But that shouldn't be too hard, as in principle I just need to pull it from the first line of the post, after figuring out whether or not to scrub header markup. Anyway, I just have to define a convenience function for this particular gemlog:
</p><pre>(defvar starlog-index-path (concat gemlog-directory "starlog/index.gmi"))

(defun index-starlog-post ()
  (interactive)
  (index-gemlog-post starlog-index-path "# Transmissions"))</pre><p>One thing I am little nervous about is the use of find-file, as it does not necessarily do what I would want — throw a fatal error — under some exceptional cases. E.g., I found that if the file doesn't exist, then find-file will go ahead and create a non-writable empty buffer. But there are several convenient things about find-file, namely that (1) it opens the file in a buffer, or switches to that buffer, and (2) it can process Tramp compatible file names, so that the files can be files we are working with remotely through Tramp and SSH.
</p><h2>Copyright
</h2><p>This work © 2024 by Christopher Howard is licensed under Attribution-ShareAlike 4.0 International.
</p><p><span class="gemini-fragment">=> </span><a href="https://creativecommons.org/licenses/by-sa/4.0/">CC BY-SA 4.0 Deed</a><br /><details>
<summary>Proxy Information</summary>
<dl>
<dt>Original URL</dt><dd><a href="gemini://gem.librehacker.com/gemlog/starlog/20240214-0.gmi">gemini://gem.librehacker.com/gemlog/starlog/20240214-0.gmi</a></dd>
<dt>Status Code</dt>
<dd>Success (20)</dd>
<dt>Meta</dt><dd><code>text/gemini</code></dd><dt>Capsule Response Time</dt>
<dd>800.400207 milliseconds</dd>
<dt>Gemini-to-HTML Time</dt>
<dd>0.321649 milliseconds</dd>
</dl>
<p>This content has been proxied by <a href="https://github.com/gemrest/september/tree/ba2dcfa">September (ba2dc)</a>.</p>
</details></body></html>