支持medium-zoom库提供的图像放缩显示功能

This commit is contained in:
Pang 2024-04-10 15:51:05 +00:00
parent 03ee911f40
commit 4e9f0e7343
2 changed files with 13 additions and 1 deletions

View File

@ -72,7 +72,7 @@ class GMEEK():
os.mkdir(self.post_dir)
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":"","bottomText":"","showPostSource":1,"iconList":{},"UTC":+8,"rssSplit":"sentence","exlink":{}}
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":"","bottomText":"","showPostSource":1,"iconList":{},"UTC":+8,"rssSplit":"sentence","exlink":{},"useMediumZoom":1,}
config=json.loads(open('config.json', 'r', encoding='utf-8').read())
self.blogBase={**dconfig,**config}.copy()
self.blogBase["postListJson"]=json.loads('{}')
@ -138,6 +138,10 @@ class GMEEK():
post_body=re.sub(r'</math-renderer>','',post_body)
issue["script"]=issue["script"]+'<script>MathJax = {tex: {inlineMath: [["$", "$"]]}};</script><script async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>'
if postBase["useMediumZoom"] == 1:
# match <a> tags containing only <img> tags regardless of newlines and remove them
post_body = re.sub(r"<a [^>]*>\s*(<img [^>]*>)\s*</a>", r"\1", post_body, flags=re.DOTALL)
postBase["postTitle"]=issue["postTitle"]
postBase["postUrl"]=self.blogBase["homeUrl"]+"/"+issue["postUrl"]
postBase["description"]=issue["description"]

View File

@ -65,6 +65,14 @@
<script>
document.getElementById("pathHome").setAttribute("d",IconList["home"]);
document.getElementById("pathIssue").setAttribute("d",IconList["github"]);
{% if blogBase['useMediumZoom']==1 -%}
// importing the medium-zoom library for <img>
let medium_zoom_script = document.createElement('script');
medium_zoom_script.src = 'https://unpkg.com/medium-zoom/dist/medium-zoom.min.js';
// only impose medium-zoom to images in the postBody
medium_zoom_script.onload = function() {mediumZoom('#postBody img');};
document.head.appendChild(medium_zoom_script);
{%- endif %}
{% if blogBase['commentNum']>0 -%}
cmButton=document.getElementById("cmButton");
span=document.createElement("span");