Implementing bookmarks for Fafi Browser

Posted  · 

This is a quick sneak peek video on some new features I’m building for Fafi 0.10.

  • Preferences
  • Bookmarks

Fafi is primarily a gemini browser but it knows a trick or two regarding other protocols and file formats :cat:

The bookmarks system is quite cute. It uses a hash table to hold the bookmarks. The keys are the URLs which are duplicated in the value as well. I set it like that because it makes it easier to update a bookmark than if it was a list and I had to iterate over it to find which record I needed to update.


(define bookmarks-file (build-path data-folder "bookmarks.rktd"))

(define bookmarks (make-parameter (make-hash)))

(serializable-struct bookmark

(define (make-bookmark url [title ""] [subscribe #f] [favourite #f] [last-checksum 0] [tags '()] [notes ""])
  (bookmark url title subscribe favourite last-checksum tags notes))

(define (add-bookmark b)
  (let ([bs (bookmarks)])
    (hash-set! bs (bookmark-url b) b)

(define (save-bookmarks)
  (let ([s (serialize (bookmarks))])
    (with-output-to-file bookmarks-file
      (lambda () (write s))
      #:exists 'replace)))

(define (load-bookmarks)
  (let ([bs (if (file-exists? bookmarks-file)
                (with-input-from-file bookmarks-file
                  (lambda () (deserialize (read))))
    (bookmarks bs)))

That is the full code of the bookmark implementation.

Source & Issue Tracker

Did you enjoyed reading this content? Want to support me?

You can buy me a coffee at ko-fi.

Comments? Questions? Feedback?

You can reach out to me on Twitter, or Mastodon, Secure Scuttlebutt, or through WebMentions.