Add option to ignore title when scraping and provide a custom title instead. Closes #3
This commit is contained in:
parent
ee01887394
commit
e0eefa2d11
@ -147,6 +147,10 @@ func (m *BookmarkManager) ScrapeAndIndex(bm *entity.Bookmark) error {
|
||||
|
||||
log.Printf("Start scrape for %s", bm.URL)
|
||||
info := content.FetchPageInfo(*bm)
|
||||
// keep the existing title if necessary
|
||||
if bm.PreserveTitle {
|
||||
info.Title = bm.Info.Title
|
||||
}
|
||||
bm.Info = info
|
||||
bm.TimestampLastScraped = time.Now()
|
||||
err := m.SaveBookmark(bm)
|
||||
@ -154,12 +158,16 @@ func (m *BookmarkManager) ScrapeAndIndex(bm *entity.Bookmark) error {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
m.UpdateIndexForBookmark(bm)
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (m *BookmarkManager) UpdateIndexForBookmark(bm *entity.Bookmark) {
|
||||
words := content.Words(bm)
|
||||
words = append(words, bm.Tags...)
|
||||
log.Printf("index for %d %s (%d words)", bm.ID, bm.URL, len(words))
|
||||
m.db.UpdateIndexForWordsByID(words, bm.ID)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *BookmarkManager) QueueScrape(bm *entity.Bookmark) {
|
||||
|
@ -7,6 +7,7 @@ type Bookmark struct {
|
||||
URL string
|
||||
Info PageInfo
|
||||
Tags []string
|
||||
PreserveTitle bool
|
||||
TimestampCreated time.Time
|
||||
TimestampLastScraped time.Time
|
||||
}
|
||||
|
2
web/static/js/vendor/hyperscript_web.min.js
vendored
Normal file
2
web/static/js/vendor/hyperscript_web.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
@ -8,7 +8,9 @@
|
||||
<title>linkwallet</title>
|
||||
<link rel="stylesheet" href="/assets/css/foundation.min.css">
|
||||
<link rel="stylesheet" href="/assets/css/app.css">
|
||||
<script src="/assets/js/htmx.min.js" defer></script>
|
||||
<script src="/assets/js/vendor/htmx.min.js" defer></script>
|
||||
<script src="/assets/js/vendor/hyperscript_web.min.js"></script>
|
||||
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
@ -7,7 +7,7 @@
|
||||
<form onsubmit="return false">
|
||||
<div class="grid-x grid-padding-x">
|
||||
<div class="large-6 cell">
|
||||
<label>Paste a URL</label>
|
||||
<label>URL</label>
|
||||
<input type="text" name="url" value="{{ .url }}"
|
||||
hx-trigger=""
|
||||
/>
|
||||
|
@ -9,7 +9,7 @@
|
||||
<p>Then whenever you are on a webpage you would like to bookmark, just
|
||||
click the bookmarklet.</p>
|
||||
|
||||
<a class="button" href="javascript:void(window.open('{{ .config.BaseURL }}/bookmarklet?url=' +encodeURIComponent(window.location), 'windowName', 'width=640,height=480'))">Bookmarklet</a>
|
||||
<a class="button" href="javascript:void(window.open('{{ .config.BaseURL }}/bookmarklet?url=' +encodeURIComponent(window.location)+'&title='+encodeURIComponent(document.title), 'windowName', 'width=640,height=480'))">Bookmarklet</a>
|
||||
|
||||
|
||||
{{ else }}
|
||||
|
@ -3,7 +3,11 @@
|
||||
<table>
|
||||
<tr>
|
||||
<th>Title</th>
|
||||
<td>{{ .bookmark.Info.Title }}</td>
|
||||
<td>
|
||||
<input type="text" name="title" {{ if not .bookmark.PreserveTitle }}disabled{{ end }} id="title" value="{{ .bookmark.Info.Title }}">
|
||||
<input id="checkbox" name="override_title" value="on" {{ if .bookmark.PreserveTitle }}checked{{end}} type="checkbox" _="on click toggle @disabled on #title">
|
||||
<label for="checkbox">override scraped title (ignore page title when scraping)</label>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>URL</th>
|
||||
|
13
web/web.go
13
web/web.go
@ -161,7 +161,6 @@ func Create(bmm *db.BookmarkManager, cmm *db.ConfigManager) *Server {
|
||||
}
|
||||
}
|
||||
|
||||
log.Printf("well done %v, %d", totalErrors, added)
|
||||
data := gin.H{
|
||||
"added": added,
|
||||
"errors": totalErrors,
|
||||
@ -262,6 +261,16 @@ func Create(bmm *db.BookmarkManager, cmm *db.ConfigManager) *Server {
|
||||
|
||||
bookmark := bmm.LoadBookmarkByID(bookmarkID)
|
||||
|
||||
// update title and override title
|
||||
overrideTitle := c.PostForm("override_title")
|
||||
if overrideTitle != "" {
|
||||
title := c.PostForm("title")
|
||||
bookmark.Info.Title = title
|
||||
bookmark.PreserveTitle = true
|
||||
} else {
|
||||
bookmark.PreserveTitle = false
|
||||
}
|
||||
|
||||
// freshen tags
|
||||
if c.PostForm("tags_hidden") == "" {
|
||||
// empty
|
||||
@ -269,7 +278,9 @@ func Create(bmm *db.BookmarkManager, cmm *db.ConfigManager) *Server {
|
||||
} else {
|
||||
bookmark.Tags = strings.Split(c.PostForm("tags_hidden"), "|")
|
||||
}
|
||||
|
||||
bmm.SaveBookmark(&bookmark)
|
||||
bmm.UpdateIndexForBookmark(&bookmark) // because title may have changed
|
||||
|
||||
meta := gin.H{"page": "edit", "bookmark": bookmark, "tw": gin.H{"tags": bookmark.Tags, "tags_hidden": strings.Join(bookmark.Tags, "|")}}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user