Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ffcf7c0438 | |||
| a910aac946 | |||
| eed41aebbb | |||
| 037be4d7e8 | |||
| 6cf327226d | |||
| 42fd1973b8 | |||
| 1563c7b21d | |||
| 65100459d6 | |||
| 977e609b13 | |||
| 3117e730c2 | |||
| 8cf034516f | |||
| 18b1c2d559 | |||
| f3c9cf3179 | |||
| 8c8a57433e |
1
.vscode/settings.json
vendored
1
.vscode/settings.json
vendored
@@ -2,6 +2,7 @@
|
|||||||
"cSpell.words": [
|
"cSpell.words": [
|
||||||
"bolthold",
|
"bolthold",
|
||||||
"colly",
|
"colly",
|
||||||
|
"htmx",
|
||||||
"incpatch",
|
"incpatch",
|
||||||
"linkwallet",
|
"linkwallet",
|
||||||
"nicetime",
|
"nicetime",
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ will not work.
|
|||||||
# Roadmap
|
# Roadmap
|
||||||
|
|
||||||
* More options when managing links
|
* More options when managing links
|
||||||
* delete
|
|
||||||
* sorting
|
* sorting
|
||||||
* More tag options
|
* More tag options
|
||||||
* bookmarklet with pre-filled tags
|
* bookmarklet with pre-filled tags
|
||||||
|
* search/filter on tags
|
||||||
@@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"log"
|
"log"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/tardisx/linkwallet/db"
|
"github.com/tardisx/linkwallet/db"
|
||||||
"github.com/tardisx/linkwallet/version"
|
"github.com/tardisx/linkwallet/version"
|
||||||
@@ -27,7 +28,12 @@ func main() {
|
|||||||
bmm := db.NewBookmarkManager(&dbh)
|
bmm := db.NewBookmarkManager(&dbh)
|
||||||
cmm := db.NewConfigManager(&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())
|
log.Printf("linkwallet version %s starting", version.Is())
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,12 @@ type BookmarkManager struct {
|
|||||||
scrapeQueue chan *entity.Bookmark
|
scrapeQueue chan *entity.Bookmark
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type SearchOptions struct {
|
||||||
|
Query string
|
||||||
|
Tags []string
|
||||||
|
Sort string
|
||||||
|
}
|
||||||
|
|
||||||
func NewBookmarkManager(db *DB) *BookmarkManager {
|
func NewBookmarkManager(db *DB) *BookmarkManager {
|
||||||
return &BookmarkManager{db: db, scrapeQueue: make(chan *entity.Bookmark)}
|
return &BookmarkManager{db: db, scrapeQueue: make(chan *entity.Bookmark)}
|
||||||
}
|
}
|
||||||
@@ -94,28 +100,12 @@ func (m *BookmarkManager) LoadBookmarkByID(id uint64) entity.Bookmark {
|
|||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *BookmarkManager) LoadBookmarksByIDs(ids []uint64) []entity.Bookmark {
|
func (m *BookmarkManager) Search(opts SearchOptions) ([]entity.Bookmark, error) {
|
||||||
// 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)
|
|
||||||
|
|
||||||
|
// first get a list of all the ids that match our query
|
||||||
|
idsMatchingQuery := make([]uint64, 0, 0)
|
||||||
counts := make(map[uint64]uint8)
|
counts := make(map[uint64]uint8)
|
||||||
|
words := content.StringToSearchWords(opts.Query)
|
||||||
words := content.StringToSearchWords(query)
|
|
||||||
|
|
||||||
for _, word := range words {
|
for _, word := range words {
|
||||||
var wi *entity.WordIndex
|
var wi *entity.WordIndex
|
||||||
@@ -133,14 +123,55 @@ func (m *BookmarkManager) Search(query string) ([]entity.Bookmark, error) {
|
|||||||
|
|
||||||
for k, v := range counts {
|
for k, v := range counts {
|
||||||
if v == uint8(len(words)) {
|
if v == uint8(len(words)) {
|
||||||
rets = append(rets, k)
|
idsMatchingQuery = append(idsMatchingQuery, k)
|
||||||
if len(rets) > 10 {
|
if len(idsMatchingQuery) > 10 {
|
||||||
break
|
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 {
|
func (m *BookmarkManager) ScrapeAndIndex(bm *entity.Bookmark) error {
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ func BenchmarkOneWordSearch(b *testing.B) {
|
|||||||
bmm := NewBookmarkManager(&dbh)
|
bmm := NewBookmarkManager(&dbh)
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
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)
|
bmm := NewBookmarkManager(&dbh)
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
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)
|
bmm := NewBookmarkManager(&dbh)
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
bmm.Search("human wiki editor")
|
bmm.Search(SearchOptions{Query: "human wiki editor"})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ func TestAddRemove(t *testing.T) {
|
|||||||
t.Errorf("scrape index returned %s", err)
|
t.Errorf("scrape index returned %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
searchRes, err := bmm.Search("fox")
|
searchRes, err := bmm.Search(SearchOptions{Query: "fox"})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("search returned %s", err)
|
t.Errorf("search returned %s", err)
|
||||||
}
|
}
|
||||||
@@ -62,7 +62,7 @@ func TestAddRemove(t *testing.T) {
|
|||||||
t.Errorf("scrape index returned %s", err)
|
t.Errorf("scrape index returned %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
searchRes, err = bmm.Search("fox")
|
searchRes, err = bmm.Search(SearchOptions{Query: "fox"})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("search returned %s", err)
|
t.Errorf("search returned %s", err)
|
||||||
}
|
}
|
||||||
@@ -70,7 +70,7 @@ func TestAddRemove(t *testing.T) {
|
|||||||
t.Error("got result when should not")
|
t.Error("got result when should not")
|
||||||
}
|
}
|
||||||
|
|
||||||
searchRes, err = bmm.Search("rabbit")
|
searchRes, err = bmm.Search(SearchOptions{Query: "rabbit"})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("search returned %s", err)
|
t.Errorf("search returned %s", err)
|
||||||
}
|
}
|
||||||
@@ -83,7 +83,7 @@ func TestAddRemove(t *testing.T) {
|
|||||||
t.Errorf("got error when deleting: %s", err)
|
t.Errorf("got error when deleting: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
searchRes, err = bmm.Search("rabbit")
|
searchRes, err = bmm.Search(SearchOptions{Query: "rabbit"})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("search returned %s", err)
|
t.Errorf("search returned %s", err)
|
||||||
}
|
}
|
||||||
@@ -119,7 +119,7 @@ func TestTagIndexing(t *testing.T) {
|
|||||||
t.Errorf("scrape index returned %s", err)
|
t.Errorf("scrape index returned %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
searchRes, err := bmm.Search("fox")
|
searchRes, err := bmm.Search(SearchOptions{Query: "fox"})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("search returned %s", err)
|
t.Errorf("search returned %s", err)
|
||||||
}
|
}
|
||||||
@@ -133,7 +133,7 @@ func TestTagIndexing(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("scrape index returned %s", err)
|
t.Errorf("scrape index returned %s", err)
|
||||||
}
|
}
|
||||||
searchRes, err = bmm.Search("sloth")
|
searchRes, err = bmm.Search(SearchOptions{Query: "sloth"})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("search returned %s", err)
|
t.Errorf("search returned %s", err)
|
||||||
}
|
}
|
||||||
|
|||||||
2
go.mod
2
go.mod
@@ -20,7 +20,6 @@ require (
|
|||||||
github.com/mattn/go-isatty v0.0.12 // indirect
|
github.com/mattn/go-isatty v0.0.12 // indirect
|
||||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // 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/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
|
github.com/ugorji/go/codec v1.1.7 // indirect
|
||||||
go.etcd.io/bbolt v1.3.6 // indirect
|
go.etcd.io/bbolt v1.3.6 // indirect
|
||||||
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // 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/htmlquery v1.2.4 // indirect
|
||||||
github.com/antchfx/xmlquery v1.3.10 // indirect
|
github.com/antchfx/xmlquery v1.3.10 // indirect
|
||||||
github.com/antchfx/xpath v1.2.0 // 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/gobwas/glob v0.2.3 // indirect
|
||||||
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
|
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
|
||||||
github.com/golang/protobuf v1.5.2 // indirect
|
github.com/golang/protobuf v1.5.2 // indirect
|
||||||
|
|||||||
7
go.sum
7
go.sum
@@ -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.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 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
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 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
|
||||||
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
|
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 h1:3DoBmSbJbZAWqXJC3SLjAPfutPJJRN1U5pALB7EeTTs=
|
||||||
github.com/gin-gonic/gin v1.7.7/go.mod h1:axIBovoeJpVj8S3BwE0uPMTeReE4+AfFtqpqaZ1qq1U=
|
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=
|
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/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.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
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.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
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 h1:W2pOjSJ6SWvldyEuiFXNxz3xZ8aiWX5LbfDiOFd7Fxg=
|
||||||
github.com/temoto/robotstxt v1.1.2/go.mod h1:+1AmkuG3IYkh1kv0d2qEB9Le88ehNO0zwOr3ujewlOo=
|
github.com/temoto/robotstxt v1.1.2/go.mod h1:+1AmkuG3IYkh1kv0d2qEB9Le88ehNO0zwOr3ujewlOo=
|
||||||
github.com/timshannon/bolthold v0.0.0-20210913165410-232392fc8a6a h1:oIi7H/bwFUYKYhzKbHc+3MvHRWqhQwXVB4LweLMiVy0=
|
github.com/timshannon/bolthold v0.0.0-20210913165410-232392fc8a6a h1:oIi7H/bwFUYKYhzKbHc+3MvHRWqhQwXVB4LweLMiVy0=
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
"golang.org/x/mod/semver"
|
"golang.org/x/mod/semver"
|
||||||
)
|
)
|
||||||
|
|
||||||
const Tag = "v0.0.17"
|
const Tag = "v0.0.23"
|
||||||
|
|
||||||
var versionInfo struct {
|
var versionInfo struct {
|
||||||
Local struct {
|
Local struct {
|
||||||
@@ -40,7 +40,14 @@ func UpgradeAvailable() (bool, string) {
|
|||||||
return true, versionInfo.Remote.Tag
|
return true, versionInfo.Remote.Tag
|
||||||
}
|
}
|
||||||
return false, ""
|
return false, ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func UpgradeAvailableString() string {
|
||||||
|
upgrade, ver := UpgradeAvailable()
|
||||||
|
if upgrade {
|
||||||
|
return ver
|
||||||
|
}
|
||||||
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func UpdateVersionInfo() {
|
func UpdateVersionInfo() {
|
||||||
|
|||||||
@@ -34,10 +34,17 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="top-bar-right">
|
<div class="top-bar-right">
|
||||||
<ul class="menu">
|
<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>
|
<li>
|
||||||
<a href="https://github.com/tardisx/linkwallet">
|
<a href="https://github.com/tardisx/linkwallet">
|
||||||
{{ version }}
|
<img src="/assets/image/GitHub-Mark-32px.png" width="16px" height="16px"/>
|
||||||
<img src="/assets/image/GitHub-Mark-32px.png" />
|
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
<!-- <li><input type="search" placeholder="Search"></li>
|
<!-- <li><input type="search" placeholder="Search"></li>
|
||||||
@@ -61,9 +68,8 @@
|
|||||||
{{/* template "foundation_sample.html" . */}}
|
{{/* template "foundation_sample.html" . */}}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<script src="/assets/js/vendor/jquery.js"></script>
|
|
||||||
<script src="/assets/js/vendor/what-input.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/vendor/foundation.js"></script>
|
||||||
<script src="/assets/js/app.js"></script>
|
<script src="/assets/js/app.js"></script>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
@@ -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">
|
<div class="large-12 cell">
|
||||||
|
|
||||||
<h5>Manage links</h5>
|
<h5>Manage links</h5>
|
||||||
|
|
||||||
<table>
|
<form onsubmit="return false">
|
||||||
<tr>
|
<div class="grid-x grid-padding-x">
|
||||||
<th> </th>
|
<div class="large-12 cell">
|
||||||
<th>title/url</th>
|
<label>Filter</label>
|
||||||
<th>tags</th>
|
<input type="text" name="query" placeholder="" hx-post="/manage/results" hx-swap="outerHTML"
|
||||||
<th class="show-for-large">created</th>
|
hx-trigger="keyup changed delay:500ms, tag_update" hx-target="#manage-results"
|
||||||
<th class="show-for-large">scraped</th>
|
hx-indicator="#htmx-indicator-search" id="manage-search" />
|
||||||
</tr>
|
</div>
|
||||||
{{ range .bookmarks }}
|
</div>
|
||||||
<tr>
|
{{ template "tags_widget.html" . }}
|
||||||
<th><a class="button" href="/edit/{{ .ID }}">edit</a></th>
|
{{ template "manage_results.html" . }}
|
||||||
<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>
|
</form>
|
||||||
<a class="button" hx-swap="outerHTML" hx-post="/scrape/{{ .ID }}">scrape</button>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
{{ end }}
|
|
||||||
</table>
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
31
web/templates/manage_results.html
Normal file
31
web/templates/manage_results.html
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
|
||||||
|
<table id="manage-results">
|
||||||
|
<tr>
|
||||||
|
<th> </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>
|
||||||
3
web/templates/manage_results_column_header.html
Normal file
3
web/templates/manage_results_column_header.html
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
|
||||||
|
<th hx-post="/manage/results?sort={{ .URLString }}" hx-target="#manage-results">{{ .Name }} {{ .TitleArrow }}
|
||||||
|
</th>
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
<input id="tag-entry" type="text" name="tag" placeholder="enter tags" />
|
<input id="tag-entry" type="text" name="tag" placeholder="enter tags" />
|
||||||
</div>
|
</div>
|
||||||
<div class="small-12 large-6 cell">
|
<div class="small-12 large-6 cell" id="tags-list">
|
||||||
{{ range .tags }}
|
{{ range .tags }}
|
||||||
<a href="#"
|
<a href="#"
|
||||||
class=""
|
class=""
|
||||||
@@ -20,7 +20,7 @@
|
|||||||
<span class="label primary">{{ . }}</span>
|
<span class="label primary">{{ . }}</span>
|
||||||
|
|
||||||
{{ end }}
|
{{ 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>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
76
web/web.go
76
web/web.go
@@ -18,6 +18,7 @@ import (
|
|||||||
|
|
||||||
"github.com/hako/durafmt"
|
"github.com/hako/durafmt"
|
||||||
|
|
||||||
|
"github.com/gin-contrib/gzip"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -41,6 +42,28 @@ type Server struct {
|
|||||||
bmm *db.BookmarkManager
|
bmm *db.BookmarkManager
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ColumnInfo struct {
|
||||||
|
Name string
|
||||||
|
Param string
|
||||||
|
Sorted 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.
|
// Create creates a new web server instance and sets up routing.
|
||||||
func Create(bmm *db.BookmarkManager, cmm *db.ConfigManager) *Server {
|
func Create(bmm *db.BookmarkManager, cmm *db.ConfigManager) *Server {
|
||||||
|
|
||||||
@@ -51,7 +74,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{"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()
|
config, err := cmm.LoadConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -67,6 +90,7 @@ func Create(bmm *db.BookmarkManager, cmm *db.ConfigManager) *Server {
|
|||||||
}
|
}
|
||||||
|
|
||||||
r.Use(headersByURI())
|
r.Use(headersByURI())
|
||||||
|
r.Use(gzip.Gzip(gzip.DefaultCompression, gzip.WithExcludedExtensions([]string{".pdf", ".mp4"})))
|
||||||
|
|
||||||
r.SetHTMLTemplate(templ)
|
r.SetHTMLTemplate(templ)
|
||||||
r.StaticFS("/assets", http.FS(staticFS))
|
r.StaticFS("/assets", http.FS(staticFS))
|
||||||
@@ -79,6 +103,7 @@ func Create(bmm *db.BookmarkManager, cmm *db.ConfigManager) *Server {
|
|||||||
})
|
})
|
||||||
|
|
||||||
r.GET("/manage", func(c *gin.Context) {
|
r.GET("/manage", func(c *gin.Context) {
|
||||||
|
|
||||||
allBookmarks, _ := bmm.ListBookmarks()
|
allBookmarks, _ := bmm.ListBookmarks()
|
||||||
meta := gin.H{"page": "manage", "config": config, "bookmarks": allBookmarks}
|
meta := gin.H{"page": "manage", "config": config, "bookmarks": allBookmarks}
|
||||||
c.HTML(http.StatusOK,
|
c.HTML(http.StatusOK,
|
||||||
@@ -86,6 +111,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"}
|
||||||
|
colScraped := &ColumnInfo{Name: "Scraped", Param: "scraped"}
|
||||||
|
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) {
|
r.GET("/config", func(c *gin.Context) {
|
||||||
meta := gin.H{"page": "config", "config": config}
|
meta := gin.H{"page": "config", "config": config}
|
||||||
c.HTML(http.StatusOK,
|
c.HTML(http.StatusOK,
|
||||||
@@ -105,7 +176,7 @@ func Create(bmm *db.BookmarkManager, cmm *db.ConfigManager) *Server {
|
|||||||
r.POST("/search", func(c *gin.Context) {
|
r.POST("/search", func(c *gin.Context) {
|
||||||
query := c.PostForm("query")
|
query := c.PostForm("query")
|
||||||
|
|
||||||
sr, err := bmm.Search(query)
|
sr, err := bmm.Search(db.SearchOptions{Query: query})
|
||||||
data := gin.H{
|
data := gin.H{
|
||||||
"results": sr,
|
"results": sr,
|
||||||
"error": err,
|
"error": err,
|
||||||
@@ -354,6 +425,7 @@ func niceTime(t time.Time) timeVariations {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
ago := durafmt.Parse(time.Since(t)).LimitFirstN(1).Format(units)
|
ago := durafmt.Parse(time.Since(t)).LimitFirstN(1).Format(units)
|
||||||
|
ago = strings.ReplaceAll(ago, " ", "")
|
||||||
|
|
||||||
return timeVariations{HumanDuration: ago}
|
return timeVariations{HumanDuration: ago}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user