rules.go 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
  2. // SPDX-License-Identifier: Apache-2.0
  3. package rewrite // import "miniflux.app/v2/internal/reader/rewrite"
  4. import (
  5. "net/url"
  6. "strings"
  7. )
  8. // List of predefined rewrite rules (alphabetically sorted)
  9. // Available rules: "add_image_title", "add_youtube_video"
  10. // domain => rule name
  11. var predefinedRules = map[string]string{
  12. "abstrusegoose.com": "add_image_title",
  13. "amazingsuperpowers.com": "add_image_title",
  14. "blog.cloudflare.com": `add_image_title,remove("figure.kg-image-card figure.kg-image + img")`,
  15. "cowbirdsinlove.com": "add_image_title",
  16. "drawingboardcomic.com": "add_image_title",
  17. "exocomics.com": "add_image_title",
  18. "framatube.org": "nl2br,convert_text_link",
  19. "happletea.com": "add_image_title",
  20. "ilpost.it": `remove(".art_tag, #audioPlayerArticle, .author-container, .caption, .ilpostShare, .lastRecents, #mc_embed_signup, .outbrain_inread, p:has(.leggi-anche), .youtube-overlay")`,
  21. "imogenquest.net": "add_image_title",
  22. "lukesurl.com": "add_image_title",
  23. "medium.com": "fix_medium_images",
  24. "mercworks.net": "add_image_title",
  25. "monkeyuser.com": "add_image_title",
  26. "mrlovenstein.com": "add_image_title",
  27. "nedroid.com": "add_image_title",
  28. "oglaf.com": `replace("media.oglaf.com/story/tt(.+).gif"|"media.oglaf.com/comic/$1.jpg"),add_image_title`,
  29. "optipess.com": "add_image_title",
  30. "peebleslab.com": "add_image_title",
  31. "quantamagazine.org": `add_youtube_video_from_id, remove("h6:not(.byline,.post__title__kicker), #comments, .next-post__content, .footer__section, figure .outer--content, script")`,
  32. "sentfromthemoon.com": "add_image_title",
  33. "thedoghousediaries.com": "add_image_title",
  34. "theverge.com": `add_dynamic_image, remove("div.duet--recirculation--related-list, .hidden")`,
  35. "treelobsters.com": "add_image_title",
  36. "webtoons.com": `add_dynamic_image,replace("webtoon"|"swebtoon")`,
  37. "www.qwantz.com": "add_image_title,add_mailto_subject",
  38. "xkcd.com": "add_image_title",
  39. "youtube.com": "add_youtube_video",
  40. }
  41. // GetRefererForURL returns the referer for the given URL if it exists, otherwise an empty string.
  42. func GetRefererForURL(u string) string {
  43. parsedUrl, err := url.Parse(u)
  44. if err != nil {
  45. return ""
  46. }
  47. switch parsedUrl.Hostname() {
  48. case "i.pximg.net":
  49. return "https://www.pixiv.net"
  50. case "sp1.piokok.com":
  51. return "https://sp1.piokok.com"
  52. case "cdnfile.sspai.com":
  53. return "https://sspai.com"
  54. case "f.video.weibocdn.com":
  55. return "https://weibo.com"
  56. case "img.hellogithub.com":
  57. return "https://hellogithub.com"
  58. }
  59. switch {
  60. case strings.HasSuffix(parsedUrl.Hostname(), ".sinaimg.cn"):
  61. return "https://weibo.com"
  62. case strings.HasSuffix(parsedUrl.Hostname(), ".cdninstagram.com"):
  63. return "https://www.instagram.com"
  64. }
  65. return ""
  66. }