Closed ouxch closed 1 month ago
这个其实可以通过Gmeek-html
来实现。具体见如下链接
https://blog.meekdai.com/post/%E3%80%90Gmeek-jin-jie-%E3%80%91-wen-zhang-cha-ru-html-biao-qian.html
这个其实可以通过
Gmeek-html
来实现。具体见如下链接 https://blog.meekdai.com/post/%E3%80%90Gmeek-jin-jie-%E3%80%91-wen-zhang-cha-ru-html-biao-qian.html
谢谢👌,学习了。可以任意加 HTML 标签的话确实方便,后面加视频用得上👍。 我暂时自己 fork 了一份跑 workflow,只是单纯解决这个图片问题的话,感觉通过配置项让框架来处理更灵活一些:
通过markdown添加的图片,确实包含data-canonical-src
图片的真正地址。这个只需要通过一小段js插件就能实现,而且不会误判在code中的内容被替换。
所有文章页实现替换Camo
,在config.json中添加如下配置
"script":"<script>document.querySelectorAll('a').forEach(anchor => {const img = anchor.querySelector('img');if (img && img.hasAttribute('data-canonical-src')) {const canonicalSrc = img.getAttribute('data-canonical-src');anchor.setAttribute('href', canonicalSrc);img.setAttribute('src', canonicalSrc);img.removeAttribute('data-canonical-src');}});</script>",
单篇文章页替换Camo
,在文章页最后一行添加
<!-- ##{"script":"<script>document.querySelectorAll('a').forEach(anchor => {const img = anchor.querySelector('img');if (img && img.hasAttribute('data-canonical-src')) {const canonicalSrc = img.getAttribute('data-canonical-src');anchor.setAttribute('href', canonicalSrc);img.setAttribute('src', canonicalSrc);img.removeAttribute('data-canonical-src');}});</script>"}## -->
通过markdown添加的图片,确实包含
data-canonical-src
图片的真正地址。这个只需要通过一小段js插件就能实现,而且不会误判在code中的内容被替换。
- 所有文章页实现替换
Camo
,在config.json中添加如下配置"script":"<script>document.querySelectorAll('a').forEach(anchor => {const img = anchor.querySelector('img');if (img && img.hasAttribute('data-canonical-src')) {const canonicalSrc = img.getAttribute('data-canonical-src');anchor.setAttribute('href', canonicalSrc);img.setAttribute('src', canonicalSrc);img.removeAttribute('data-canonical-src');}});</script>",
- 单篇文章页替换
Camo
,在文章页最后一行添加<!-- ##{"script":"<script>document.querySelectorAll('a').forEach(anchor => {const img = anchor.querySelector('img');if (img && img.hasAttribute('data-canonical-src')) {const canonicalSrc = img.getAttribute('data-canonical-src');anchor.setAttribute('href', canonicalSrc);img.setAttribute('src', canonicalSrc);img.removeAttribute('data-canonical-src');}});</script>"}## -->
嗯嗯,能解决问题就行。正则确实可能误判,严谨点的话可以把 html 字符串解析一遍再做属性的处理。我想的是编译期能解决的尽量不要留到运行时,页面加载时执行的脚本能少一点是一点嘛,快速验证了一下这个思路发现可以。其实关键就是要知道 GitHub 有 Camo 重新托管图片的这个机制,解决的办法就多了。开始不知道有这个机制,直接添加附件/markdown标记/img标签都尝试了,图片链接一直是 github 的,还以为是没重新部署成功或者有缓存 bug 之类的,折腾了几遍就去搜了一下这个域名才定位到问题😂
通过markdown添加的图片,确实包含
data-canonical-src
图片的真正地址。这个只需要通过一小段js插件就能实现,而且不会误判在code中的内容被替换。
所有文章页实现替换
Camo
,在config.json中添加如下配置"script":"<script>document.querySelectorAll('a').forEach(anchor => {const img = anchor.querySelector('img');if (img && img.hasAttribute('data-canonical-src')) {const canonicalSrc = img.getAttribute('data-canonical-src');anchor.setAttribute('href', canonicalSrc);img.setAttribute('src', canonicalSrc);img.removeAttribute('data-canonical-src');}});</script>",
单篇文章页替换
Camo
,在文章页最后一行添加<!-- ##{"script":"<script>document.querySelectorAll('a').forEach(anchor => {const img = anchor.querySelector('img');if (img && img.hasAttribute('data-canonical-src')) {const canonicalSrc = img.getAttribute('data-canonical-src');anchor.setAttribute('href', canonicalSrc);img.setAttribute('src', canonicalSrc);img.removeAttribute('data-canonical-src');}});</script>"}## -->
有个问题:尖括号里面多了个单引号
谢谢,已经修改
谢谢,已经修改
看看我的新页面,咋样,目标是首页清晰明朗点,我之前用的自己的代码复制按钮,我看你后来增加复制功能了,不过之前看的时候好像还没有代码高亮?现在,目录按钮和返回顶部统一了css,看看要不要更新到你的仓库里。文章内图片增加了边框和阴影,悬停动画。
@tiengming 额,你确定你的首页改成下面这个图片这样了?
代码复制按钮上一个版本新增的功能。
@tiengming 额,你确定你的首页改成下面这个图片这样了?
代码复制按钮上一个版本新增的功能。
等你把代码高亮的功能增加了,我就舍弃我的代码复制插件了。你的图片是我改的,主要是把标签和时间放在了文章标题的下一行
@tiengming 代码高亮不是一直都有的啊? https://blog.meekdai.com/post/markdown-ce-shi-ye-mian.html#%E4%BB%A3%E7%A0%81%E9%AB%98%E4%BA%AE
@tiengming 代码高亮不是一直都有的啊? https://blog.meekdai.com/post/markdown-ce-shi-ye-mian.html#%E4%BB%A3%E7%A0%81%E9%AB%98%E4%BA%AE
好嘞,那我修改成你的代码插件
增加
disableCamo
配置项,控制文章中的图片是否使用创建文章(issue)时输入的原始链接。 背景:Github 这么做的理由是:
然而如果你的图片本身托管在国内,GitHub 这么做反而会降低图片的访问速度,甚至导致无法访问(不能科学上网时)。 因此,增加一个单独的配置项,如果配置了
"disableCamo": 1
,Gmeek 会在 GitHub 渲染网页后将图片链接简单替换为原始链接。参考: