Compare commits
52 Commits
v0.0.18
...
v0.1.0-alp
| Author | SHA1 | Date | |
|---|---|---|---|
| 3a5fc1d66d | |||
| 76c5282695 | |||
| 1ca348ab45 | |||
| aec791b943 | |||
| ec6c40802f | |||
| 05a7acf601 | |||
| ecd27b6d6b | |||
| 85b98b6a25 | |||
| 8215eaa821 | |||
| b7044c13f7 | |||
| 62795261cb | |||
| c11ad6f6f7 | |||
| 1301fe9545 | |||
| 03abcc1340 | |||
| e8936beea0 | |||
| f98df478bb | |||
| a03baca498 | |||
| 1904bfd265 | |||
| 2d488ffdcc | |||
| f4c5834f0c | |||
| db72e8fb7d | |||
| 6f93f2ff50 | |||
| 2913d510bd | |||
| 8bd2c87fc6 | |||
| ccf373b863 | |||
| c5957e38db | |||
| 5be599589a | |||
| da970239a5 | |||
| 451335e17d | |||
| 6175c77478 | |||
| 742f42115f | |||
| 9e7914c9a1 | |||
| fe9d8e71f4 | |||
| 0c3bf0701d | |||
| 0bc777c6f1 | |||
| 2055bba5f0 | |||
| a2a1f9c06d | |||
| 79280135a1 | |||
| 4422f3840e | |||
| ffcf7c0438 | |||
| a910aac946 | |||
| eed41aebbb | |||
| 037be4d7e8 | |||
| 6cf327226d | |||
| 42fd1973b8 | |||
| 1563c7b21d | |||
| 65100459d6 | |||
| 977e609b13 | |||
| 3117e730c2 | |||
| 8cf034516f | |||
| 18b1c2d559 | |||
| f3c9cf3179 |
@@ -90,3 +90,4 @@ changelog:
|
||||
- '^docs:'
|
||||
- '^test:'
|
||||
- '^[Bb]ump'
|
||||
- '^[Cc]lean'
|
||||
|
||||
1
.vscode/settings.json
vendored
1
.vscode/settings.json
vendored
@@ -2,6 +2,7 @@
|
||||
"cSpell.words": [
|
||||
"bolthold",
|
||||
"colly",
|
||||
"htmx",
|
||||
"incpatch",
|
||||
"linkwallet",
|
||||
"nicetime",
|
||||
|
||||
32
README.md
32
README.md
@@ -1,7 +1,25 @@
|
||||
|
||||
# linkwallet
|
||||
|
||||
[](https://goreportcard.com/report/github.com/tardisx/linkwallet)
|
||||
|
||||
A self-hosted bookmark database with full-text page content search.
|
||||
|
||||
Searching uses English stemming, providing matches against similar words, in both page
|
||||
titles and page content. Searches are lightning fast.
|
||||
|
||||
![Search][screenshot_search]
|
||||
|
||||
Bookmark content is automatically re-scraped periodically. Tags can be applied (though with
|
||||
the full-text search they are often not needed). Bookmarks can be easily managed, and can be
|
||||
imported or exported in bulk.
|
||||
|
||||
![Admin][screenshot_admin]
|
||||
|
||||
Bookmarks can be added with two clicks via the bookmarklet.
|
||||
|
||||
![Bookmarklet][screenshot_bookmarklet]
|
||||
|
||||
# Feature list
|
||||
|
||||
* Simple cross-platform single binary deployment
|
||||
@@ -32,6 +50,11 @@ A self-hosted bookmark database with full-text page content search.
|
||||
mountpoint.
|
||||
* Run `docker-compose up -d`
|
||||
|
||||
To upgrade:
|
||||
|
||||
* `docker-compose pull`
|
||||
* `docker-compose up -d`
|
||||
|
||||
## Packages (deb/rpm)
|
||||
|
||||
* Download the .deb or .rpm from the releases
|
||||
@@ -67,7 +90,12 @@ will not work.
|
||||
# Roadmap
|
||||
|
||||
* More options when managing links
|
||||
* delete
|
||||
* sorting
|
||||
* More tag options
|
||||
* bookmarklet with pre-filled tags
|
||||
* bookmarklet with pre-filled tags
|
||||
* search/filter on tags
|
||||
|
||||
[screenshot_search]: https://raw.githubusercontent.com/tardisx/linkwallet/main/screenshot_search.png
|
||||
[screenshot_admin]: https://raw.githubusercontent.com/tardisx/linkwallet/main/screenshot_admin.png
|
||||
[screenshot_bookmarklet]: https://raw.githubusercontent.com/tardisx/linkwallet/main/screenshot_bookmarklet.png
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"flag"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"github.com/tardisx/linkwallet/db"
|
||||
"github.com/tardisx/linkwallet/version"
|
||||
@@ -24,12 +25,29 @@ func main() {
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
bmm := db.NewBookmarkManager(&dbh)
|
||||
cmm := db.NewConfigManager(&dbh)
|
||||
|
||||
go func() { version.UpdateVersionInfo() }()
|
||||
go func() {
|
||||
for {
|
||||
version.VersionInfo.UpdateVersionInfo()
|
||||
time.Sleep(time.Hour * 6)
|
||||
}
|
||||
}()
|
||||
|
||||
log.Printf("linkwallet version %s starting", version.Is())
|
||||
// update stats every 5 minutes
|
||||
go func() {
|
||||
for {
|
||||
err := dbh.UpdateBookmarkStats()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
time.Sleep(time.Minute * 5)
|
||||
}
|
||||
}()
|
||||
|
||||
log.Printf("linkwallet version %s starting", version.VersionInfo.Local.Tag)
|
||||
|
||||
server := web.Create(bmm, cmm)
|
||||
go bmm.RunQueue()
|
||||
|
||||
@@ -53,13 +53,15 @@ func FetchPageInfo(bm entity.Bookmark) entity.PageInfo {
|
||||
func Words(bm *entity.Bookmark) []string {
|
||||
words := []string{}
|
||||
|
||||
words = append(words, StringToSearchWords(bm.Info.RawText)...)
|
||||
words = append(words, StringToSearchWords(bm.Info.Title)...)
|
||||
words = append(words, StringToSearchWords(bm.URL)...)
|
||||
words = append(words, StringToStemmedSearchWords(bm.Info.RawText)...)
|
||||
words = append(words, StringToStemmedSearchWords(bm.Info.Title)...)
|
||||
words = append(words, StringToStemmedSearchWords(bm.URL)...)
|
||||
return words
|
||||
}
|
||||
|
||||
func StringToSearchWords(s string) []string {
|
||||
// StringToStemmedSearchWords returns a list of stemmed words with stop words
|
||||
// removed.
|
||||
func StringToStemmedSearchWords(s string) []string {
|
||||
words := []string{}
|
||||
|
||||
words = append(words, stemmerFilter(stopwordFilter(tokenize(s)))...)
|
||||
|
||||
@@ -68,7 +68,24 @@ func TestWords(t *testing.T) {
|
||||
words[6] != "dog" {
|
||||
t.Error("incorrect words returned")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestStemmer(t *testing.T) {
|
||||
s := `quick quick fox 😂 smile http://google.com`
|
||||
words1 := StringToStemmedSearchWords(s)
|
||||
t.Log(words1)
|
||||
if len(words1) != 7 {
|
||||
t.Error("wrong number of words")
|
||||
}
|
||||
if words1[0] != "quick" ||
|
||||
words1[1] != "quick" ||
|
||||
words1[2] != "fox" ||
|
||||
words1[3] != "smile" ||
|
||||
words1[4] != "http" ||
|
||||
words1[5] != "googl" ||
|
||||
words1[6] != "com" {
|
||||
t.Error("bad words")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
107
db/bookmarks.go
107
db/bookmarks.go
@@ -1,9 +1,12 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -18,6 +21,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 +35,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 {
|
||||
@@ -54,7 +69,7 @@ func (m *BookmarkManager) DeleteBookmark(bm *entity.Bookmark) error {
|
||||
|
||||
// ListBookmarks returns all bookmarks.
|
||||
func (m *BookmarkManager) ListBookmarks() ([]entity.Bookmark, error) {
|
||||
bookmarks := make([]entity.Bookmark, 0, 0)
|
||||
bookmarks := make([]entity.Bookmark, 0)
|
||||
err := m.db.store.Find(&bookmarks, &bolthold.Query{})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@@ -86,7 +101,6 @@ func (m *BookmarkManager) SaveBookmark(bm *entity.Bookmark) error {
|
||||
func (m *BookmarkManager) LoadBookmarkByID(id uint64) entity.Bookmark {
|
||||
// log.Printf("loading %v", ids)
|
||||
ret := entity.Bookmark{}
|
||||
log.Printf("loading id %d", id)
|
||||
err := m.db.store.Get(id, &ret)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@@ -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.StringToStemmedSearchWords(opts.Query)
|
||||
|
||||
for _, word := range words {
|
||||
var wi *entity.WordIndex
|
||||
@@ -133,14 +131,57 @@ func (m *BookmarkManager) Search(query string) ([]entity.Bookmark, error) {
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
m.db.IncrementSearches()
|
||||
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (m *BookmarkManager) ScrapeAndIndex(bm *entity.Bookmark) error {
|
||||
@@ -166,7 +207,6 @@ func (m *BookmarkManager) ScrapeAndIndex(bm *entity.Bookmark) error {
|
||||
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)
|
||||
}
|
||||
|
||||
@@ -240,3 +280,18 @@ func (m *BookmarkManager) UpdateContent() {
|
||||
time.Sleep(time.Second * 5)
|
||||
}
|
||||
}
|
||||
|
||||
func (m *BookmarkManager) Stats() (entity.DBStats, error) {
|
||||
stats := entity.DBStats{}
|
||||
err := m.db.store.Get("stats", &stats)
|
||||
if err != nil && err != bolthold.ErrNotFound {
|
||||
return stats, fmt.Errorf("could not load stats: %s", err)
|
||||
}
|
||||
// get the DB size
|
||||
fi, err := os.Stat(m.db.file)
|
||||
if err != nil {
|
||||
return stats, fmt.Errorf("could not load db file size: %s", err)
|
||||
}
|
||||
stats.FileSize = int(fi.Size())
|
||||
return stats, nil
|
||||
}
|
||||
|
||||
@@ -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"})
|
||||
}
|
||||
}
|
||||
|
||||
88
db/db.go
88
db/db.go
@@ -2,7 +2,7 @@ package db
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"github.com/tardisx/linkwallet/entity"
|
||||
bolthold "github.com/timshannon/bolthold"
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
|
||||
type DB struct {
|
||||
store *bolthold.Store
|
||||
file string
|
||||
}
|
||||
|
||||
func (db *DB) Open(path string) error {
|
||||
@@ -21,6 +22,7 @@ func (db *DB) Open(path string) error {
|
||||
return fmt.Errorf("cannot open '%s' - %s", path, err)
|
||||
}
|
||||
db.store = store
|
||||
db.file = path
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -28,8 +30,84 @@ func (db *DB) Close() {
|
||||
db.store.Close()
|
||||
}
|
||||
|
||||
func (db *DB) Dumpy() {
|
||||
res := make([]entity.Bookmark, 0, 0)
|
||||
db.store.Find(&res, &bolthold.Query{})
|
||||
log.Printf("%v", res)
|
||||
// func (db *DB) Dumpy() {
|
||||
// res := make([]entity.Bookmark, 0, 0)
|
||||
// db.store.Find(&res, &bolthold.Query{})
|
||||
// log.Printf("%v", res)
|
||||
// }
|
||||
|
||||
// IncrementSearches increments the number of searches we have ever performed by one.
|
||||
func (db *DB) IncrementSearches() error {
|
||||
txn, err := db.store.Bolt().Begin(true)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not start transaction for increment searches: %s", err)
|
||||
}
|
||||
|
||||
stats := entity.DBStats{}
|
||||
err = db.store.TxGet(txn, "stats", &stats)
|
||||
if err != nil && err != bolthold.ErrNotFound {
|
||||
txn.Rollback()
|
||||
return fmt.Errorf("could not get stats for incrementing searches: %s", err)
|
||||
}
|
||||
|
||||
stats.Searches += 1
|
||||
err = db.store.TxUpsert(txn, "stats", &stats)
|
||||
if err != nil {
|
||||
txn.Rollback()
|
||||
return fmt.Errorf("could not upsert stats for incrementing searches: %s", err)
|
||||
}
|
||||
err = txn.Commit()
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not commit increment searches transaction: %s", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// UpdateBookmarkStats updates the history on the number of bookmarks and words indexed.
|
||||
func (db *DB) UpdateBookmarkStats() error {
|
||||
|
||||
txn, err := db.store.Bolt().Begin(true)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not start transaction for update stats: %s", err)
|
||||
}
|
||||
// count bookmarks and words indexed
|
||||
bmI := entity.Bookmark{}
|
||||
wiI := entity.WordIndex{}
|
||||
bookmarkCount, err := db.store.TxCount(txn, &bmI, &bolthold.Query{})
|
||||
if err != nil {
|
||||
txn.Rollback()
|
||||
return fmt.Errorf("could not get bookmark count: %s", err)
|
||||
}
|
||||
indexWordCount, err := db.store.TxCount(txn, &wiI, &bolthold.Query{})
|
||||
if err != nil {
|
||||
txn.Rollback()
|
||||
return fmt.Errorf("could not get index word count: %s", err)
|
||||
}
|
||||
|
||||
// bucket these stats by day
|
||||
now := time.Now().Truncate(time.Hour * 24)
|
||||
|
||||
stats := entity.DBStats{}
|
||||
err = db.store.TxGet(txn, "stats", &stats)
|
||||
if err != nil && err != bolthold.ErrNotFound {
|
||||
txn.Rollback()
|
||||
return fmt.Errorf("could not get stats: %s", err)
|
||||
}
|
||||
if stats.History == nil {
|
||||
stats.History = make(map[time.Time]entity.BookmarkInfo)
|
||||
}
|
||||
stats.History[now] = entity.BookmarkInfo{Bookmarks: bookmarkCount, IndexedWords: indexWordCount}
|
||||
err = db.store.TxUpsert(txn, "stats", &stats)
|
||||
if err != nil {
|
||||
txn.Rollback()
|
||||
return fmt.Errorf("could not upsert stats: %s", err)
|
||||
}
|
||||
|
||||
err = txn.Commit()
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not commit stats transaction: %s", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
16
db/index.go
16
db/index.go
@@ -20,7 +20,20 @@ func (db *DB) UpdateIndexForWordsByID(words []string, id uint64) {
|
||||
}
|
||||
db.store.TxForEach(txn, &bolthold.Query{}, func(wi *entity.WordIndex) error {
|
||||
delete(wi.Bitmap, id)
|
||||
db.store.TxUpdate(txn, "word_index_"+wi.Word, wi)
|
||||
// if the index is now completely empty, nuke it entirely
|
||||
empty := true
|
||||
for _, v := range wi.Bitmap {
|
||||
if v {
|
||||
empty = false
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if empty {
|
||||
db.store.TxDelete(txn, "word_index_"+wi.Word, wi)
|
||||
} else {
|
||||
db.store.TxUpdate(txn, "word_index_"+wi.Word, wi)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
@@ -56,7 +69,6 @@ func (db *DB) UpdateIndexForWordsByID(words []string, id uint64) {
|
||||
|
||||
func (db *DB) DumpIndex() {
|
||||
|
||||
// delete this id from all indices
|
||||
err := db.store.ForEach(&bolthold.Query{}, func(wi *entity.WordIndex) error {
|
||||
log.Printf("%10s: %v", wi.Word, wi.Bitmap)
|
||||
return nil
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
@@ -119,7 +119,7 @@ func TestTagIndexing(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)
|
||||
}
|
||||
@@ -133,7 +133,7 @@ func TestTagIndexing(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Errorf("scrape index returned %s", err)
|
||||
}
|
||||
searchRes, err = bmm.Search("sloth")
|
||||
searchRes, err = bmm.Search(SearchOptions{Query: "sloth"})
|
||||
if err != nil {
|
||||
t.Errorf("search returned %s", err)
|
||||
}
|
||||
|
||||
48
entity/meta.go
Normal file
48
entity/meta.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package entity
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
"time"
|
||||
)
|
||||
|
||||
type DBStats struct {
|
||||
History map[time.Time]BookmarkInfo
|
||||
FileSize int
|
||||
Searches int
|
||||
}
|
||||
|
||||
type BookmarkInfo struct {
|
||||
Bookmarks int
|
||||
IndexedWords int
|
||||
}
|
||||
|
||||
func (stats DBStats) String() string {
|
||||
out := fmt.Sprintf("searches: %d\n", stats.Searches)
|
||||
|
||||
dates := []time.Time{}
|
||||
|
||||
for k := range stats.History {
|
||||
dates = append(dates, k)
|
||||
}
|
||||
|
||||
sort.Slice(dates, func(i, j int) bool { return dates[i].Before(dates[j]) })
|
||||
|
||||
for _, k := range dates {
|
||||
out += fmt.Sprintf("%s - %d bookmarks, %d words indexed\n", k, stats.History[k].Bookmarks, stats.History[k].IndexedWords)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func (stats DBStats) MostRecentBookmarkInfo() BookmarkInfo {
|
||||
mostRecent := time.Time{}
|
||||
for k := range stats.History {
|
||||
if k.After(mostRecent) {
|
||||
mostRecent = k
|
||||
}
|
||||
}
|
||||
if !mostRecent.IsZero() {
|
||||
return stats.History[mostRecent]
|
||||
}
|
||||
return BookmarkInfo{}
|
||||
}
|
||||
21
go.mod
21
go.mod
@@ -6,13 +6,20 @@ require (
|
||||
github.com/gin-gonic/gin v1.7.7
|
||||
github.com/gocolly/colly v1.2.0
|
||||
github.com/kljensen/snowball v0.6.0
|
||||
gonum.org/v1/plot v0.12.0
|
||||
)
|
||||
|
||||
require (
|
||||
git.sr.ht/~sbinet/gg v0.3.1 // indirect
|
||||
github.com/ajstarks/svgo v0.0.0-20211024235047-1546f124cd8b // indirect
|
||||
github.com/gin-contrib/sse v0.1.0 // indirect
|
||||
github.com/go-fonts/liberation v0.2.0 // indirect
|
||||
github.com/go-latex/latex v0.0.0-20210823091927-c0d11ff05a81 // indirect
|
||||
github.com/go-pdf/fpdf v0.6.0 // indirect
|
||||
github.com/go-playground/locales v0.13.0 // indirect
|
||||
github.com/go-playground/universal-translator v0.17.0 // indirect
|
||||
github.com/go-playground/validator/v10 v10.4.1 // indirect
|
||||
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
|
||||
github.com/google/go-querystring v1.1.0 // indirect
|
||||
github.com/json-iterator/go v1.1.9 // indirect
|
||||
github.com/kr/pretty v0.1.0 // indirect
|
||||
@@ -20,10 +27,10 @@ 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
|
||||
golang.org/x/crypto v0.7.0 // indirect
|
||||
golang.org/x/image v0.6.0 // indirect
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
|
||||
gopkg.in/yaml.v2 v2.2.8 // indirect
|
||||
)
|
||||
@@ -34,19 +41,21 @@ 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
|
||||
github.com/gomarkdown/markdown v0.0.0-20220627144906-e9a81102ebeb
|
||||
github.com/google/go-github/v44 v44.1.0
|
||||
github.com/hako/durafmt v0.0.0-20210608085754-5c1018a4e16b
|
||||
github.com/kennygrant/sanitize v1.2.4 // indirect
|
||||
github.com/saintfish/chardet v0.0.0-20120816061221-3af4cd4741ca // indirect
|
||||
github.com/temoto/robotstxt v1.1.2 // indirect
|
||||
github.com/timshannon/bolthold v0.0.0-20210913165410-232392fc8a6a
|
||||
golang.org/x/mod v0.5.1
|
||||
golang.org/x/net v0.0.0-20220517181318-183a9ca12b87 // indirect
|
||||
golang.org/x/sys v0.0.0-20220519141025-dcacdad47464 // indirect
|
||||
golang.org/x/text v0.3.7 // indirect
|
||||
golang.org/x/mod v0.8.0
|
||||
golang.org/x/net v0.8.0 // indirect
|
||||
golang.org/x/sys v0.6.0 // indirect
|
||||
golang.org/x/text v0.8.0 // indirect
|
||||
google.golang.org/appengine v1.6.7 // indirect
|
||||
google.golang.org/protobuf v1.27.1 // indirect
|
||||
)
|
||||
|
||||
109
go.sum
109
go.sum
@@ -1,5 +1,12 @@
|
||||
git.sr.ht/~sbinet/gg v0.3.1 h1:LNhjNn8DerC8f9DHLz6lS0YYul/b602DUxDgGkd/Aik=
|
||||
git.sr.ht/~sbinet/gg v0.3.1/go.mod h1:KGYtlADtqsqANL9ueOFkWymvzUvLMQllU5Ixo+8v3pc=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/PuerkitoBio/goquery v1.8.0 h1:PJTF7AmFCFKk1N6V6jmKfrNH9tV5pNE6lZMkG0gta/U=
|
||||
github.com/PuerkitoBio/goquery v1.8.0/go.mod h1:ypIiRMtY7COPGk+I/YbZLbxsxn9g5ejnI2HSMtkjZvI=
|
||||
github.com/ajstarks/deck v0.0.0-20200831202436-30c9fc6549a9/go.mod h1:JynElWSGnm/4RlzPXRlREEwqTHAN3T56Bv2ITsFT3gY=
|
||||
github.com/ajstarks/deck/generate v0.0.0-20210309230005-c3f852c02e19/go.mod h1:T13YZdzov6OU0A1+RfKZiZN9ca6VeKdBdyDV+BY97Tk=
|
||||
github.com/ajstarks/svgo v0.0.0-20211024235047-1546f124cd8b h1:slYM766cy2nI3BwyRiyQj/Ud48djTMtMebDqepE95rw=
|
||||
github.com/ajstarks/svgo v0.0.0-20211024235047-1546f124cd8b/go.mod h1:1KcenG0jGWcpt8ov532z81sp/kMMUG485J2InIOyADM=
|
||||
github.com/andybalholm/cascadia v1.3.1 h1:nhxRkql1kdYCc8Snf7D5/D3spOX+dBgjA6u8x004T2c=
|
||||
github.com/andybalholm/cascadia v1.3.1/go.mod h1:R4bJ1UQfqADjvDa4P6HZHLh/3OxWWEqc0Sk8XGwHqvA=
|
||||
github.com/antchfx/htmlquery v1.2.4 h1:qLteofCMe/KGovBI6SQgmou2QNyedFUW+pE+BpeZ494=
|
||||
@@ -8,13 +15,31 @@ github.com/antchfx/xmlquery v1.3.10 h1:U2yMwr8U0KmGM2iDG2Ky/3LfxNsiK4uw1bSBkeMO9
|
||||
github.com/antchfx/xmlquery v1.3.10/go.mod h1:wojC/BxjEkjJt6dPiAqUzoXO5nIMWtxHS8PD8TmN4ks=
|
||||
github.com/antchfx/xpath v1.2.0 h1:mbwv7co+x0RwgeGAOHdrKy89GvHaGvxxBtPK0uF9Zr8=
|
||||
github.com/antchfx/xpath v1.2.0/go.mod h1:i54GszH55fYfBmoZXapTHN8T8tkcHfRgLyVwwqzXNcs=
|
||||
github.com/boombuler/barcode v1.0.0/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8=
|
||||
github.com/boombuler/barcode v1.0.1/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8=
|
||||
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/fogleman/gg v1.3.0/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k=
|
||||
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-fonts/dejavu v0.1.0 h1:JSajPXURYqpr+Cu8U9bt8K+XcACIHWqWrvWCKyeFmVQ=
|
||||
github.com/go-fonts/dejavu v0.1.0/go.mod h1:4Wt4I4OU2Nq9asgDCteaAaWZOV24E+0/Pwo0gppep4g=
|
||||
github.com/go-fonts/latin-modern v0.2.0 h1:5/Tv1Ek/QCr20C6ZOz15vw3g7GELYL98KWr8Hgo+3vk=
|
||||
github.com/go-fonts/latin-modern v0.2.0/go.mod h1:rQVLdDMK+mK1xscDwsqM5J8U2jrRa3T0ecnM9pNujks=
|
||||
github.com/go-fonts/liberation v0.2.0 h1:jAkAWJP4S+OsrPLZM4/eC9iW7CtHy+HBXrEwZXWo5VM=
|
||||
github.com/go-fonts/liberation v0.2.0/go.mod h1:K6qoJYypsmfVjWg8KOVDQhLc8UDgIK2HYqyqAO9z7GY=
|
||||
github.com/go-fonts/stix v0.1.0/go.mod h1:w/c1f0ldAUlJmLBvlbkvVXLAD+tAMqobIIQpmnUIzUY=
|
||||
github.com/go-latex/latex v0.0.0-20210823091927-c0d11ff05a81 h1:6zl3BbBhdnMkpSj2YY30qV3gDcVBGtFgVsV3+/i+mKQ=
|
||||
github.com/go-latex/latex v0.0.0-20210823091927-c0d11ff05a81/go.mod h1:SX0U8uGpxhq9o2S/CELCSUxEWWAuoCUcVCQWv7G2OCk=
|
||||
github.com/go-pdf/fpdf v0.5.0/go.mod h1:HzcnA+A23uwogo0tp9yU+l3V+KXhiESpt1PMayhOh5M=
|
||||
github.com/go-pdf/fpdf v0.6.0 h1:MlgtGIfsdMEEQJr2le6b/HNr1ZlQwxyWr77r2aj2U/8=
|
||||
github.com/go-pdf/fpdf v0.6.0/go.mod h1:HzcnA+A23uwogo0tp9yU+l3V+KXhiESpt1PMayhOh5M=
|
||||
github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A=
|
||||
github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
|
||||
github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q=
|
||||
@@ -27,6 +52,8 @@ github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y=
|
||||
github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8=
|
||||
github.com/gocolly/colly v1.2.0 h1:qRz9YAn8FIH0qzgNUw+HT9UN7wm1oF9OBAilwEWpyrI=
|
||||
github.com/gocolly/colly v1.2.0/go.mod h1:Hof5T3ZswNVsOHYmba1u03W65HDWgpV5HifSuueE0EA=
|
||||
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g=
|
||||
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
|
||||
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
|
||||
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE=
|
||||
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
|
||||
@@ -35,6 +62,8 @@ github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaW
|
||||
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
||||
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
|
||||
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
||||
github.com/gomarkdown/markdown v0.0.0-20220627144906-e9a81102ebeb h1:5b/eFaSaKPFG9ygDBaPKkydKU5nFJYk08g9jPIVogMg=
|
||||
github.com/gomarkdown/markdown v0.0.0-20220627144906-e9a81102ebeb/go.mod h1:JDGcbDT52eL4fju3sZ4TeHGsQwhG9nbDV21aMyhwPoA=
|
||||
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
|
||||
@@ -47,8 +76,10 @@ github.com/hako/durafmt v0.0.0-20210608085754-5c1018a4e16b h1:wDUNC2eKiL35DbLvsD
|
||||
github.com/hako/durafmt v0.0.0-20210608085754-5c1018a4e16b/go.mod h1:VzxiSdG6j1pi7rwGm/xYI5RbtpBgM8sARDXlvEvxlu0=
|
||||
github.com/json-iterator/go v1.1.9 h1:9yzud/Ht36ygwatGx56VwCZtlI/2AD15T1X2sjSuGns=
|
||||
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
||||
github.com/jung-kurt/gofpdf v1.0.0/go.mod h1:7Id9E/uU8ce6rXgefFLlgrJj/GYY22cpxn+r32jIOes=
|
||||
github.com/kennygrant/sanitize v1.2.4 h1:gN25/otpP5vAsO2djbMhF/LQX6R7+O1TB4yv8NzpJ3o=
|
||||
github.com/kennygrant/sanitize v1.2.4/go.mod h1:LGsjYYtgxbetdg5owWB2mpgUL6e2nfw2eObZ0u0qvak=
|
||||
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
||||
github.com/kljensen/snowball v0.6.0 h1:6DZLCcZeL0cLfodx+Md4/OLC6b/bfurWUOUGs1ydfOU=
|
||||
github.com/kljensen/snowball v0.6.0/go.mod h1:27N7E8fVU5H68RlUmnWwZCfxgt4POBJfENGMvNRhldw=
|
||||
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
|
||||
@@ -64,15 +95,23 @@ github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OH
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLDQ0W1YjYsBW+p8U2u7vzgW2SQVmlNazg=
|
||||
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
||||
github.com/phpdave11/gofpdf v1.4.2/go.mod h1:zpO6xFn9yxo3YLyMvW8HcKWVdbNqgIfOOp2dXMnm1mY=
|
||||
github.com/phpdave11/gofpdi v1.0.12/go.mod h1:vBmVV0Do6hSBHC8uKUQ71JGW+ZGQq74llk/7bXwjDoI=
|
||||
github.com/phpdave11/gofpdi v1.0.13/go.mod h1:vBmVV0Do6hSBHC8uKUQ71JGW+ZGQq74llk/7bXwjDoI=
|
||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/ruudk/golang-pdf417 v0.0.0-20181029194003-1af4ab5afa58/go.mod h1:6lfFZQK844Gfx8o5WFuvpxWRwnSoipWe/p622j1v06w=
|
||||
github.com/ruudk/golang-pdf417 v0.0.0-20201230142125-a7e3863a1245/go.mod h1:pQAZKsJ8yyVxGRWYNEm9oFB8ieLgKFnamEyDmSA0BRk=
|
||||
github.com/saintfish/chardet v0.0.0-20120816061221-3af4cd4741ca h1:NugYot0LIVPxTvN8n+Kvkn6TrbMyxQiuvKdEwFdR9vI=
|
||||
github.com/saintfish/chardet v0.0.0-20120816061221-3af4cd4741ca/go.mod h1:uugorj2VCxiV1x+LzaIdVa9b4S4qGAcH6cbhh4qVxOU=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
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=
|
||||
@@ -80,38 +119,84 @@ github.com/timshannon/bolthold v0.0.0-20210913165410-232392fc8a6a/go.mod h1:iSvu
|
||||
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
|
||||
github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs=
|
||||
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
|
||||
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
go.etcd.io/bbolt v1.3.6 h1:/ecaJf0sk1l4l6V4awd65v2C3ILy7MSj+s/x1ADCIMU=
|
||||
go.etcd.io/bbolt v1.3.6/go.mod h1:qXsaaIqmgQH0T+OPdb99Bf+PKfBBQVAdyD6TY9G8XM4=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 h1:HWj/xjIHfjYU5nVXpTM0s39J9CbLn7Cc5a7IC5rwsMQ=
|
||||
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/mod v0.5.1 h1:OJxoQ/rynoF0dcCdI7cLPktw/hR2cueqYfjm43oqK38=
|
||||
golang.org/x/mod v0.5.1/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro=
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/crypto v0.7.0 h1:AvwMYaRytfdeVt3u6mLaxYtErKYjxA2OXjJ1HHq6t3A=
|
||||
golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU=
|
||||
golang.org/x/exp v0.0.0-20220827204233-334a2380cb91 h1:tnebWN09GYg9OLPss1KXj8txwZc6X6uMr6VFdcGNbHw=
|
||||
golang.org/x/image v0.0.0-20190910094157-69e4b8554b2a/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
|
||||
golang.org/x/image v0.0.0-20200119044424-58c23975cae1/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
|
||||
golang.org/x/image v0.0.0-20200430140353-33d19683fad8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
|
||||
golang.org/x/image v0.0.0-20201208152932-35266b937fa6/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
|
||||
golang.org/x/image v0.0.0-20210607152325-775e3b0c77b9/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM=
|
||||
golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM=
|
||||
golang.org/x/image v0.0.0-20211028202545-6944b10bf410/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM=
|
||||
golang.org/x/image v0.6.0 h1:bR8b5okrPI3g/gyZakLZHeWxAR8Dn5CyxXv1hLH5g/4=
|
||||
golang.org/x/image v0.6.0/go.mod h1:MXLdDR43H7cDJq5GEGXEVeeNhPgi+YYEQ2pC1byI1x0=
|
||||
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||
golang.org/x/mod v0.8.0 h1:LUYupSeNrTNCGzR/hVBk2NHZO4hXcVaW1k4Qx7rjPx8=
|
||||
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20200421231249-e086a090c8fd/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
||||
golang.org/x/net v0.0.0-20200813134508-3edf25e44fcc/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
||||
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20210916014120-12bc252f5db8/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.0.0-20220517181318-183a9ca12b87 h1:cCR+9mKLOGyX4Zx+uBZDXEDAQsvKQ/XbW4vreG5v1jU=
|
||||
golang.org/x/net v0.0.0-20220517181318-183a9ca12b87/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
|
||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
||||
golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ=
|
||||
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200923182605-d9f96fdee20d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20220519141025-dcacdad47464 h1:MpIuURY70f0iKp/oooEFtB2oENcHITo/z1b6u41pKCw=
|
||||
golang.org/x/sys v0.0.0-20220519141025-dcacdad47464/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68=
|
||||
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
|
||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
gonum.org/v1/gonum v0.12.0 h1:xKuo6hzt+gMav00meVPUlXwSdoEJP46BR+wdxQEFK2o=
|
||||
gonum.org/v1/plot v0.12.0 h1:y1ZNmfz/xHuHvtgFe8USZVyykQo5ERXPnspQNVK15Og=
|
||||
gonum.org/v1/plot v0.12.0/go.mod h1:PgiMf9+3A3PnZdJIciIXmyN1FwdAA6rXELSN761oQkw=
|
||||
google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c=
|
||||
google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
|
||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||
@@ -126,3 +211,5 @@ gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
|
||||
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
honnef.co/go/tools v0.1.3/go.mod h1:NgwopIslSNH47DimFoV78dnkksY2EFtX0ajyb3K/las=
|
||||
rsc.io/pdf v0.1.1 h1:k1MczvYDUvJBe93bYd7wrZLLUEcLZAuF824/I4e5Xr4=
|
||||
|
||||
14
meta/meta.go
Normal file
14
meta/meta.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package meta
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
func MemInfo() string {
|
||||
stats := runtime.MemStats{}
|
||||
runtime.ReadMemStats(&stats)
|
||||
|
||||
return fmt.Sprintf("%.1fMb", float64(stats.Alloc)/1024.0/1024.0)
|
||||
|
||||
}
|
||||
BIN
screenshot_admin.png
Normal file
BIN
screenshot_admin.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 175 KiB |
BIN
screenshot_bookmarklet.png
Normal file
BIN
screenshot_bookmarklet.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 36 KiB |
BIN
screenshot_search.png
Normal file
BIN
screenshot_search.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 107 KiB |
@@ -2,15 +2,17 @@ package version
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/google/go-github/v44/github"
|
||||
"golang.org/x/mod/semver"
|
||||
)
|
||||
|
||||
const Tag = "v0.0.18"
|
||||
const Tag = "v0.0.36"
|
||||
|
||||
var versionInfo struct {
|
||||
type Info struct {
|
||||
Local struct {
|
||||
Tag string
|
||||
}
|
||||
@@ -18,51 +20,58 @@ var versionInfo struct {
|
||||
Valid bool
|
||||
Tag string
|
||||
}
|
||||
m sync.Mutex
|
||||
UpgradeReleaseNotes string
|
||||
m sync.Mutex
|
||||
}
|
||||
|
||||
var VersionInfo Info
|
||||
|
||||
func init() {
|
||||
versionInfo.Remote.Valid = false
|
||||
versionInfo.Local.Tag = Tag
|
||||
VersionInfo.Remote.Valid = false
|
||||
VersionInfo.Local.Tag = Tag
|
||||
}
|
||||
|
||||
func Is() string {
|
||||
return versionInfo.Local.Tag
|
||||
}
|
||||
|
||||
func UpgradeAvailable() (bool, string) {
|
||||
versionInfo.m.Lock()
|
||||
defer versionInfo.m.Unlock()
|
||||
if !versionInfo.Remote.Valid {
|
||||
return false, ""
|
||||
func (vi *Info) UpgradeAvailable() bool {
|
||||
vi.m.Lock()
|
||||
defer vi.m.Unlock()
|
||||
if !vi.Remote.Valid {
|
||||
return false
|
||||
}
|
||||
if semver.Compare(versionInfo.Local.Tag, versionInfo.Remote.Tag) < 0 {
|
||||
return true, versionInfo.Remote.Tag
|
||||
if semver.Compare(vi.Local.Tag, vi.Remote.Tag) < 0 {
|
||||
return true
|
||||
}
|
||||
return false, ""
|
||||
return false
|
||||
}
|
||||
|
||||
func UpgradeAvailableString() string {
|
||||
upgrade, ver := UpgradeAvailable()
|
||||
if upgrade {
|
||||
return ver
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func UpdateVersionInfo() {
|
||||
func (vi *Info) UpdateVersionInfo() {
|
||||
client := github.NewClient(nil)
|
||||
|
||||
rels, _, err := client.Repositories.ListReleases(context.Background(), "tardisx", "linkwallet", nil)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
return
|
||||
}
|
||||
if len(rels) == 0 {
|
||||
return
|
||||
}
|
||||
versionInfo.m.Lock()
|
||||
versionInfo.Remote.Tag = *rels[0].TagName
|
||||
versionInfo.Remote.Valid = true
|
||||
versionInfo.m.Unlock()
|
||||
|
||||
vi.m.Lock()
|
||||
vi.Remote.Tag = *rels[0].TagName
|
||||
vi.Remote.Valid = true
|
||||
vi.UpgradeReleaseNotes = ""
|
||||
for _, r := range rels {
|
||||
if semver.Compare(VersionInfo.Local.Tag, *r.TagName) < 0 {
|
||||
vi.UpgradeReleaseNotes += fmt.Sprintf("*Version %s*\n\n", *r.TagName)
|
||||
bodyLines := strings.Split(*r.Body, "\n")
|
||||
for _, l := range bodyLines {
|
||||
if strings.Index(l, "#") == 0 && strings.Contains(l, "Changelog") {
|
||||
// do nothing, ignore the changelog heading
|
||||
} else {
|
||||
vi.UpgradeReleaseNotes += l + "\n"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
vi.m.Unlock()
|
||||
|
||||
}
|
||||
|
||||
@@ -34,13 +34,12 @@
|
||||
</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 }}
|
||||
<a href="/info">{{ version.Local.Tag }}
|
||||
{{ if version.UpgradeAvailable }}
|
||||
❗
|
||||
{{ end }}
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="https://github.com/tardisx/linkwallet">
|
||||
@@ -64,13 +63,14 @@
|
||||
{{ template "config.html" . }}
|
||||
{{ else if eq .page "edit" }}
|
||||
{{ template "edit.html" . }}
|
||||
{{ else if eq .page "info" }}
|
||||
{{ template "info.html" . }}
|
||||
{{ end }}
|
||||
{{/* 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>
|
||||
|
||||
@@ -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">
|
||||
<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>
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
<td>{{ .bookmark.URL }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>tags</th>
|
||||
<th>Tags</th>
|
||||
<td>
|
||||
{{ template "tags_widget.html" .tw }}
|
||||
</td>
|
||||
@@ -30,7 +30,10 @@
|
||||
</tr>
|
||||
</table>
|
||||
<p>
|
||||
<button type="button" hx-confirm="Delete this bookmark permanently?" hx-delete="/edit/{{.bookmark.ID}}" class="alert button">delete</button>
|
||||
<button type="button" class="button" hx-post="/edit/{{.bookmark.ID}}">save</button>
|
||||
<button type="button" hx-confirm="Delete this bookmark permanently?" hx-delete="/edit/{{.bookmark.ID}}" class="alert button">Delete</button>
|
||||
<button type="button" class="button" hx-indicator="#saving" hx-post="/edit/{{.bookmark.ID}}"> {{ if .saved }} Saved {{ else }} Save {{ end }}</button>
|
||||
<span id="saving" class="htmx-indicator">
|
||||
<img style="height:1em;" src="/assets/image/beating.gif" /> Saving...
|
||||
</span>
|
||||
</p>
|
||||
</form>
|
||||
40
web/templates/info.html
Normal file
40
web/templates/info.html
Normal file
@@ -0,0 +1,40 @@
|
||||
<div class="grid-x grid-padding-x">
|
||||
<div class="large-6 medium-12 cell">
|
||||
|
||||
<h5>System information</h5>
|
||||
<table>
|
||||
<tr><th>Memory in use</th><td>{{ meminfo }}</td></tr>
|
||||
<tr><th>Database disk size</th><td>{{ niceSizeMB .stats.FileSize }}Mb</td></tr>
|
||||
<tr><th>Bookmarks</th><td>{{ .stats.MostRecentBookmarkInfo.Bookmarks }}</td></tr>
|
||||
<tr><th>Words in index</th><td>{{ .stats.MostRecentBookmarkInfo.IndexedWords }}</td></tr>
|
||||
<tr><th>Total searches</th><td>{{ .stats.Searches }}</td></tr>
|
||||
</table>
|
||||
|
||||
<h5>Database information</h5>
|
||||
<img src="/graph/bookmarks">
|
||||
<img src="/graph/indexed_words">
|
||||
|
||||
</div>
|
||||
<div class="large-6 medium-12 cell">
|
||||
|
||||
<h5>Release info</h5>
|
||||
{{ if not version.Remote.Valid }}
|
||||
<p>GitHub version information not yet fetched.</p>
|
||||
{{ else }}
|
||||
{{ if version.UpgradeAvailable }}
|
||||
<p>
|
||||
A new version is available:
|
||||
<a href="https://github.com/tardisx/linkwallet/releases/tag/{{ version.Remote.Tag }}">
|
||||
{{ version.Remote.Tag }}
|
||||
</a>
|
||||
(you have {{ version.Local.Tag }}).
|
||||
</p>
|
||||
|
||||
{{ markdown version.UpgradeReleaseNotes }}
|
||||
|
||||
{{ else }}
|
||||
<p>You are currently running the most recent version.</p>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
|
||||
</div>
|
||||
@@ -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> </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>
|
||||
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 class="{{ .Class }}" hx-post="/manage/results?sort={{ .URLString }}" hx-target="#manage-results">{{ .Name }} {{ .TitleArrow }}
|
||||
</th>
|
||||
@@ -11,7 +11,7 @@
|
||||
<div class="large-12 cell">
|
||||
<label>Free text</label>
|
||||
<input type="text" name="query" placeholder="" hx-post="/search"
|
||||
hx-trigger="keyup changed delay:50ms, search" hx-target="#search-results"
|
||||
hx-trigger="keyup changed delay:250ms, search" hx-target="#search-results"
|
||||
hx-indicator="#htmx-indicator-search" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -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>
|
||||
197
web/web.go
197
web/web.go
@@ -14,11 +14,19 @@ import (
|
||||
|
||||
"github.com/tardisx/linkwallet/db"
|
||||
"github.com/tardisx/linkwallet/entity"
|
||||
"github.com/tardisx/linkwallet/meta"
|
||||
"github.com/tardisx/linkwallet/version"
|
||||
|
||||
"github.com/gomarkdown/markdown"
|
||||
"github.com/hako/durafmt"
|
||||
|
||||
"github.com/gin-contrib/gzip"
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"gonum.org/v1/plot"
|
||||
"gonum.org/v1/plot/font"
|
||||
"gonum.org/v1/plot/plotter"
|
||||
"gonum.org/v1/plot/vg"
|
||||
)
|
||||
|
||||
//go:embed static/*
|
||||
@@ -41,9 +49,38 @@ 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 {
|
||||
|
||||
// Set the default font for graphs
|
||||
plot.DefaultFont = font.Font{
|
||||
Typeface: "Liberation",
|
||||
Variant: "Mono",
|
||||
}
|
||||
|
||||
// setup routes for the static assets (vendor includes)
|
||||
staticFS, err := fs.Sub(staticFiles, "static")
|
||||
if err != nil {
|
||||
@@ -51,7 +88,16 @@ 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, "newVersion": version.UpgradeAvailableString}).ParseFS(templateFiles, "templates/*.html"))
|
||||
templ := template.Must(template.New("").Funcs(
|
||||
template.FuncMap{
|
||||
"nicetime": niceTime,
|
||||
"niceURL": niceURL,
|
||||
"niceSizeMB": func(s int) string { return fmt.Sprintf("%.1f", float32(s)/1024/1024) },
|
||||
"join": strings.Join,
|
||||
"version": func() *version.Info { return &version.VersionInfo },
|
||||
"meminfo": meta.MemInfo,
|
||||
"markdown": func(s string) template.HTML { return template.HTML(string(markdown.ToHTML([]byte(s), nil, nil))) },
|
||||
}).ParseFS(templateFiles, "templates/*.html"))
|
||||
|
||||
config, err := cmm.LoadConfig()
|
||||
if err != nil {
|
||||
@@ -67,6 +113,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 +126,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 +134,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,
|
||||
@@ -105,7 +199,14 @@ 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)
|
||||
// no query, return an empty response
|
||||
if len(query) == 0 {
|
||||
c.Status(http.StatusNoContent)
|
||||
c.Writer.Write([]byte{})
|
||||
return
|
||||
}
|
||||
|
||||
sr, err := bmm.Search(db.SearchOptions{Query: query})
|
||||
data := gin.H{
|
||||
"results": sr,
|
||||
"error": err,
|
||||
@@ -133,8 +234,16 @@ 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) {
|
||||
urls := c.PostForm("urls")
|
||||
|
||||
@@ -282,7 +391,7 @@ func Create(bmm *db.BookmarkManager, cmm *db.ConfigManager) *Server {
|
||||
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, "|")}}
|
||||
meta := gin.H{"page": "edit", "bookmark": bookmark, "saved": true, "tw": gin.H{"tags": bookmark.Tags, "tags_hidden": strings.Join(bookmark.Tags, "|")}}
|
||||
|
||||
c.HTML(http.StatusOK,
|
||||
"edit_form.html", meta,
|
||||
@@ -307,9 +416,85 @@ func Create(bmm *db.BookmarkManager, cmm *db.ConfigManager) *Server {
|
||||
)
|
||||
})
|
||||
|
||||
r.GET("/info", func(c *gin.Context) {
|
||||
dbStats, err := bmm.Stats()
|
||||
if err != nil {
|
||||
panic("could not load stats for info page")
|
||||
}
|
||||
meta := gin.H{"page": "info", "stats": dbStats, "config": config}
|
||||
c.HTML(http.StatusOK,
|
||||
"_layout.html", meta,
|
||||
)
|
||||
})
|
||||
|
||||
r.GET("/graph/:type", func(c *gin.Context) {
|
||||
|
||||
graphType := c.Param("type")
|
||||
p := plot.New()
|
||||
|
||||
dbStats, err := bmm.Stats()
|
||||
if err != nil {
|
||||
panic("could not load stats for graph page")
|
||||
}
|
||||
|
||||
sortedKeys := make([]time.Time, 0)
|
||||
for k := range dbStats.History {
|
||||
sortedKeys = append(sortedKeys, k)
|
||||
}
|
||||
sort.Slice(sortedKeys, func(i, j int) bool {
|
||||
return sortedKeys[i].Before(sortedKeys[j])
|
||||
})
|
||||
|
||||
xTicks := plot.TimeTicks{Format: "2006-01-02"}
|
||||
p.X.Tick.Marker = xTicks
|
||||
|
||||
plotPoints(sortedKeys, dbStats, p, graphType)
|
||||
|
||||
writerTo, err := p.WriterTo(vg.Points(640), vg.Points(480), "png")
|
||||
if err != nil {
|
||||
panic("error creating WriterTo: " + err.Error())
|
||||
}
|
||||
|
||||
c.Header("Content-Type", "image/png")
|
||||
writerTo.WriteTo(c.Writer)
|
||||
|
||||
})
|
||||
|
||||
return server
|
||||
}
|
||||
|
||||
func plotPoints(sortedKeys []time.Time, dbStats entity.DBStats, p *plot.Plot, k string) {
|
||||
|
||||
if k == "indexed_words" {
|
||||
p.Title.Text = "Indexed words over time"
|
||||
p.Y.Label.Text = "Words indexed"
|
||||
} else if k == "bookmarks" {
|
||||
p.Title.Text = "Bookmarks over time"
|
||||
p.Y.Label.Text = "Bookmarks"
|
||||
} else {
|
||||
panic("bad k")
|
||||
}
|
||||
p.X.Label.Text = "Date"
|
||||
|
||||
pts := make(plotter.XYs, len(sortedKeys))
|
||||
for i := range sortedKeys {
|
||||
pts[i].X = float64(sortedKeys[i].Unix())
|
||||
if k == "indexed_words" {
|
||||
pts[i].Y = float64(dbStats.History[sortedKeys[i]].IndexedWords)
|
||||
} else if k == "bookmarks" {
|
||||
pts[i].Y = float64(dbStats.History[sortedKeys[i]].Bookmarks)
|
||||
} else {
|
||||
panic("bad key")
|
||||
}
|
||||
}
|
||||
|
||||
l, err := plotter.NewLine(pts)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
p.Add(l)
|
||||
}
|
||||
|
||||
// headersByURI sets the headers for some special cases, set a custom long cache time for
|
||||
// static resources.
|
||||
func headersByURI() gin.HandlerFunc {
|
||||
@@ -330,7 +515,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{}
|
||||
@@ -354,6 +542,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}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user