Add option to ignore title when scraping and provide a custom title instead. Closes #3

This commit is contained in:
2022-06-05 11:19:44 +09:30
parent ee01887394
commit e0eefa2d11
9 changed files with 35 additions and 7 deletions

View File

@@ -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) {