Skip to content

Commit

Permalink
switch rewriter to web_content & fix duplicated shared entry content
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Yrovas committed Aug 4, 2023
1 parent 07f6f5c commit 739e6e2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 30 deletions.
38 changes: 19 additions & 19 deletions reader/rewrite/rewriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,55 +61,55 @@ func parseRules(rulesText string) (rules []rule) {
func applyRule(entryURL string, entry *model.Entry, rule rule) {
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_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 = replaceLineFeeds(entry.Content)
entry.WebContent = replaceLineFeeds(entry.WebContent)
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 {
logger.Debug("[Rewrite] Cannot find search and replace terms for replace rule %s", rule)
}
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 {
logger.Debug("[Rewrite] Cannot find selector for remove rule %s", rule)
}
case "add_castopod_episode":
entry.Content = addCastopodEpisode(entryURL, entry.Content)
entry.WebContent = addCastopodEpisode(entryURL, entry.WebContent)
case "base64_decode":
if len(rule.args) >= 1 {
entry.Content = applyFuncOnTextContent(entry.Content, rule.args[0], decodeBase64Content)
entry.WebContent = applyFuncOnTextContent(entry.WebContent, rule.args[0], decodeBase64Content)
} else {
entry.Content = applyFuncOnTextContent(entry.Content, "body", decodeBase64Content)
entry.WebContent = applyFuncOnTextContent(entry.WebContent, "body", decodeBase64Content)
}
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 = removeClickbait(entry.Title)
}
Expand Down
21 changes: 10 additions & 11 deletions template/templates/views/entry.html
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ <h1 dir="auto">
{{ noescape (proxyFilter .entry.Content) }}
{{ end }}
{{ else }}
{{ noescape .entry.Content }}
{{ if .entry.WebContent }}
{{ noescape .entry.WebContent }}
{{ else }}
Expand All @@ -218,11 +217,11 @@ <h1 dir="auto">
data-last-position="{{ .MediaProgression }}"
data-save-url="{{ route "saveEnclosureProgression" "enclosureID" .ID }}"
>
{{ if (and $.user (mustBeProxyfied "audio")) }}
<source src="{{ proxyURL .URL }}" type="{{ .Html5MimeType }}">
{{ else }}
<source src="{{ .URL | safeURL }}" type="{{ .Html5MimeType }}">
{{ end }}
{{ if (and $.user (mustBeProxyfied "audio")) }}
<source src="{{ proxyURL .URL }}" type="{{ .Html5MimeType }}">
{{ else }}
<source src="{{ .URL | safeURL }}" type="{{ .Html5MimeType }}">
{{ end }}
</audio>
</div>
{{ else if hasPrefix .MimeType "video/" }}
Expand All @@ -231,11 +230,11 @@ <h1 dir="auto">
data-last-position="{{ .MediaProgression }}"
data-save-url="{{ route "saveEnclosureProgression" "enclosureID" .ID }}"
>
{{ if (and $.user (mustBeProxyfied "video")) }}
<source src="{{ proxyURL .URL }}" type="{{ .Html5MimeType }}">
{{ else }}
<source src="{{ .URL | safeURL }}" type="{{ .Html5MimeType }}">
{{ end }}
{{ if (and $.user (mustBeProxyfied "video")) }}
<source src="{{ proxyURL .URL }}" type="{{ .Html5MimeType }}">
{{ else }}
<source src="{{ .URL | safeURL }}" type="{{ .Html5MimeType }}">
{{ end }}
</video>
</div>
{{ else if hasPrefix .MimeType "image/" }}
Expand Down

0 comments on commit 739e6e2

Please sign in to comment.