Recently Written · git

sbm-sync

Sync server for sbm bookmark files: one small Go program, plain files, AGPL

git clone https://github.com/equwal/sbm-sync

Log | Files | Refs


commit 6880bf43e5eab79805c61375d839bcbc5b02f822
equwal <truex@equwal.com>
2026-09-22 19:23:19 -0700

Search the bookmarks from the home page

When the account can use its bookmarks, the home page shows a search
box. The results show under it while you type, and Enter opens the
first result. An empty box shows no results. Without script, the box
opens the search on the bookmarks page.

 README.md   |  3 ++-
 pages.html  |  5 +++++
 web_test.go | 20 ++++++++++++++++++++
 3 files changed, 27 insertions(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 317e39d..5d8669d 100644
--- a/README.md
+++ b/README.md
@@ -39,7 +39,8 @@ sync), nothing is removed: the result is the union of both files.
 ## Bookmarks on the web
 
 After you sign in, the page **/bookmarks** shows your bookmarks in any
-browser, also on a phone. It does what bm does:
+browser, also on a phone. The home page then has the search box too. The
+page does what bm does:
 
 - Search as fzf does, with the search of the add-on. The results change
   while you type, and Enter opens the first result (Ctrl+Enter: in a new
diff --git a/pages.html b/pages.html
index 3b5d4c7..45f357e 100644
--- a/pages.html
+++ b/pages.html
@@ -50,6 +50,11 @@ details { margin: 1em 0; } summary { cursor: pointer; }
 
 {{define "home"}}{{template "head" .}}
 <h1>Your bookmarks, the same everywhere</h1>
+{{if .Active}}<form id="search" method="get" action="/bookmarks">
+<input type="search" name="q" placeholder="Search your bookmarks, or type an address" aria-label="Search your bookmarks" autocomplete="off" autofocus>
+</form>
+<div id="results" data-empty="clear"></div>
+<script src="/search.js" defer></script>{{end}}
 <p><a href="https://github.com/equwal/sbm">sbm</a> keeps your bookmarks in one plain
 text file. sbm Sync keeps that file the same on each of your devices: bm on
 your computers, the sbm app for Android, and the sbm add-on for Firefox and
diff --git a/web_test.go b/web_test.go
index 51054fe..29b1ec4 100644
--- a/web_test.go
+++ b/web_test.go
@@ -433,6 +433,26 @@ func TestOtherSiteCannotChangeBookmarks(t *testing.T) {
 	}
 }
 
+func TestSearchOnTheHomePage(t *testing.T) {
+	e := newEnv(t, false)
+	e.withMail()
+	if strings.Contains(e.body(e.browser(), "/"), `id="search"`) {
+		t.Error("the home page shows the search to a visitor who is not signed in")
+	}
+	c := e.signup("me@example.org")
+	if strings.Contains(e.body(c, "/"), `id="search"`) {
+		t.Error("the home page shows the search before the email check")
+	}
+	e.open(e.link())
+	page := e.body(c, "/")
+	for _, want := range []string{`<form id="search" method="get" action="/bookmarks">`,
+		`<div id="results" data-empty="clear"></div>`, `<script src="/search.js" defer></script>`} {
+		if !strings.Contains(page, want) {
+			t.Errorf("the home page has no %q", want)
+		}
+	}
+}
+
 func TestLiveSearch(t *testing.T) {
 	e := newEnv(t, false)
 	c, _, _ := e.account("https://a.org\tA\t\ngemini://b.org\tB\t\n")