💾 Archived View for gem.librehacker.com › gemlog › starlog › 20240214-0.gmi captured on 2024-06-20 at 12:07:51. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2024-03-21)

-=-=-=-=-=-=-

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 " <TITLE HERE>")))
      (find-file index-path) ;; enough error handling?
      (beginning-of-buffer)
      (search-forward index-header-string)
      (forward-char 2)
      (insert entry-string ?\n))))

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:

(defvar starlog-index-path (concat gemlog-directory "starlog/index.gmi"))

(defun index-starlog-post ()
  (interactive)
  (index-gemlog-post starlog-index-path "# Transmissions"))

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.

Copyright

This work © 2024 by Christopher Howard is licensed under Attribution-ShareAlike 4.0 International.

CC BY-SA 4.0 Deed