Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 10e205dd8e | |||
| 360c3fcc11 | |||
| f8060fbef6 | |||
| cbe455b566 | |||
| 0fc2a597cd | |||
| adbf2ef450 | |||
| be10f5238e | |||
| 78488d2f41 | |||
| 7399fbc5ff | |||
| f62499f6b5 | |||
| 16006c1f1b | |||
| 92c293205d | |||
| 6473b48a5b | |||
| 385397c980 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,4 +1,3 @@
|
||||
badger/
|
||||
dist/
|
||||
tmp/
|
||||
linkwallet
|
||||
|
||||
@@ -11,11 +11,15 @@ builds:
|
||||
- windows
|
||||
- darwin
|
||||
dockers:
|
||||
- image_templates:
|
||||
- goos: linux
|
||||
goarch: amd64
|
||||
image_templates:
|
||||
- "tardisx/linkwallet:{{ .Tag }}"
|
||||
- "tardisx/linkwallet:v{{ .Major }}"
|
||||
- "tardisx/linkwallet:v{{ .Major }}.{{ .Minor }}"
|
||||
- "tardisx/linkwallet"
|
||||
build_flag_templates:
|
||||
- "--platform=linux/amd64"
|
||||
archives:
|
||||
- replacements:
|
||||
darwin: Darwin
|
||||
@@ -33,3 +37,4 @@ changelog:
|
||||
exclude:
|
||||
- '^docs:'
|
||||
- '^test:'
|
||||
- '^[Bb]ump'
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
FROM scratch
|
||||
FROM alpine:3.16
|
||||
ENTRYPOINT ["/linkwallet"]
|
||||
COPY linkwallet /
|
||||
19
README.md
19
README.md
@@ -1 +1,20 @@
|
||||
# linkwallet
|
||||
|
||||
A self-hosted bookmark database with full-text page content search.
|
||||
|
||||
# Feature list
|
||||
|
||||
* Simple cross-platform single binary deployment
|
||||
* or docker if you prefer
|
||||
* Full-text search
|
||||
* Bookmark content is scraped and indexed locally
|
||||
* Page content periodically refreshed automatically
|
||||
* Interactively search across titles and content
|
||||
* Rippingly fast results, as you type
|
||||
* Embedded database, no separate database system required
|
||||
* Light on resources
|
||||
|
||||
# Roadmap
|
||||
|
||||
* Bookmarklet
|
||||
* Tags
|
||||
|
||||
26
cmd/linkwallet/linkwallet.go
Normal file
26
cmd/linkwallet/linkwallet.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"github.com/tardisx/linkwallet/db"
|
||||
"github.com/tardisx/linkwallet/version"
|
||||
"github.com/tardisx/linkwallet/web"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
dbh := db.DB{}
|
||||
dbh.Open("badger")
|
||||
bmm := db.NewBookmarkManager(&dbh)
|
||||
cmm := db.NewConfigManager(&dbh)
|
||||
|
||||
go func() { version.UpdateVersionInfo() }()
|
||||
|
||||
log.Printf("linkallet verison %s starting", version.Is())
|
||||
|
||||
server := web.Create(bmm, cmm)
|
||||
go bmm.RunQueue()
|
||||
go bmm.UpdateContent()
|
||||
server.Start()
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package db
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -48,6 +49,19 @@ func (m *BookmarkManager) ListBookmarks() ([]entity.Bookmark, error) {
|
||||
return bookmarks, nil
|
||||
}
|
||||
|
||||
// ExportBookmarks exports all bookmarks to an io.Writer
|
||||
func (m *BookmarkManager) ExportBookmarks(w io.Writer) error {
|
||||
bms := []entity.Bookmark{}
|
||||
err := m.db.store.Find(&bms, &badgerhold.Query{})
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not export bookmarks: %w", err)
|
||||
}
|
||||
for _, bm := range bms {
|
||||
w.Write([]byte(bm.URL + "\n"))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *BookmarkManager) SaveBookmark(bm *entity.Bookmark) error {
|
||||
err := m.db.store.Update(bm.ID, &bm)
|
||||
if err != nil {
|
||||
|
||||
49
db/config.go
Normal file
49
db/config.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/tardisx/linkwallet/entity"
|
||||
"github.com/timshannon/badgerhold/v4"
|
||||
)
|
||||
|
||||
type ConfigManager struct {
|
||||
db *DB
|
||||
}
|
||||
|
||||
func NewConfigManager(db *DB) *ConfigManager {
|
||||
return &ConfigManager{db: db}
|
||||
}
|
||||
|
||||
func (cmm *ConfigManager) LoadConfig() (entity.Config, error) {
|
||||
config := entity.Config{}
|
||||
err := cmm.db.store.FindOne(&config, &badgerhold.Query{})
|
||||
if err == nil {
|
||||
if config.Version == 1 {
|
||||
return config, nil
|
||||
} else {
|
||||
return entity.Config{}, fmt.Errorf("failed to load config - wrong version %d", config.Version)
|
||||
}
|
||||
} else if err == badgerhold.ErrNotFound {
|
||||
log.Printf("using default config")
|
||||
return cmm.DefaultConfig(), nil
|
||||
} else {
|
||||
return entity.Config{}, fmt.Errorf("failed to load config: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (cmm *ConfigManager) DefaultConfig() entity.Config {
|
||||
return entity.Config{
|
||||
BaseURL: "http://localhost:8080",
|
||||
Version: 1,
|
||||
}
|
||||
}
|
||||
|
||||
func (cmm *ConfigManager) SaveConfig(conf *entity.Config) error {
|
||||
err := cmm.db.store.Upsert("config", conf)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not save config: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -23,7 +23,7 @@ func (db *DB) UpdateIndexForWordsByID(words []string, id uint64) {
|
||||
delete(wi.Bitmap, id)
|
||||
})
|
||||
|
||||
// addiing
|
||||
// adding
|
||||
var find, store time.Duration
|
||||
for i, word := range words {
|
||||
// log.Printf("indexing %s", word)
|
||||
|
||||
6
entity/config.go
Normal file
6
entity/config.go
Normal file
@@ -0,0 +1,6 @@
|
||||
package entity
|
||||
|
||||
type Config struct {
|
||||
BaseURL string
|
||||
Version int
|
||||
}
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"golang.org/x/mod/semver"
|
||||
)
|
||||
|
||||
const Tag = "v0.0.3"
|
||||
const Tag = "v0.0.10"
|
||||
|
||||
var versionInfo struct {
|
||||
Local struct {
|
||||
|
||||
BIN
web/static/image/GitHub-Mark-32px.png
Normal file
BIN
web/static/image/GitHub-Mark-32px.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.7 KiB |
@@ -21,14 +21,23 @@
|
||||
<li>
|
||||
<a href="#">Admin</a>
|
||||
<ul class="menu vertical">
|
||||
<li><a href="/config">Configuration</a></li>
|
||||
<li><a href="/manage">Manage links</a></li>
|
||||
<li><a href="/export">Export all URLs</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a href="javascript:void(window.open('{{ .config.BaseURL }}/bookmarklet?url=' +encodeURIComponent(window.location), 'windowName', 'width=640,height=480'))">Bookmarklet</a></li>
|
||||
|
||||
</ul>
|
||||
</div>
|
||||
<div class="top-bar-right">
|
||||
<ul class="menu">
|
||||
<li><a href="https://github.com">gh</a></li>
|
||||
<li>
|
||||
<a href="https://github.com/tardisx/linkwallet">
|
||||
{{ version }}
|
||||
<img src="/assets/image/GitHub-Mark-32px.png" />
|
||||
</a>
|
||||
</li>
|
||||
<!-- <li><input type="search" placeholder="Search"></li>
|
||||
<li><button type="button" class="button">Search</button></li> -->
|
||||
</ul>
|
||||
@@ -38,8 +47,12 @@
|
||||
<div class="grid-container">
|
||||
{{ if eq .page "root" }}
|
||||
{{ template "search.html" . }}
|
||||
{{ else if eq .page "bookmarklet_click" }}
|
||||
{{ template "bookmarklet.html" . }}
|
||||
{{ else if eq .page "manage" }}
|
||||
{{ template "manage.html" . }}
|
||||
{{ else if eq .page "config" }}
|
||||
{{ template "config.html" . }}
|
||||
{{ end }}
|
||||
{{/* template "foundation_sample.html" . */}}
|
||||
</div>
|
||||
|
||||
@@ -1,19 +1,27 @@
|
||||
<div class="large-8 medium-8 cell" id="add-url-form" >
|
||||
<h5>Add a new URL</h5>
|
||||
<span>[<a hx-get="/bulk_add" hx-target="#add-url-form" href="#">bulk</a>]</span>
|
||||
<div>
|
||||
<h5 style="display:inline-block;">Add a new URL</h5>
|
||||
<p style="display:inline-block;">[<a hx-get="/bulk_add" hx-target="#add-url-form" href="#">bulk add</a>]</h5>
|
||||
</div>
|
||||
|
||||
<form onsubmit="return false">
|
||||
<div class="grid-x grid-padding-x">
|
||||
<div class="large-6 cell">
|
||||
<label>Paste a URL</label>
|
||||
<input type="text" name="url"
|
||||
hx-post="/add"
|
||||
hx-target="#add-url-form" hx-trigger=""
|
||||
<input type="text" name="url" value="{{ .url }}"
|
||||
hx-trigger=""
|
||||
/>
|
||||
</div>
|
||||
<div class="large-6 cell">
|
||||
{{ template "tags_widget.html" . }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="grid-x grid-padding-x">
|
||||
<div class="medium-6 cell">
|
||||
<a href="#" class="button" hx-post="/add"
|
||||
hx-target="#add-url-form">add</a>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
{{ if .error }}
|
||||
<p class="error">{{ .error }}</p>
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
<div class="large-8 medium-8 cell" id="add-url-form" >
|
||||
<h5>Add URLs in bulk</h5>
|
||||
<span>[<a hx-get="/single_add" hx-target="#add-url-form" href="#">single</a>]</span>
|
||||
<form onsubmit="return false">
|
||||
<div>
|
||||
<h5 style="display:inline-block;">Add bulk URLs</h5>
|
||||
<p style="display:inline-block;">[<a hx-get="/single_add" hx-target="#add-url-form" href="#">single add</a>]</h5>
|
||||
</div> <form onsubmit="return false">
|
||||
<div class="grid-x grid-padding-x">
|
||||
<div class="large-12 cell">
|
||||
<label>Paste URL's, one per line</label>
|
||||
|
||||
20
web/templates/bookmarklet.html
Normal file
20
web/templates/bookmarklet.html
Normal file
@@ -0,0 +1,20 @@
|
||||
<div class="grid-x grid-padding-x">
|
||||
<div class="large-12 cell">
|
||||
|
||||
{{ if .clicked }}
|
||||
|
||||
<p>Drag the bookmarklet link below to your bookmarks bar, or right click
|
||||
it, copy the link and add it to your bookmarks manually.</p>
|
||||
|
||||
<p>Then whenever you are on a webpage you would like to bookmark, just
|
||||
click the bookmarklet.</p>
|
||||
|
||||
<a class="button" href="javascript:void(window.open('{{ .config.BaseURL }}/bookmarklet?url=' +encodeURIComponent(window.location), 'windowName', 'width=640,height=480'))">Bookmarklet</a>
|
||||
|
||||
|
||||
{{ else }}
|
||||
{{ template "add_url_form.html" .}}
|
||||
{{ end }}
|
||||
|
||||
</div>
|
||||
</div>
|
||||
7
web/templates/config.html
Normal file
7
web/templates/config.html
Normal file
@@ -0,0 +1,7 @@
|
||||
<div class="grid-x grid-padding-x">
|
||||
<div class="large-12 cell">
|
||||
|
||||
<h5>Configuration</h5>
|
||||
{{ template "config_form.html" . }}
|
||||
</div>
|
||||
</div>
|
||||
12
web/templates/config_form.html
Normal file
12
web/templates/config_form.html
Normal file
@@ -0,0 +1,12 @@
|
||||
|
||||
<form onsubmit="false;" id="config-form" hx-target="#config-form">
|
||||
<table>
|
||||
<tr>
|
||||
<th>Base URL</th>
|
||||
<td>
|
||||
<input type="text" name="baseurl" value="{{ .config.BaseURL }}">
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<p><a class="button" hx-post="/config">save</a></p>
|
||||
</form>
|
||||
@@ -1,12 +1,16 @@
|
||||
<div class="grid-x grid-padding-x">
|
||||
<div class="large-12 cell">
|
||||
|
||||
<h5>Manage:
|
||||
|
||||
</h5>
|
||||
<h5>Manage links</h5>
|
||||
|
||||
<table>
|
||||
<tr><th>id</th><th>url</th><th>created</th><th>scraped</th></tr>
|
||||
<tr>
|
||||
<th>id</th>
|
||||
<th>title/url</th>
|
||||
<th>tags</th>
|
||||
<th class="show-for-large">created</th>
|
||||
<th class="show-for-large">scraped</th>
|
||||
</tr>
|
||||
{{ range .bookmarks }}
|
||||
<tr>
|
||||
<th>{{ .ID }}</th>
|
||||
@@ -15,11 +19,16 @@
|
||||
<br>
|
||||
<a href="{{ .URL }}">{{ niceURL .URL }}</a>
|
||||
</td>
|
||||
<td>{{ (nicetime .TimestampCreated).HumanDuration }} ago</td>
|
||||
<td>{{ (nicetime .TimestampLastScraped).HumanDuration }} ago</td>
|
||||
<td>
|
||||
{{ range .Tags }}
|
||||
<span class="label primary">{{ . }}</span>
|
||||
{{ end }}
|
||||
</td>
|
||||
<td class="show-for-large">{{ (nicetime .TimestampCreated).HumanDuration }} ago</td>
|
||||
<td class="show-for-large">{{ (nicetime .TimestampLastScraped).HumanDuration }} ago</td>
|
||||
|
||||
<td>
|
||||
<button class="button" hx-post="/scrape/{{ .ID }}">scrape</button>
|
||||
<a class="button" hx-swap="outerHTML" hx-post="/scrape/{{ .ID }}">scrape</button>
|
||||
</td>
|
||||
</tr>
|
||||
{{ end }}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
<div class="grid-x grid-padding-x">
|
||||
<div class="large-8 medium-8 cell">
|
||||
<div class="large-6 medium-12 cell">
|
||||
|
||||
<h5>Search:
|
||||
<h5>Search
|
||||
<span id="htmx-indicator-search" class="htmx-indicator">
|
||||
<img src="/assets/image/beating.gif" /> Searching...
|
||||
<img style="height:1em;" src="/assets/image/beating.gif" /> Searching...
|
||||
</span>
|
||||
</h5>
|
||||
<form onsubmit="return false">
|
||||
@@ -19,9 +19,9 @@
|
||||
<div id="search-results">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="large-6 medium-12 cell">
|
||||
{{ template "add_url_form.html" . }}
|
||||
|
||||
</div>
|
||||
|
||||
<!-- <div class="large-4 medium-4 cell">
|
||||
<h5>Try one of these buttons:</h5>
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
<div id="label-widget">
|
||||
<div class="grid-x grid-padding-x">
|
||||
<div class="small-3 medium-2 large-1 cell">
|
||||
</div>
|
||||
<div class="small-9 medium-10 large-5 cell"
|
||||
hx-post="/tags"
|
||||
hx-target="#label-widget"
|
||||
@@ -14,15 +12,15 @@
|
||||
<div class="small-12 large-6 cell">
|
||||
{{ range .tags }}
|
||||
<a href="#"
|
||||
class=""
|
||||
title="remove {{ . }}"
|
||||
hx-trigger="click"
|
||||
hx-target="#label-widget"
|
||||
hx-post="/tags?remove={{ . }}">
|
||||
{{ . }}
|
||||
</a>
|
||||
hx-post="/tags?remove={{ . }}">[-]</a>
|
||||
<span class="label primary">{{ . }}</span>
|
||||
|
||||
{{ end }}
|
||||
<input type="hidden" name="tags_hidden" value="{{ .tags_hidden }}">
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
60
web/web.go
60
web/web.go
@@ -14,6 +14,7 @@ import (
|
||||
|
||||
"github.com/tardisx/linkwallet/db"
|
||||
"github.com/tardisx/linkwallet/entity"
|
||||
"github.com/tardisx/linkwallet/version"
|
||||
|
||||
"github.com/hako/durafmt"
|
||||
|
||||
@@ -41,7 +42,7 @@ type Server struct {
|
||||
}
|
||||
|
||||
// Create creates a new web server instance and sets up routing.
|
||||
func Create(bmm *db.BookmarkManager) *Server {
|
||||
func Create(bmm *db.BookmarkManager, cmm *db.ConfigManager) *Server {
|
||||
|
||||
// setup routes for the static assets (vendor includes)
|
||||
staticFS, err := fs.Sub(staticFiles, "static")
|
||||
@@ -50,7 +51,12 @@ func Create(bmm *db.BookmarkManager) *Server {
|
||||
}
|
||||
|
||||
// templ := template.Must(template.New("").Funcs(template.FuncMap{"dict": dictHelper}).ParseFS(templateFiles, "templates/*.html"))
|
||||
templ := template.Must(template.New("").Funcs(template.FuncMap{"nicetime": niceTime, "niceURL": niceURL}).ParseFS(templateFiles, "templates/*.html"))
|
||||
templ := template.Must(template.New("").Funcs(template.FuncMap{"nicetime": niceTime, "niceURL": niceURL, "join": strings.Join, "version": version.Is}).ParseFS(templateFiles, "templates/*.html"))
|
||||
|
||||
config, err := cmm.LoadConfig()
|
||||
if err != nil {
|
||||
log.Fatalf("could not start server - failed to load config: %s", err)
|
||||
}
|
||||
|
||||
r := gin.Default()
|
||||
|
||||
@@ -66,7 +72,7 @@ func Create(bmm *db.BookmarkManager) *Server {
|
||||
r.StaticFS("/assets", http.FS(staticFS))
|
||||
|
||||
r.GET("/", func(c *gin.Context) {
|
||||
meta := gin.H{"page": "root"}
|
||||
meta := gin.H{"page": "root", "config": config}
|
||||
c.HTML(http.StatusOK,
|
||||
"_layout.html", meta,
|
||||
)
|
||||
@@ -74,12 +80,27 @@ func Create(bmm *db.BookmarkManager) *Server {
|
||||
|
||||
r.GET("/manage", func(c *gin.Context) {
|
||||
allBookmarks, _ := bmm.ListBookmarks()
|
||||
meta := gin.H{"page": "manage", "bookmarks": allBookmarks}
|
||||
meta := gin.H{"page": "manage", "config": config, "bookmarks": allBookmarks}
|
||||
c.HTML(http.StatusOK,
|
||||
"_layout.html", meta,
|
||||
)
|
||||
})
|
||||
|
||||
r.GET("/config", func(c *gin.Context) {
|
||||
meta := gin.H{"page": "config", "config": config}
|
||||
c.HTML(http.StatusOK,
|
||||
"_layout.html", meta,
|
||||
)
|
||||
})
|
||||
|
||||
r.POST("/config", func(c *gin.Context) {
|
||||
config.BaseURL = c.PostForm("baseurl")
|
||||
cmm.SaveConfig(&config)
|
||||
meta := gin.H{"config": config}
|
||||
|
||||
c.HTML(http.StatusOK, "config_form.html", meta)
|
||||
})
|
||||
|
||||
r.POST("/search", func(c *gin.Context) {
|
||||
query := c.PostForm("query")
|
||||
|
||||
@@ -151,8 +172,6 @@ func Create(bmm *db.BookmarkManager) *Server {
|
||||
|
||||
r.POST("/tags", func(c *gin.Context) {
|
||||
|
||||
log.Printf("POST: tag '%s' tags_hidden '%s'", c.PostForm("tag"), c.PostForm("tags_hidden"))
|
||||
|
||||
newTag := c.PostForm("tag")
|
||||
oldTags := strings.Split(c.PostForm("tags_hidden"), "|")
|
||||
|
||||
@@ -186,7 +205,32 @@ func Create(bmm *db.BookmarkManager) *Server {
|
||||
idNum, _ := strconv.ParseInt(id, 10, 32)
|
||||
bm := bmm.LoadBookmarkByID(uint64(idNum))
|
||||
bmm.QueueScrape(&bm)
|
||||
c.String(http.StatusOK, "queued")
|
||||
c.String(http.StatusOK, "<p>scrape queued</p>")
|
||||
})
|
||||
|
||||
r.GET("/export", func(c *gin.Context) {
|
||||
c.Writer.Header().Set("Content-Type", "text/plain")
|
||||
c.Writer.Header().Set("Content-Disposition", "attachment; filename=\"bookmarks.txt\"")
|
||||
err := bmm.ExportBookmarks(c.Writer)
|
||||
// this is a bit late, but we already added headers, so at least log it.
|
||||
if err != nil {
|
||||
log.Printf("got error when exporting: %s", err)
|
||||
}
|
||||
})
|
||||
|
||||
r.GET("/bookmarklet", func(c *gin.Context) {
|
||||
url := c.Query("url")
|
||||
|
||||
meta := gin.H{"page": "bookmarklet_click", "config": config, "url": url}
|
||||
|
||||
// check if they just clicked it from the actual app
|
||||
if strings.Index(url, config.BaseURL) == 0 {
|
||||
meta["clicked"] = true
|
||||
}
|
||||
|
||||
c.HTML(http.StatusOK,
|
||||
"_layout.html", meta,
|
||||
)
|
||||
})
|
||||
|
||||
return server
|
||||
@@ -212,7 +256,7 @@ func cleanupTags(tags []string) []string {
|
||||
keys := make(map[string]struct{})
|
||||
for _, k := range tags {
|
||||
if k != "" && k != "|" {
|
||||
keys[k] = struct{}{}
|
||||
keys[strings.ToLower(k)] = struct{}{}
|
||||
}
|
||||
}
|
||||
out := []string{}
|
||||
|
||||
Reference in New Issue
Block a user