Skip to content

Commit

Permalink
keep rss & web content | rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Yrovas authored and danielyrovas committed Mar 28, 2024
1 parent 6592c1a commit 29ee5ec
Show file tree
Hide file tree
Showing 30 changed files with 325 additions and 193 deletions.
8 changes: 7 additions & 1 deletion internal/api/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,13 @@ func (h *handler) fetchContent(w http.ResponseWriter, r *http.Request) {
return
}

json.OK(w, r, map[string]string{"content": entry.Content})
if request.QueryBoolParam(r, "save", false) {
if err := h.store.UpdateEntryTitleAndContent(entry); err != nil {
json.ServerError(w, r, err)
}
}

json.OK(w, r, map[string]string{"content": entry.Content, "web_content": entry.WebContent})
}

func (h *handler) flushHistory(w http.ResponseWriter, r *http.Request) {
Expand Down
7 changes: 7 additions & 0 deletions internal/database/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -882,4 +882,11 @@ var migrations = []func(tx *sql.Tx) error{
_, err = tx.Exec(sql)
return err
},
func(tx *sql.Tx) (err error) {
sql := `
ALTER TABLE entries ADD COLUMN web_content text default '';
`
_, err = tx.Exec(sql)
return err
},
}
2 changes: 2 additions & 0 deletions internal/locale/translations/de_DE.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
"entry.save.title": "Diesen Artikel speichern",
"entry.save.completed": "Erledigt!",
"entry.save.toast.completed": "Artikel gespeichert",
"entry.scraper.label.rss": "RSS-Inhalte anzeigen",
"entry.scraper.title.rss": "RSS-Inhalte abrufen",
"entry.scraper.label": "Herunterladen",
"entry.scraper.title": "Inhalt herunterladen",
"entry.scraper.completed": "Erledigt!",
Expand Down
2 changes: 2 additions & 0 deletions internal/locale/translations/el_EL.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
"entry.save.title": "Αποθηκεύστε αυτό το άρθρο",
"entry.save.completed": "Έγινε!",
"entry.save.toast.completed": "Το άρθρο αποθηκεύτηκε",
"entry.scraper.label.rss": "Εμφάνιση περιεχομένου RSS",
"entry.scraper.title.rss": "Λήψη περιεχομένου RSS",
"entry.scraper.label": "Λήψη",
"entry.scraper.title": "Λήψη αρχικού περιεχομένου",
"entry.scraper.completed": "Έγινε!",
Expand Down
2 changes: 2 additions & 0 deletions internal/locale/translations/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
"entry.save.title": "Save this entry",
"entry.save.completed": "Done!",
"entry.save.toast.completed": "Entry saved",
"entry.scraper.label.rss": "Show RSS Content",
"entry.scraper.title.rss": "Fetch RSS content",
"entry.scraper.label": "Download",
"entry.scraper.title": "Fetch original content",
"entry.scraper.completed": "Done!",
Expand Down
2 changes: 2 additions & 0 deletions internal/locale/translations/es_ES.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
"entry.save.title": "Guardar este artículo",
"entry.save.completed": "¡Hecho!",
"entry.save.toast.completed": "Artículos guardados",
"entry.scraper.label.rss": "Mostrar contenido RSS",
"entry.scraper.title.rss": "Obtener contenido RSS",
"entry.scraper.label": "Descargar",
"entry.scraper.title": "Obtener contenido original",
"entry.scraper.completed": "¡Hecho!",
Expand Down
2 changes: 2 additions & 0 deletions internal/locale/translations/fi_FI.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
"entry.save.title": "Tallenna tämä artikkeli",
"entry.save.completed": "Valmis!",
"entry.save.toast.completed": "Artikkeli tallennettu",
"entry.scraper.label.rss": "Näytä RSS-sisältö",
"entry.scraper.title.rss": "Hae RSS-sisältöä",
"entry.scraper.label": "Lataa",
"entry.scraper.title": "Nouda alkuperäinen sisältö",
"entry.scraper.completed": "Valmis!",
Expand Down
2 changes: 2 additions & 0 deletions internal/locale/translations/fr_FR.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
"entry.save.title": "Sauvegarder cet article",
"entry.save.completed": "Terminé !",
"entry.save.toast.completed": "Article sauvegardé",
"entry.scraper.label.rss": "Afficher le contenu RSS",
"entry.scraper.title.rss": "Obtenir le contenu RSS",
"entry.scraper.label": "Télécharger",
"entry.scraper.title": "Récupérer le contenu original",
"entry.scraper.completed": "Terminé !",
Expand Down
2 changes: 2 additions & 0 deletions internal/locale/translations/hi_IN.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
"entry.save.title": "एस लेख को सहेजे",
"entry.save.completed": "कार्य समाप्त हुआ!",
"entry.save.toast.completed": "लेख को सहेज लिया",
"entry.scraper.label.rss": "RSS सामग्री दिखाएँ",
"entry.scraper.title.rss": "RSS सामग्री प्राप्त करें",
"entry.scraper.label": "डाउनलोड",
"entry.scraper.title": "मूल विषयवस्तु लाए",
"entry.scraper.completed": "कार्य समाप्त हुआ!",
Expand Down
2 changes: 2 additions & 0 deletions internal/locale/translations/id_ID.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
"entry.save.title": "Simpan artikel ini",
"entry.save.completed": "Selesai!",
"entry.save.toast.completed": "Artikel tersimpan",
"entry.scraper.label.rss": "Tampilkan Konten RSS",
"entry.scraper.title.rss": "Dapatkan Konten RSS",
"entry.scraper.label": "Unduh",
"entry.scraper.title": "Ambil konten asli",
"entry.scraper.completed": "Selesai!",
Expand Down
2 changes: 2 additions & 0 deletions internal/locale/translations/it_IT.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
"entry.save.title": "Salva questo articolo",
"entry.save.completed": "Fatto!",
"entry.save.toast.completed": "Articolo salvato",
"entry.scraper.label.rss": "Mostra contenuto RSS",
"entry.scraper.title.rss": "Ottieni contenuto RSS",
"entry.scraper.label": "Scarica",
"entry.scraper.title": "Scarica il contenuto integrale",
"entry.scraper.completed": "Fatto!",
Expand Down
2 changes: 2 additions & 0 deletions internal/locale/translations/ja_JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
"entry.save.title": "この記事を保存",
"entry.save.completed": "完了!",
"entry.save.toast.completed": "記事は保存されました",
"entry.scraper.label.rss": "RSS コンテンツを表示",
"entry.scraper.title.rss": "RSS コンテンツを取得",
"entry.scraper.label": "ダウンロード",
"entry.scraper.title": "オリジナルの内容を取得",
"entry.scraper.completed": "完了!",
Expand Down
2 changes: 2 additions & 0 deletions internal/locale/translations/nl_NL.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
"entry.save.title": "Artikel opslaan",
"entry.save.completed": "Done!",
"entry.save.toast.completed": "Artikel opgeslagen",
"entry.scraper.label.rss": "Toon RSS-content",
"entry.scraper.title.rss": "Haal RSS-content op",
"entry.scraper.label": "Downloaden",
"entry.scraper.title": "Fetch original content",
"entry.scraper.completed": "Klaar!",
Expand Down
2 changes: 2 additions & 0 deletions internal/locale/translations/pl_PL.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
"entry.save.title": "Zapisz ten artykuł",
"entry.save.completed": "Gotowe!",
"entry.save.toast.completed": "Artykuł zapisany",
"entry.scraper.label.rss": "Pokaż treść RSS",
"entry.scraper.title.rss": "Pobierz treść RSS",
"entry.scraper.label": "Ściągnij",
"entry.scraper.title": "Pobierz oryginalną treść",
"entry.scraper.completed": "Gotowe!",
Expand Down
2 changes: 2 additions & 0 deletions internal/locale/translations/pt_BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
"entry.save.title": "Salvar esse item",
"entry.save.completed": "Feito!",
"entry.save.toast.completed": "Item guardado",
"entry.scraper.label.rss": "Mostrar conteúdo RSS",
"entry.scraper.title.rss": "Obter conteúdo RSS",
"entry.scraper.label": "Baixar",
"entry.scraper.title": "Obter conteúdo completo",
"entry.scraper.completed": "Feito!",
Expand Down
2 changes: 2 additions & 0 deletions internal/locale/translations/ru_RU.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
"entry.save.title": "Сохранить эту статью",
"entry.save.completed": "Готово!",
"entry.save.toast.completed": "Статья сохранена",
"entry.scraper.label.rss": "Показать содержимое RSS",
"entry.scraper.title.rss": "Получить содержимое RSS",
"entry.scraper.label": "Скачать",
"entry.scraper.title": "Извлечь оригинальное содержимое",
"entry.scraper.completed": "Готово!",
Expand Down
2 changes: 2 additions & 0 deletions internal/locale/translations/tr_TR.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
"entry.save.title": "Bu makaleyi kaydet",
"entry.save.completed": "Bitti!",
"entry.save.toast.completed": "Makale kaydedildi",
"entry.scraper.label.rss": "RSS İçeriğini Göster",
"entry.scraper.title.rss": "RSS İçeriğini Al",
"entry.scraper.label": "İndir",
"entry.scraper.title": "Orijinal içeriği çek",
"entry.scraper.completed": "Bitti!",
Expand Down
2 changes: 2 additions & 0 deletions internal/locale/translations/uk_UA.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@
"entry.state.saving": "Зберігаю...",
"entry.state.loading": "Завантаження...",
"entry.save.label": "Зберегти",
"entry.scraper.label.rss": "Показати вміст RSS",
"entry.save.title": "Зберегти цю статтю",
"entry.scraper.title.rss": "Отримати вміст RSS",
"entry.save.completed": "Готово!",
"entry.save.toast.completed": "Стаття збережена",
"entry.scraper.label": "Завантажити",
Expand Down
2 changes: 2 additions & 0 deletions internal/locale/translations/zh_CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
"entry.save.title": "保存这篇文章",
"entry.save.completed": "完成",
"entry.save.toast.completed": "已保存文章",
"entry.scraper.label.rss": "显示 RSS 内容",
"entry.scraper.title.rss": "获取 RSS 内容",
"entry.scraper.label": "抓取全文",
"entry.scraper.title": "抓取全文内容",
"entry.scraper.completed": "抓取完成",
Expand Down
2 changes: 2 additions & 0 deletions internal/locale/translations/zh_TW.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
"entry.save.title": "儲存這篇文章",
"entry.save.completed": "完成",
"entry.save.toast.completed": "已儲存文章",
"entry.scraper.label.rss": "顯示 RSS 內容",
"entry.scraper.title.rss": "獲取 RSS 內容",
"entry.scraper.label": "下載原文",
"entry.scraper.title": "下載原文內容",
"entry.scraper.completed": "下載完成",
Expand Down
1 change: 1 addition & 0 deletions internal/model/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type Entry struct {
CreatedAt time.Time `json:"created_at"`
ChangedAt time.Time `json:"changed_at"`
Content string `json:"content"`
WebContent string `json:"web_content,omitempty"`
Author string `json:"author"`
ShareCode string `json:"share_code"`
Starred bool `json:"starred"`
Expand Down
10 changes: 5 additions & 5 deletions internal/reader/processor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,14 @@ func ProcessFeedEntries(store *storage.Storage, feed *model.Feed, user *model.Us
)
} else if content != "" {
// We replace the entry content only if the scraper doesn't return any error.
entry.Content = content
entry.WebContent = content
}
}

rewrite.Rewriter(websiteURL, entry, feed.RewriteRules)

// The sanitizer should always run at the end of the process to make sure unsafe HTML is filtered.
entry.Content = sanitizer.Sanitize(websiteURL, entry.Content)
entry.WebContent = sanitizer.Sanitize(websiteURL, entry.Content)

updateEntryReadingTime(store, feed, entry, entryIsNew, user)
filteredEntries = append(filteredEntries, entry)
Expand Down Expand Up @@ -209,14 +209,14 @@ func ProcessEntryWebPage(feed *model.Feed, entry *model.Entry, user *model.User)
}

if content != "" {
entry.Content = content
entry.WebContent = content
if user.ShowReadingTime {
entry.ReadingTime = readingtime.EstimateReadingTime(entry.Content, user.DefaultReadingSpeed, user.CJKReadingSpeed)
entry.ReadingTime = readingtime.EstimateReadingTime(entry.WebContent, user.DefaultReadingSpeed, user.CJKReadingSpeed)
}
}

rewrite.Rewriter(websiteURL, entry, entry.Feed.RewriteRules)
entry.Content = sanitizer.Sanitize(websiteURL, entry.Content)
entry.WebContent = sanitizer.Sanitize(websiteURL, entry.WebContent)

return nil
}
Expand Down
42 changes: 21 additions & 21 deletions internal/reader/rewrite/rewriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,35 +24,35 @@ type rule struct {
func (rule rule) applyRule(entryURL string, entry *model.Entry) {
switch rule.name {
case "add_image_title":
entry.Content = addImageTitle(entryURL, entry.Content)
entry.WebContent = addImageTitle(entryURL, entry.WebContent)
case "add_mailto_subject":
entry.Content = addMailtoSubject(entryURL, entry.Content)
entry.WebContent = addMailtoSubject(entryURL, entry.WebContent)
case "add_dynamic_image":
entry.Content = addDynamicImage(entryURL, entry.Content)
entry.WebContent = addDynamicImage(entryURL, entry.WebContent)
case "add_dynamic_iframe":
entry.Content = addDynamicIframe(entryURL, entry.Content)
entry.WebContent = addDynamicIframe(entryURL, entry.WebContent)
case "add_youtube_video":
entry.Content = addYoutubeVideo(entryURL, entry.Content)
entry.WebContent = addYoutubeVideo(entryURL, entry.WebContent)
case "add_invidious_video":
entry.Content = addInvidiousVideo(entryURL, entry.Content)
entry.WebContent = addInvidiousVideo(entryURL, entry.WebContent)
case "add_youtube_video_using_invidious_player":
entry.Content = addYoutubeVideoUsingInvidiousPlayer(entryURL, entry.Content)
entry.WebContent = addYoutubeVideoUsingInvidiousPlayer(entryURL, entry.WebContent)
case "add_youtube_video_from_id":
entry.Content = addYoutubeVideoFromId(entry.Content)
entry.WebContent = addYoutubeVideoFromId(entry.WebContent)
case "add_pdf_download_link":
entry.Content = addPDFLink(entryURL, entry.Content)
entry.WebContent = addPDFLink(entryURL, entry.WebContent)
case "nl2br":
entry.Content = strings.ReplaceAll(entry.Content, "\n", "<br>")
entry.WebContent = strings.ReplaceAll(entry.WebContent, "\n", "<br>")
case "convert_text_link", "convert_text_links":
entry.Content = replaceTextLinks(entry.Content)
entry.WebContent = replaceTextLinks(entry.WebContent)
case "fix_medium_images":
entry.Content = fixMediumImages(entryURL, entry.Content)
entry.WebContent = fixMediumImages(entryURL, entry.WebContent)
case "use_noscript_figure_images":
entry.Content = useNoScriptImages(entryURL, entry.Content)
entry.WebContent = useNoScriptImages(entryURL, entry.WebContent)
case "replace":
// Format: replace("search-term"|"replace-term")
if len(rule.args) >= 2 {
entry.Content = replaceCustom(entry.Content, rule.args[0], rule.args[1])
entry.WebContent = replaceCustom(entry.WebContent, rule.args[0], rule.args[1])
} else {
slog.Warn("Cannot find search and replace terms for replace rule",
slog.Any("rule", rule),
Expand All @@ -72,29 +72,29 @@ func (rule rule) applyRule(entryURL string, entry *model.Entry) {
case "remove":
// Format: remove("#selector > .element, .another")
if len(rule.args) >= 1 {
entry.Content = removeCustom(entry.Content, rule.args[0])
entry.WebContent = removeCustom(entry.WebContent, rule.args[0])
} else {
slog.Warn("Cannot find selector for remove rule",
slog.Any("rule", rule),
slog.String("entry_url", entryURL),
)
}
case "add_castopod_episode":
entry.Content = addCastopodEpisode(entryURL, entry.Content)
entry.WebContent = addCastopodEpisode(entryURL, entry.WebContent)
case "base64_decode":
selector := "body"
if len(rule.args) >= 1 {
selector = rule.args[0]
}
entry.Content = applyFuncOnTextContent(entry.Content, selector, decodeBase64Content)
entry.WebContent = applyFuncOnTextContent(entry.WebContent, selector, decodeBase64Content)
case "add_hn_links_using_hack":
entry.Content = addHackerNewsLinksUsing(entry.Content, "hack")
entry.WebContent = addHackerNewsLinksUsing(entry.WebContent, "hack")
case "add_hn_links_using_opener":
entry.Content = addHackerNewsLinksUsing(entry.Content, "opener")
entry.WebContent = addHackerNewsLinksUsing(entry.WebContent, "opener")
case "parse_markdown":
entry.Content = parseMarkdown(entry.Content)
entry.WebContent = parseMarkdown(entry.WebContent)
case "remove_tables":
entry.Content = removeTables(entry.Content)
entry.WebContent = removeTables(entry.WebContent)
case "remove_clickbait":
entry.Title = cases.Title(language.English).String(strings.ToLower(entry.Title))
}
Expand Down
Loading

0 comments on commit 29ee5ec

Please sign in to comment.