nx-router

A declarative URL routing extension for Nyxt

  • common-lisp
  • browser

nx-router is a declarative URL routing extension for the Nyxt browser.

It offers a convenient wrapper around the built-in request resource handling functionality in Nyxt by introducingrouter objects users can include in their configuration to define redirects, blocklists, and resource openers with an easy and declarative syntax.

It aims to be simple while staying composable and flexible. Routers are defined like this:

(list
  (make-instance 'router:redirector
    :name 'fandom
    :route "https://([\w'-]+)\.fandom.com/wiki/(.*)"
    :redirect "https://breezewiki.com/\1/wiki/\2")
  (make-instance 'router:blocker
    :name 'fandom
    :route (match-domain "fandom.com")
    :instances-builder router:breezewiki-instances-builder
    :blocklist ".*/search")
  (make-instance 'router:opener
    :name 'fandom
    :resource "mpv --video=no ~a"))

A particular feature of the redirector router is support for reverse redirects so that certain URLs get recorded with their original path, which is useful if you don't want to record alternative frontends URLs and potentially deal with unmaintained instances in the future.

(make-instance 'router:redirector
  :route (match-regex "https://.*google.com/search.*")
  :redirect (quri:uri "http://localhost:5000")
  :reverse (quri:uri "https://www.google.com"))