From 1a4f90eae9c3d41c8a50eec50d3a56e3ef58d699 Mon Sep 17 00:00:00 2001 From: awesomeoxc Date: Thu, 1 Aug 2024 16:20:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20`disableCamo`=20=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E9=A1=B9=EF=BC=8C=E6=8E=A7=E5=88=B6=E6=96=87=E7=AB=A0?= =?UTF-8?q?=E4=B8=AD=E7=9A=84=E5=9B=BE=E7=89=87=E6=98=AF=E5=90=A6=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E5=88=9B=E5=BB=BA=E6=96=87=E7=AB=A0(issue)=E6=97=B6?= =?UTF-8?q?=E8=BE=93=E5=85=A5=E7=9A=84=E5=8E=9F=E5=A7=8B=E9=93=BE=E6=8E=A5?= =?UTF-8?q?=E3=80=82=20=E8=83=8C=E6=99=AF=EF=BC=9A=201.=20Gmeek=20?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E4=BA=86=20GitHub=20API=20=E5=B0=86=20markdo?= =?UTF-8?q?wn=20=E6=B8=B2=E6=9F=93=E4=B8=BA=20html=EF=BC=9B=202.=20?= =?UTF-8?q?=E8=80=8C=E5=9C=A8=E8=BF=99=E4=B8=AA=E8=BF=87=E7=A8=8B=20GitHub?= =?UTF-8?q?=20=E4=BC=9A=E4=BD=BF=E7=94=A8=E5=BC=80=E6=BA=90=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=20Camo=20=E5=B0=86=20markdown=20=E4=B8=AD=E7=9A=84?= =?UTF-8?q?=E5=9B=BE=E7=89=87=E8=BF=9B=E8=A1=8C=E6=89=98=E7=AE=A1=EF=BC=9B?= =?UTF-8?q?=203.=20Camo=20=E4=BC=9A=E4=B8=BA=E6=AF=8F=E5=B9=85=E5=9B=BE?= =?UTF-8?q?=E5=83=8F=E7=94=9F=E6=88=90=E5=BC=80=E5=A4=B4=E4=B8=BA=20https:?= =?UTF-8?q?//camo.githubusercontent.com/=20=E7=9A=84=E5=8C=BF=E5=90=8D=20U?= =?UTF-8?q?RL=20=E4=BB=A3=E7=90=86=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Github 这么做的理由是: 1. 代理这些图像将有助于保护用户的隐私:用户访问这些图片时,浏览器信息不会泄露给第三方服务; 2. Github 通过 CDN 加速图像的访问; 3. 有 CDN 可以减少因原始图片链接失效而无法正常渲染的情况; 然而如果你的图片本身托管在国内,GitHub 这么做反而会降低图片的访问速度,甚至导致无法访问(不能科学上网时)。 因此,增加一个单独的配置项,如果配置了 `"disableCamo": 1`,Gmeek 会在 GitHub 渲染网页后将图片链接简单替换为原始链接。 --- Gmeek.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Gmeek.py b/Gmeek.py index a84b275..fbd3b61 100644 --- a/Gmeek.py +++ b/Gmeek.py @@ -86,7 +86,7 @@ class GMEEK(): print("static does not exist") def defaultConfig(self): - dconfig={"singlePage":[],"startSite":"","filingNum":"","onePageListNum":15,"commentLabelColor":"#006b75","yearColorList":["#bc4c00", "#0969da", "#1f883d", "#A333D0"],"i18n":"CN","themeMode":"manual","dayTheme":"light","nightTheme":"dark","urlMode":"pinyin","script":"","style":"","head":"","indexScript":"","indexStyle":"","bottomText":"","showPostSource":1,"iconList":{},"UTC":+8,"rssSplit":"sentence","exlink":{},"needComment":1,"allHead":""} + dconfig={"singlePage":[],"startSite":"","filingNum":"","onePageListNum":15,"commentLabelColor":"#006b75","yearColorList":["#bc4c00", "#0969da", "#1f883d", "#A333D0"],"i18n":"CN","themeMode":"manual","dayTheme":"light","nightTheme":"dark","urlMode":"pinyin","script":"","style":"","head":"","indexScript":"","indexStyle":"","bottomText":"","showPostSource":1,"iconList":{},"UTC":+8,"rssSplit":"sentence","exlink":{},"needComment":1,"allHead":"","disableCamo":0} config=json.loads(open('config.json', 'r', encoding='utf-8').read()) self.blogBase={**dconfig,**config}.copy() self.blogBase["postListJson"]=json.loads('{}') @@ -159,6 +159,8 @@ class GMEEK(): return a_tag + img_tag def process_html_img_src(self, origin_html): + if self.blogBase["disableCamo"] != 1: + return origin_html # 使用正则表达式查找并替换符合条件的标签 pattern = r'(]*>)(]*data-canonical-src[^>]*>)' processed_html = re.sub(pattern, self.replace_canonical_attributes, origin_html)