mirror of
https://github.com/go-shiori/shiori.git
synced 2025-10-06 19:47:16 +08:00
Clear UTM parameters from URL
This commit is contained in:
parent
8ebe093efd
commit
d167379546
2 changed files with 33 additions and 0 deletions
26
cmd/add.go
26
cmd/add.go
|
@ -2,6 +2,7 @@ package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"html/template"
|
"html/template"
|
||||||
|
nurl "net/url"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -59,6 +60,12 @@ func addBookmark(base model.Bookmark, offline bool) (book model.Bookmark, err er
|
||||||
// Prepare initial result
|
// Prepare initial result
|
||||||
book = base
|
book = base
|
||||||
|
|
||||||
|
// Clear UTM parameters from URL
|
||||||
|
book.URL, err = clearUTMParams(book.URL)
|
||||||
|
if err != nil {
|
||||||
|
return book, err
|
||||||
|
}
|
||||||
|
|
||||||
// Fetch data from internet
|
// Fetch data from internet
|
||||||
if !offline {
|
if !offline {
|
||||||
article, err := readability.Parse(book.URL, 10*time.Second)
|
article, err := readability.Parse(book.URL, 10*time.Second)
|
||||||
|
@ -94,3 +101,22 @@ func addBookmark(base model.Bookmark, offline bool) (book model.Bookmark, err er
|
||||||
func normalizeSpace(str string) string {
|
func normalizeSpace(str string) string {
|
||||||
return strings.Join(strings.Fields(str), " ")
|
return strings.Join(strings.Fields(str), " ")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func clearUTMParams(uri string) (string, error) {
|
||||||
|
tempURL, err := nurl.Parse(uri)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
newQuery := nurl.Values{}
|
||||||
|
for key, value := range tempURL.Query() {
|
||||||
|
if strings.HasPrefix(key, "utm_") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
newQuery[key] = value
|
||||||
|
}
|
||||||
|
|
||||||
|
tempURL.RawQuery = newQuery.Encode()
|
||||||
|
return tempURL.String(), nil
|
||||||
|
}
|
||||||
|
|
|
@ -82,6 +82,13 @@ func init() {
|
||||||
|
|
||||||
func updateBookmarks(indices []string, url, title, excerpt string, tags []string, offline bool) ([]model.Bookmark, error) {
|
func updateBookmarks(indices []string, url, title, excerpt string, tags []string, offline bool) ([]model.Bookmark, error) {
|
||||||
mutex := sync.Mutex{}
|
mutex := sync.Mutex{}
|
||||||
|
|
||||||
|
// Clear UTM parameters from URL
|
||||||
|
url, err := clearUTMParams(url)
|
||||||
|
if err != nil {
|
||||||
|
return []model.Bookmark{}, err
|
||||||
|
}
|
||||||
|
|
||||||
// Read bookmarks from database
|
// Read bookmarks from database
|
||||||
bookmarks, err := DB.GetBookmarks(true, indices...)
|
bookmarks, err := DB.GetBookmarks(true, indices...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Add table
Reference in a new issue