rules.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. "www.qwantz.com": "add_image_title,add_mailto_subject",
  37. "xkcd.com": "add_image_title",
  38. "youtube.com": "add_youtube_video",
  39. }
  40. // GetRefererForURL returns the referer for the given URL if it exists, otherwise an empty string.
  41. func GetRefererForURL(u string) string {
  42. parsedUrl, err := url.Parse(u)
  43. if err != nil {
  44. return ""
  45. }
  46. switch parsedUrl.Hostname() {
  47. case "appinn.com":
  48. return "https://appinn.com"
  49. case "bjp.org.cn":
  50. return "https://bjp.org.cn"
  51. case "cdnfile.sspai.com":
  52. return "https://sspai.com"
  53. case "f.video.weibocdn.com":
  54. return "https://weibo.com"
  55. case "i.pximg.net":
  56. return "https://www.pixiv.net"
  57. case "img.hellogithub.com":
  58. return "https://hellogithub.com"
  59. case "moyu.im":
  60. return "https://i.jandan.net"
  61. }
  62. switch {
  63. case strings.HasSuffix(parsedUrl.Hostname(), ".cdninstagram.com"):
  64. return "https://www.instagram.com"
  65. case strings.HasSuffix(parsedUrl.Hostname(), ".moyu.im"):
  66. return "https://i.jandan.net"
  67. case strings.HasSuffix(parsedUrl.Hostname(), ".sinaimg.cn"):
  68. return "https://weibo.com"
  69. }
  70. return ""
  71. }