36 Commits

Author SHA1 Message Date
6175c77478 Bump version 2022-06-10 11:24:29 +09:30
742f42115f Add error checking for URL validity 2022-06-10 11:23:55 +09:30
9e7914c9a1 Space cells so that tags do not go on a new row. 2022-06-10 11:14:21 +09:30
fe9d8e71f4 Bump version 2022-06-09 20:21:45 +09:30
0c3bf0701d Don't panic if we cannot fetch current version from github 2022-06-09 20:20:31 +09:30
0bc777c6f1 Bump version 2022-06-09 19:56:21 +09:30
2055bba5f0 Capture tag if URL added before tag submission, allow for tags to be comma separated. 2022-06-09 19:51:21 +09:30
a2a1f9c06d Fix some element positioning 2022-06-09 19:38:30 +09:30
79280135a1 Bump version 2022-06-07 20:00:12 +09:30
4422f3840e Fix bug where column headings were displayed incorrectly on small screens 2022-06-07 19:59:33 +09:30
ffcf7c0438 Bump version 2022-06-07 19:52:35 +09:30
a910aac946 Add reversible column sorting, with sort direction indicators 2022-06-07 19:51:56 +09:30
eed41aebbb Neaten the formatting of durations 2022-06-07 16:45:03 +09:30
037be4d7e8 Bump version 2022-06-07 16:26:39 +09:30
6cf327226d Add basic sorting to management interface 2022-06-07 16:25:45 +09:30
42fd1973b8 Clean up search code, limit bookmarks list by query and/or tags 2022-06-07 11:07:38 +09:30
1563c7b21d Manage list can be free-text searched and limited by tag. 2022-06-06 22:05:56 +09:30
65100459d6 Bump version 2022-06-05 16:15:36 +09:30
977e609b13 Fix - re-add needed javascript files 2022-06-05 16:15:00 +09:30
3117e730c2 Update roadmap 2022-06-05 16:03:46 +09:30
8cf034516f Bump version 2022-06-05 16:03:16 +09:30
18b1c2d559 Do version check every 6 hours 2022-06-05 16:02:40 +09:30
f3c9cf3179 Use gzip compresion and remove some unused imports 2022-06-05 16:01:01 +09:30
8c8a57433e Show if a new version is available in the menu bar 2022-06-05 12:04:47 +09:30
dab54bdeaa Bump version 2022-06-05 11:20:53 +09:30
e0eefa2d11 Add option to ignore title when scraping and provide a custom title instead. Closes #3 2022-06-05 11:19:44 +09:30
ee01887394 Fix: trim trailing slashes from BaseURL. Fixes #2 2022-06-04 11:21:28 +09:30
5ac74ce4f4 Bump version 2022-06-04 11:07:55 +09:30
e808f28554 Use minified foundation css 2022-06-04 11:06:52 +09:30
afcb88ae1b Don't changelog merge messages 2022-06-04 11:04:58 +09:30
def4e35cc9 Merge branch 'main' of https://github.com/tardisx/linkwallet 2022-06-04 11:04:14 +09:30
2ba4066643 Add tags to indices for searching 2022-06-04 11:03:26 +09:30
4cac81aab0 Add .gitattributes file to hide HTML from linguist stats 2022-06-04 11:02:52 +09:30
c4947d24b8 Create go.yml 2022-06-02 18:50:44 +09:30
194fc9eeb4 Create codeql-analysis.yml 2022-06-02 18:48:49 +09:30
6f1ef7c75c Update documentation 2022-06-02 14:19:49 +09:30
26 changed files with 445 additions and 105 deletions

1
.gitattributes vendored Normal file
View File

@@ -0,0 +1 @@
content/corpora/* linguist-vendored

72
.github/workflows/codeql-analysis.yml vendored Normal file
View File

@@ -0,0 +1,72 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"
on:
push:
branches: [ main ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ main ]
schedule:
- cron: '18 22 * * 2'
jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write
strategy:
fail-fast: false
matrix:
language: [ 'go', 'javascript' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
steps:
- name: Checkout repository
uses: actions/checkout@v3
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2
# Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
# - run: |
# echo "Run, Build Application using script"
# ./location_of_script_within_repo/buildscript.sh
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2

25
.github/workflows/go.yml vendored Normal file
View File

@@ -0,0 +1,25 @@
name: Go
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.18
- name: Build
run: go build -v ./...
- name: Test
run: go test -v ./...

View File

@@ -21,7 +21,7 @@ dockers:
build_flag_templates:
- "--platform=linux/amd64"
nfpms:
-
-
id: default
package_name: linkwallet
file_name_template: "{{ .ConventionalFileName }}"
@@ -86,6 +86,7 @@ changelog:
sort: asc
filters:
exclude:
- '^Merge:'
- '^docs:'
- '^test:'
- '^[Bb]ump'

View File

@@ -2,6 +2,7 @@
"cSpell.words": [
"bolthold",
"colly",
"htmx",
"incpatch",
"linkwallet",
"nicetime",

View File

@@ -32,6 +32,14 @@ A self-hosted bookmark database with full-text page content search.
mountpoint.
* Run `docker-compose up -d`
## Packages (deb/rpm)
* Download the .deb or .rpm from the releases
* Install using apt/dpkg/rpm
* Automatically creates a systemd service, enabled and started
* Runs as user `linkwallet`
* Database stored in `/var/lib/linkwallet`
## Binary
* Download the appropriate binary from the releases page
@@ -44,10 +52,6 @@ A self-hosted bookmark database with full-text page content search.
* Checkout the code
* `go build cmd/linkwallet/linkwallet.go`
## deb/rpm packages
Coming soon.
# Using
linkwallet is a 100% web-driven app. After running, hit the web interface
@@ -63,8 +67,7 @@ will not work.
# Roadmap
* More options when managing links
* delete
* sorting
* More tag options
* search for tags
* bookmarklet with pre-filled tags
* bookmarklet with pre-filled tags
* search/filter on tags

View File

@@ -3,6 +3,7 @@ package main
import (
"flag"
"log"
"time"
"github.com/tardisx/linkwallet/db"
"github.com/tardisx/linkwallet/version"
@@ -27,7 +28,12 @@ func main() {
bmm := db.NewBookmarkManager(&dbh)
cmm := db.NewConfigManager(&dbh)
go func() { version.UpdateVersionInfo() }()
go func() {
for {
version.UpdateVersionInfo()
time.Sleep(time.Hour * 6)
}
}()
log.Printf("linkwallet version %s starting", version.Is())

View File

@@ -1,9 +1,11 @@
package db
import (
"errors"
"fmt"
"io"
"log"
"strings"
"sync"
"time"
@@ -18,6 +20,12 @@ type BookmarkManager struct {
scrapeQueue chan *entity.Bookmark
}
type SearchOptions struct {
Query string
Tags []string
Sort string
}
func NewBookmarkManager(db *DB) *BookmarkManager {
return &BookmarkManager{db: db, scrapeQueue: make(chan *entity.Bookmark)}
}
@@ -26,6 +34,12 @@ func NewBookmarkManager(db *DB) *BookmarkManager {
// if this bookmark already exists (based on URL match).
// The entity.Bookmark ID field will be updated.
func (m *BookmarkManager) AddBookmark(bm *entity.Bookmark) error {
if strings.Index(bm.URL, "https://") != 0 &&
strings.Index(bm.URL, "http://") != 0 {
return errors.New("URL must begin with http:// or https://")
}
existing := entity.Bookmark{}
err := m.db.store.FindOne(&existing, bolthold.Where("URL").Eq(bm.URL))
if err != bolthold.ErrNotFound {
@@ -94,28 +108,12 @@ func (m *BookmarkManager) LoadBookmarkByID(id uint64) entity.Bookmark {
return ret
}
func (m *BookmarkManager) LoadBookmarksByIDs(ids []uint64) []entity.Bookmark {
// log.Printf("loading %v", ids)
ret := make([]entity.Bookmark, 0, 0)
s := make([]interface{}, len(ids))
for i, v := range ids {
s[i] = v
}
err := m.db.store.Find(&ret, bolthold.Where("ID").In(s...))
if err != nil {
panic(err)
}
return ret
}
func (m *BookmarkManager) Search(query string) ([]entity.Bookmark, error) {
rets := make([]uint64, 0, 0)
func (m *BookmarkManager) Search(opts SearchOptions) ([]entity.Bookmark, error) {
// first get a list of all the ids that match our query
idsMatchingQuery := make([]uint64, 0, 0)
counts := make(map[uint64]uint8)
words := content.StringToSearchWords(query)
words := content.StringToSearchWords(opts.Query)
for _, word := range words {
var wi *entity.WordIndex
@@ -131,24 +129,67 @@ func (m *BookmarkManager) Search(query string) ([]entity.Bookmark, error) {
}
}
// log.Printf("counts: %#v", counts)
for k, v := range counts {
if v == uint8(len(words)) {
rets = append(rets, k)
if len(rets) > 10 {
idsMatchingQuery = append(idsMatchingQuery, k)
if len(idsMatchingQuery) > 10 {
break
}
}
}
return m.LoadBookmarksByIDs(rets), nil
// now we can do our search
bhQuery := bolthold.Query{}
if opts.Query != "" {
bhQuery = bolthold.Query(*bhQuery.And("ID").In(bolthold.Slice(idsMatchingQuery)...))
}
if opts.Tags != nil && len(opts.Tags) > 0 {
bhQuery = bolthold.Query(*bhQuery.And("Tags").ContainsAll(bolthold.Slice(opts.Tags)...))
}
reverse := false
sortOrder := opts.Sort
if sortOrder != "" && sortOrder[0] == '-' {
reverse = true
sortOrder = sortOrder[1:]
}
if sortOrder == "title" {
bhQuery.SortBy("Info.Title")
} else if sortOrder == "created" {
bhQuery.SortBy("TimestampCreated")
} else if sortOrder == "scraped" {
bhQuery.SortBy("TimestampLastScraped")
} else {
bhQuery.SortBy("ID")
}
if reverse {
bhQuery = *bhQuery.Reverse()
}
out := []entity.Bookmark{}
err := m.db.store.ForEach(&bhQuery,
func(bm *entity.Bookmark) error {
out = append(out, *bm)
return nil
})
if err != nil {
panic(err)
}
return out, nil
}
func (m *BookmarkManager) ScrapeAndIndex(bm *entity.Bookmark) error {
log.Printf("Start scrape for %s", bm.URL)
info := content.FetchPageInfo(*bm)
// keep the existing title if necessary
if bm.PreserveTitle {
info.Title = bm.Info.Title
}
bm.Info = info
bm.TimestampLastScraped = time.Now()
err := m.SaveBookmark(bm)
@@ -156,11 +197,16 @@ func (m *BookmarkManager) ScrapeAndIndex(bm *entity.Bookmark) error {
panic(err)
}
m.UpdateIndexForBookmark(bm)
return nil
}
func (m *BookmarkManager) UpdateIndexForBookmark(bm *entity.Bookmark) {
words := content.Words(bm)
words = append(words, bm.Tags...)
log.Printf("index for %d %s (%d words)", bm.ID, bm.URL, len(words))
m.db.UpdateIndexForWordsByID(words, bm.ID)
return nil
}
func (m *BookmarkManager) QueueScrape(bm *entity.Bookmark) {

View File

@@ -73,7 +73,7 @@ func BenchmarkOneWordSearch(b *testing.B) {
bmm := NewBookmarkManager(&dbh)
b.ResetTimer()
for i := 0; i < b.N; i++ {
bmm.Search("hello")
bmm.Search(SearchOptions{Query: "hello"})
}
}
@@ -84,7 +84,7 @@ func BenchmarkTwoWordSearch(b *testing.B) {
bmm := NewBookmarkManager(&dbh)
b.ResetTimer()
for i := 0; i < b.N; i++ {
bmm.Search("human relate")
bmm.Search(SearchOptions{Query: "human relate"})
}
}
@@ -95,6 +95,6 @@ func BenchmarkThreeWordSearch(b *testing.B) {
bmm := NewBookmarkManager(&dbh)
b.ResetTimer()
for i := 0; i < b.N; i++ {
bmm.Search("human wiki editor")
bmm.Search(SearchOptions{Query: "human wiki editor"})
}
}

View File

@@ -47,7 +47,7 @@ func TestAddRemove(t *testing.T) {
t.Errorf("scrape index returned %s", err)
}
searchRes, err := bmm.Search("fox")
searchRes, err := bmm.Search(SearchOptions{Query: "fox"})
if err != nil {
t.Errorf("search returned %s", err)
}
@@ -62,7 +62,7 @@ func TestAddRemove(t *testing.T) {
t.Errorf("scrape index returned %s", err)
}
searchRes, err = bmm.Search("fox")
searchRes, err = bmm.Search(SearchOptions{Query: "fox"})
if err != nil {
t.Errorf("search returned %s", err)
}
@@ -70,7 +70,7 @@ func TestAddRemove(t *testing.T) {
t.Error("got result when should not")
}
searchRes, err = bmm.Search("rabbit")
searchRes, err = bmm.Search(SearchOptions{Query: "rabbit"})
if err != nil {
t.Errorf("search returned %s", err)
}
@@ -83,7 +83,7 @@ func TestAddRemove(t *testing.T) {
t.Errorf("got error when deleting: %s", err)
}
searchRes, err = bmm.Search("rabbit")
searchRes, err = bmm.Search(SearchOptions{Query: "rabbit"})
if err != nil {
t.Errorf("search returned %s", err)
}
@@ -92,3 +92,52 @@ func TestAddRemove(t *testing.T) {
}
}
func TestTagIndexing(t *testing.T) {
ts := newTestServer()
defer ts.Close()
serverResponse = "<p>the quick brown fox</p>"
db := DB{}
f, _ := os.CreateTemp("", "test_boltdb_*")
f.Close()
defer os.Remove(f.Name())
db.Open(f.Name())
bmm := NewBookmarkManager(&db)
bm := entity.Bookmark{URL: ts.URL}
err := bmm.AddBookmark(&bm)
if err != nil {
t.Fatalf("error adding: %s", err)
}
if bm.ID == 0 {
t.Error("bookmark did not get an id")
}
err = bmm.ScrapeAndIndex(&bm)
if err != nil {
t.Errorf("scrape index returned %s", err)
}
searchRes, err := bmm.Search(SearchOptions{Query: "fox"})
if err != nil {
t.Errorf("search returned %s", err)
}
if len(searchRes) != 1 {
t.Error("did not get one id")
}
// add a tag
bm.Tags = []string{"sloth"}
err = bmm.ScrapeAndIndex(&bm)
if err != nil {
t.Errorf("scrape index returned %s", err)
}
searchRes, err = bmm.Search(SearchOptions{Query: "sloth"})
if err != nil {
t.Errorf("search returned %s", err)
}
if len(searchRes) != 1 {
t.Error("did not get one id for sloth")
}
}

View File

@@ -7,6 +7,7 @@ type Bookmark struct {
URL string
Info PageInfo
Tags []string
PreserveTitle bool
TimestampCreated time.Time
TimestampLastScraped time.Time
}

2
go.mod
View File

@@ -20,7 +20,6 @@ require (
github.com/mattn/go-isatty v0.0.12 // indirect
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 // indirect
github.com/stretchr/testify v1.6.1 // indirect
github.com/ugorji/go/codec v1.1.7 // indirect
go.etcd.io/bbolt v1.3.6 // indirect
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect
@@ -34,6 +33,7 @@ require (
github.com/antchfx/htmlquery v1.2.4 // indirect
github.com/antchfx/xmlquery v1.3.10 // indirect
github.com/antchfx/xpath v1.2.0 // indirect
github.com/gin-contrib/gzip v0.0.5
github.com/gobwas/glob v0.2.3 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.2 // indirect

7
go.sum
View File

@@ -11,8 +11,11 @@ github.com/antchfx/xpath v1.2.0/go.mod h1:i54GszH55fYfBmoZXapTHN8T8tkcHfRgLyVwwq
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gin-contrib/gzip v0.0.5 h1:mhnVU32YnnBh2LPH2iqRqsA/eR7SAqRaD388jL2s/j0=
github.com/gin-contrib/gzip v0.0.5/go.mod h1:OPIK6HR0Um2vNmBUTlayD7qle4yVVRZT0PyhdUigrKk=
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
github.com/gin-gonic/gin v1.7.4/go.mod h1:jD2toBW3GZUr5UMcdrwQA10I7RuaFOl/SGeDjXkfUtY=
github.com/gin-gonic/gin v1.7.7 h1:3DoBmSbJbZAWqXJC3SLjAPfutPJJRN1U5pALB7EeTTs=
github.com/gin-gonic/gin v1.7.7/go.mod h1:axIBovoeJpVj8S3BwE0uPMTeReE4+AfFtqpqaZ1qq1U=
github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A=
@@ -71,8 +74,8 @@ github.com/saintfish/chardet v0.0.0-20120816061221-3af4cd4741ca/go.mod h1:uugorj
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/temoto/robotstxt v1.1.2 h1:W2pOjSJ6SWvldyEuiFXNxz3xZ8aiWX5LbfDiOFd7Fxg=
github.com/temoto/robotstxt v1.1.2/go.mod h1:+1AmkuG3IYkh1kv0d2qEB9Le88ehNO0zwOr3ujewlOo=
github.com/timshannon/bolthold v0.0.0-20210913165410-232392fc8a6a h1:oIi7H/bwFUYKYhzKbHc+3MvHRWqhQwXVB4LweLMiVy0=

View File

@@ -8,7 +8,7 @@ import (
"golang.org/x/mod/semver"
)
const Tag = "v0.0.15"
const Tag = "v0.0.27"
var versionInfo struct {
Local struct {
@@ -40,7 +40,14 @@ func UpgradeAvailable() (bool, string) {
return true, versionInfo.Remote.Tag
}
return false, ""
}
func UpgradeAvailableString() string {
upgrade, ver := UpgradeAvailable()
if upgrade {
return ver
}
return ""
}
func UpdateVersionInfo() {
@@ -48,7 +55,7 @@ func UpdateVersionInfo() {
rels, _, err := client.Repositories.ListReleases(context.Background(), "tardisx", "linkwallet", nil)
if err != nil {
panic(err)
return
}
if len(rels) == 0 {
return

File diff suppressed because one or more lines are too long

View File

@@ -6,9 +6,11 @@
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>linkwallet</title>
<link rel="stylesheet" href="/assets/css/foundation.css">
<link rel="stylesheet" href="/assets/css/foundation.min.css">
<link rel="stylesheet" href="/assets/css/app.css">
<script src="/assets/js/htmx.min.js" defer></script>
<script src="/assets/js/vendor/htmx.min.js" defer></script>
<script src="/assets/js/vendor/hyperscript_web.min.js"></script>
</head>
<body>
@@ -32,10 +34,17 @@
</div>
<div class="top-bar-right">
<ul class="menu">
{{ if newVersion }}
<li>
<div><a href="https://github.com/tardisx/linkwallet/releases/tag/{{ newVersion }}">{{ newVersion }} available</a></div>
</li>
{{ end }}
<li class="menu-text">
{{ version }}
</li>
<li>
<a href="https://github.com/tardisx/linkwallet">
{{ version }}
<img src="/assets/image/GitHub-Mark-32px.png" />
<img src="/assets/image/GitHub-Mark-32px.png" width="16px" height="16px"/>
</a>
</li>
<!-- <li><input type="search" placeholder="Search"></li>
@@ -59,9 +68,8 @@
{{/* template "foundation_sample.html" . */}}
</div>
<script src="/assets/js/vendor/jquery.js"></script>
<script src="/assets/js/vendor/what-input.js"></script>
<script src="/assets/js/vendor/jquery.js"></script>
<script src="/assets/js/vendor/foundation.js"></script>
<script src="/assets/js/app.js"></script>
</body>

View File

@@ -1,24 +1,24 @@
<div class="large-8 medium-8 cell" id="add-url-form" >
<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 style="display:inline-block;">[<a hx-get="/bulk_add" hx-swap="outerHTML" hx-target="#add-url-form" href="#">bulk add</a>]</div></h5>
</div>
<form onsubmit="return false">
<div class="grid-x grid-padding-x">
<div class="large-6 cell">
<label>Paste a URL</label>
<div class="medium-6 cell">
<label>URL</label>
<input type="text" name="url" value="{{ .url }}"
hx-trigger=""
/>
</div>
<div class="large-6 cell">
<div class="medium-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"
<a href="#" class="button" hx-post="/add"
hx-target="#add-url-form">add</a>
</div>
</div>

View File

@@ -1,14 +1,13 @@
<div class="large-8 medium-8 cell" id="add-url-form" >
<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">
<p style="display:inline-block;">[<a hx-get="/single_add" hx-swap="outerHTML" 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>
<textarea type="text" name="urls" rows="10"
></textarea>
<textarea type="text" name="urls" rows="10"></textarea>
</div>
</div>
<button

View File

@@ -9,7 +9,7 @@
<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>
<a class="button" href="javascript:void(window.open('{{ .config.BaseURL }}/bookmarklet?url=' +encodeURIComponent(window.location)+'&title='+encodeURIComponent(document.title), 'windowName', 'width=640,height=480'))">Bookmarklet</a>
{{ else }}

View File

@@ -3,7 +3,11 @@
<table>
<tr>
<th>Title</th>
<td>{{ .bookmark.Info.Title }}</td>
<td>
<input type="text" name="title" {{ if not .bookmark.PreserveTitle }}disabled{{ end }} id="title" value="{{ .bookmark.Info.Title }}">
<input id="checkbox" name="override_title" value="on" {{ if .bookmark.PreserveTitle }}checked{{end}} type="checkbox" _="on click toggle @disabled on #title">
<label for="checkbox">override scraped title (ignore page title when scraping)</label>
</td>
</tr>
<tr>
<th>URL</th>

View File

@@ -1,38 +1,21 @@
<div class="grid-x grid-padding-x">
<div class="grid-x grid-padding-x" id="manage">
<div class="large-12 cell">
<h5>Manage links</h5>
<table>
<tr>
<th>&nbsp;</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><a class="button" href="/edit/{{ .ID }}">edit</a></th>
<td>
<a href="{{ .URL }}">{{ .Info.Title }}</a>
<br>
<a href="{{ .URL }}">{{ niceURL .URL }}</a>
</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>
<form onsubmit="return false">
<div class="grid-x grid-padding-x">
<div class="large-12 cell">
<label>Filter</label>
<input type="text" name="query" placeholder="" hx-post="/manage/results" hx-swap="outerHTML"
hx-trigger="keyup changed delay:500ms, tag_update" hx-target="#manage-results"
hx-indicator="#htmx-indicator-search" id="manage-search" />
</div>
</div>
{{ template "tags_widget.html" . }}
{{ template "manage_results.html" . }}
<td>
<a class="button" hx-swap="outerHTML" hx-post="/scrape/{{ .ID }}">scrape</button>
</td>
</tr>
{{ end }}
</table>
</form>
</div>
</div>

View File

@@ -0,0 +1,31 @@
<table id="manage-results">
<tr>
<th>&nbsp;</th>
{{ template "manage_results_column_header.html" .column.title }}
<th>tags</th>
{{ template "manage_results_column_header.html" .column.created }}
{{ template "manage_results_column_header.html" .column.scraped }}
</tr>
{{ range .bookmarks }}
<tr>
<th><a class="button" href="/edit/{{ .ID }}">edit</a></th>
<td>
<a href="{{ .URL }}">{{ .Info.Title }}</a>
<br>
<a href="{{ .URL }}">{{ niceURL .URL }}</a>
</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>
<a class="button" hx-swap="outerHTML" hx-post="/scrape/{{ .ID }}">scrape</button>
</td>
</tr>
{{ end }}
</table>

View File

@@ -0,0 +1,3 @@
<th class="{{ .Class }}" hx-post="/manage/results?sort={{ .URLString }}" hx-target="#manage-results">{{ .Name }}&nbsp;{{ .TitleArrow }}
</th>

View File

@@ -1,15 +1,15 @@
<div id="label-widget">
<div id="label-widget" >
<div class="grid-x grid-padding-x">
<div class="small-9 medium-10 large-5 cell"
<div class="small-6 cell"
hx-post="/tags"
hx-target="#label-widget"
hx-trigger="change">
hx-trigger="change queue:first">
<label for="tag-entry"
class="">Tags</label>
<input id="tag-entry" type="text" name="tag" placeholder="enter tags" />
</div>
<div class="small-12 large-6 cell">
<div class="small-6 cell" id="tags-list">
{{ range .tags }}
<a href="#"
class=""
@@ -20,7 +20,7 @@
<span class="label primary">{{ . }}</span>
{{ end }}
<input type="hidden" name="tags_hidden" value="{{ .tags_hidden }}">
<input _="on load send tag_update to #manage-search" type="hidden" id="tags-hidden" name="tags_hidden" value="{{ .tags_hidden }}">
</div>
</div>
</div>

View File

@@ -18,6 +18,7 @@ import (
"github.com/hako/durafmt"
"github.com/gin-contrib/gzip"
"github.com/gin-gonic/gin"
)
@@ -41,6 +42,29 @@ type Server struct {
bmm *db.BookmarkManager
}
type ColumnInfo struct {
Name string
Param string
Sorted string
Class string
}
func (c ColumnInfo) URLString() string {
if c.Sorted == "asc" {
return "-" + c.Param
}
return c.Param
}
func (c ColumnInfo) TitleArrow() string {
if c.Sorted == "asc" {
return "↑"
} else if c.Sorted == "desc" {
return "↓"
}
return ""
}
// Create creates a new web server instance and sets up routing.
func Create(bmm *db.BookmarkManager, cmm *db.ConfigManager) *Server {
@@ -51,7 +75,7 @@ func Create(bmm *db.BookmarkManager, cmm *db.ConfigManager) *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, "join": strings.Join, "version": version.Is}).ParseFS(templateFiles, "templates/*.html"))
templ := template.Must(template.New("").Funcs(template.FuncMap{"nicetime": niceTime, "niceURL": niceURL, "join": strings.Join, "version": version.Is, "newVersion": version.UpgradeAvailableString}).ParseFS(templateFiles, "templates/*.html"))
config, err := cmm.LoadConfig()
if err != nil {
@@ -67,6 +91,7 @@ func Create(bmm *db.BookmarkManager, cmm *db.ConfigManager) *Server {
}
r.Use(headersByURI())
r.Use(gzip.Gzip(gzip.DefaultCompression, gzip.WithExcludedExtensions([]string{".pdf", ".mp4"})))
r.SetHTMLTemplate(templ)
r.StaticFS("/assets", http.FS(staticFS))
@@ -79,6 +104,7 @@ func Create(bmm *db.BookmarkManager, cmm *db.ConfigManager) *Server {
})
r.GET("/manage", func(c *gin.Context) {
allBookmarks, _ := bmm.ListBookmarks()
meta := gin.H{"page": "manage", "config": config, "bookmarks": allBookmarks}
c.HTML(http.StatusOK,
@@ -86,6 +112,52 @@ func Create(bmm *db.BookmarkManager, cmm *db.ConfigManager) *Server {
)
})
r.POST("/manage/results", func(c *gin.Context) {
query := c.PostForm("query")
tags := []string{}
sort := c.Query("sort")
if c.PostForm("tags_hidden") != "" {
tags = strings.Split(c.PostForm("tags_hidden"), "|")
}
allBookmarks, _ := bmm.Search(db.SearchOptions{Query: query, Tags: tags, Sort: sort})
meta := gin.H{"config": config, "bookmarks": allBookmarks}
colTitle := &ColumnInfo{Name: "Title/URL", Param: "title"}
colCreated := &ColumnInfo{Name: "Created", Param: "created", Class: "show-for-large"}
colScraped := &ColumnInfo{Name: "Scraped", Param: "scraped", Class: "show-for-large"}
if sort == "title" {
colTitle.Sorted = "asc"
}
if sort == "-title" {
colTitle.Sorted = "desc"
}
if sort == "scraped" {
colScraped.Sorted = "asc"
}
if sort == "-scraped" {
colScraped.Sorted = "desc"
}
if sort == "created" {
colCreated.Sorted = "asc"
}
if sort == "-created" {
colCreated.Sorted = "desc"
}
cols := gin.H{
"title": colTitle,
"created": colCreated,
"scraped": colScraped,
}
meta["column"] = cols
c.HTML(http.StatusOK,
"manage_results.html", meta,
)
})
r.GET("/config", func(c *gin.Context) {
meta := gin.H{"page": "config", "config": config}
c.HTML(http.StatusOK,
@@ -95,6 +167,7 @@ func Create(bmm *db.BookmarkManager, cmm *db.ConfigManager) *Server {
r.POST("/config", func(c *gin.Context) {
config.BaseURL = c.PostForm("baseurl")
config.BaseURL = strings.TrimRight(config.BaseURL, "/")
cmm.SaveConfig(&config)
meta := gin.H{"config": config}
@@ -104,7 +177,7 @@ func Create(bmm *db.BookmarkManager, cmm *db.ConfigManager) *Server {
r.POST("/search", func(c *gin.Context) {
query := c.PostForm("query")
sr, err := bmm.Search(query)
sr, err := bmm.Search(db.SearchOptions{Query: query})
data := gin.H{
"results": sr,
"error": err,
@@ -132,6 +205,13 @@ func Create(bmm *db.BookmarkManager, cmm *db.ConfigManager) *Server {
"bm": bm,
"error": err,
}
if err != nil {
data["url"] = url
data["tags"] = tags
data["tags_hidden"] = c.PostForm("tags_hidden")
}
c.HTML(http.StatusOK, "add_url_form.html", data)
})
r.POST("/add_bulk", func(c *gin.Context) {
@@ -160,7 +240,6 @@ func Create(bmm *db.BookmarkManager, cmm *db.ConfigManager) *Server {
}
}
log.Printf("well done %v, %d", totalErrors, added)
data := gin.H{
"added": added,
"errors": totalErrors,
@@ -261,6 +340,16 @@ func Create(bmm *db.BookmarkManager, cmm *db.ConfigManager) *Server {
bookmark := bmm.LoadBookmarkByID(bookmarkID)
// update title and override title
overrideTitle := c.PostForm("override_title")
if overrideTitle != "" {
title := c.PostForm("title")
bookmark.Info.Title = title
bookmark.PreserveTitle = true
} else {
bookmark.PreserveTitle = false
}
// freshen tags
if c.PostForm("tags_hidden") == "" {
// empty
@@ -268,7 +357,9 @@ func Create(bmm *db.BookmarkManager, cmm *db.ConfigManager) *Server {
} else {
bookmark.Tags = strings.Split(c.PostForm("tags_hidden"), "|")
}
bmm.SaveBookmark(&bookmark)
bmm.UpdateIndexForBookmark(&bookmark) // because title may have changed
meta := gin.H{"page": "edit", "bookmark": bookmark, "tw": gin.H{"tags": bookmark.Tags, "tags_hidden": strings.Join(bookmark.Tags, "|")}}
@@ -318,7 +409,10 @@ func cleanupTags(tags []string) []string {
keys := make(map[string]struct{})
for _, k := range tags {
if k != "" && k != "|" {
keys[strings.ToLower(k)] = struct{}{}
for _, subKey := range strings.Split(k, ",") {
subKey := strings.Trim(subKey, " ")
keys[strings.ToLower(subKey)] = struct{}{}
}
}
}
out := []string{}
@@ -342,6 +436,7 @@ func niceTime(t time.Time) timeVariations {
panic(err)
}
ago := durafmt.Parse(time.Since(t)).LimitFirstN(1).Format(units)
ago = strings.ReplaceAll(ago, " ", "")
return timeVariations{HumanDuration: ago}
}