通过themeMode配置主题模式
目前默认为manual,另外可选跟随系统auto,和固定主题fix
This commit is contained in:
parent
5cebb6fd72
commit
6e8e04c634
2
Gmeek.py
2
Gmeek.py
@ -71,7 +71,7 @@ class GMEEK():
|
|||||||
os.mkdir(self.post_dir)
|
os.mkdir(self.post_dir)
|
||||||
|
|
||||||
def defaultConfig(self):
|
def defaultConfig(self):
|
||||||
dconfig={"singlePage":[],"startSite":"","filingNum":"","onePageListNum":15,"commentLabelColor":"#006b75","yearColorList":["#bc4c00", "#0969da", "#1f883d", "#A333D0"],"i18n":"CN","dayTheme":"light","nightTheme":"dark","urlMode":"pinyin","script":"","style":"","bottomText":"","showPostSource":1,"iconList":{},"UTC":+8,"rssSplit":"sentence"}
|
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"}
|
||||||
config=json.loads(open('config.json', 'r', encoding='utf-8').read())
|
config=json.loads(open('config.json', 'r', encoding='utf-8').read())
|
||||||
self.blogBase={**dconfig,**config}.copy()
|
self.blogBase={**dconfig,**config}.copy()
|
||||||
self.blogBase["postListJson"]=json.loads('{}')
|
self.blogBase["postListJson"]=json.loads('{}')
|
||||||
|
|||||||
@ -1,16 +1,18 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html data-color-mode="light" data-dark-theme="{{ blogBase['nightTheme'] }}" data-light-theme="{{ blogBase['dayTheme'] }}" lang={% if blogBase['i18n']=='CN' %}"zh-CN"{% elif blogBase['i18n']=='RU' %}"ru"{% else -%}"en"{%- endif -%}>
|
<html {%- if blogBase['themeMode']=='auto' -%}data-color-mode="auto"{%- else -%}data-color-mode="light"{%- endif -%} data-dark-theme="{{ blogBase['nightTheme'] }}" data-light-theme="{{ blogBase['dayTheme'] }}" lang={% if blogBase['i18n']=='CN' %}"zh-CN"{% elif blogBase['i18n']=='RU' %}"ru"{% else -%}"en"{%- endif -%}>
|
||||||
<head>
|
<head>
|
||||||
<meta content="text/html; charset=utf-8" http-equiv="content-type" />
|
<meta content="text/html; charset=utf-8" http-equiv="content-type" />
|
||||||
<meta name="viewport" content="width=device-width,initial-scale=1.0">
|
<meta name="viewport" content="width=device-width,initial-scale=1.0">
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||||
<link href="//cdn.staticfile.net/Primer/21.0.7/primer.css" rel="stylesheet" />
|
<link href="//cdn.staticfile.net/Primer/21.0.7/primer.css" rel="stylesheet" />
|
||||||
<link rel="icon" href="{{ blogBase['faviconUrl'] }}">
|
<link rel="icon" href="{{ blogBase['faviconUrl'] }}">
|
||||||
|
{%- if blogBase['themeMode']=='manual' -%}
|
||||||
<script>
|
<script>
|
||||||
if(localStorage.getItem("meek_theme")==null){}
|
if(localStorage.getItem("meek_theme")==null){}
|
||||||
else if(localStorage.getItem("meek_theme")=="dark"){document.getElementsByTagName("html")[0].attributes.getNamedItem("data-color-mode").value="dark";}
|
else if(localStorage.getItem("meek_theme")=="dark"){document.getElementsByTagName("html")[0].attributes.getNamedItem("data-color-mode").value="dark";}
|
||||||
else if(localStorage.getItem("meek_theme")=="light"){document.getElementsByTagName("html")[0].attributes.getNamedItem("data-color-mode").value="light";}
|
else if(localStorage.getItem("meek_theme")=="light"){document.getElementsByTagName("html")[0].attributes.getNamedItem("data-color-mode").value="light";}
|
||||||
</script>
|
</script>
|
||||||
|
{%- endif -%}
|
||||||
{% block head %}{% endblock %}
|
{% block head %}{% endblock %}
|
||||||
</head>
|
</head>
|
||||||
<style>
|
<style>
|
||||||
@ -29,6 +31,7 @@ body{box-sizing: border-box;min-width: 200px;max-width: 900px;margin: 20px auto;
|
|||||||
<script>
|
<script>
|
||||||
var IconList={{ IconList }};
|
var IconList={{ IconList }};
|
||||||
var utterancesLoad=0;
|
var utterancesLoad=0;
|
||||||
|
{%- if blogBase['themeMode']=='manual' -%}
|
||||||
if(localStorage.getItem("meek_theme")==null){localStorage.setItem("meek_theme","light");changeLight();}
|
if(localStorage.getItem("meek_theme")==null){localStorage.setItem("meek_theme","light");changeLight();}
|
||||||
else if(localStorage.getItem("meek_theme")=="dark"){changeDark();}
|
else if(localStorage.getItem("meek_theme")=="dark"){changeDark();}
|
||||||
else if(localStorage.getItem("meek_theme")=="light"){changeLight();}
|
else if(localStorage.getItem("meek_theme")=="light"){changeLight();}
|
||||||
@ -49,11 +52,13 @@ function modeSwitch(){
|
|||||||
if(document.getElementsByTagName("html")[0].attributes[0].value=="light"){changeDark();localStorage.setItem("meek_theme","dark");}
|
if(document.getElementsByTagName("html")[0].attributes[0].value=="light"){changeDark();localStorage.setItem("meek_theme","dark");}
|
||||||
else{changeLight();localStorage.setItem("meek_theme","light");}
|
else{changeLight();localStorage.setItem("meek_theme","light");}
|
||||||
}
|
}
|
||||||
|
|
||||||
function utterancesTheme(theme){
|
function utterancesTheme(theme){
|
||||||
const message = {type: 'set-theme',theme: theme};
|
const message = {type: 'set-theme',theme: theme};
|
||||||
const iframe = document.getElementsByClassName('utterances-frame')[0];
|
const iframe = document.getElementsByClassName('utterances-frame')[0];
|
||||||
iframe.contentWindow.postMessage(message, 'https://utteranc.es');
|
iframe.contentWindow.postMessage(message, 'https://utteranc.es');
|
||||||
}
|
}
|
||||||
|
{%- endif -%}
|
||||||
|
|
||||||
console.log("\n %c Gmeek {{ blogBase['GMEEK_VERSION'] }} %c https://github.com/Meekdai/Gmeek \n\n", "color: #fff; background-image: linear-gradient(90deg, rgb(47, 172, 178) 0%, rgb(45, 190, 96) 100%); padding:5px 1px;", "background-image: linear-gradient(90deg, rgb(45, 190, 96) 0%, rgb(255, 255, 255) 100%); padding:5px 0;");
|
console.log("\n %c Gmeek {{ blogBase['GMEEK_VERSION'] }} %c https://github.com/Meekdai/Gmeek \n\n", "color: #fff; background-image: linear-gradient(90deg, rgb(47, 172, 178) 0%, rgb(45, 190, 96) 100%); padding:5px 1px;", "background-image: linear-gradient(90deg, rgb(45, 190, 96) 0%, rgb(255, 255, 255) 100%); padding:5px 0;");
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@ -58,7 +58,7 @@
|
|||||||
<path id="pathRSS" fill-rule="evenodd"></path>
|
<path id="pathRSS" fill-rule="evenodd"></path>
|
||||||
</svg>
|
</svg>
|
||||||
</button></a>
|
</button></a>
|
||||||
<button class="btn btn-invisible circle" onclick="modeSwitch()" title="{{ i18n['switchTheme'] }}">
|
<button class="btn btn-invisible circle" onclick="modeSwitch()" title="{{ i18n['switchTheme'] }}" {%- if blogBase['themeMode']!='manual' -%}style="display:none;"{%- endif -%}>
|
||||||
<svg class="octicon" width="16" height="16" >
|
<svg class="octicon" width="16" height="16" >
|
||||||
<path id="themeSwitch" fill-rule="evenodd"></path>
|
<path id="themeSwitch" fill-rule="evenodd"></path>
|
||||||
</svg>
|
</svg>
|
||||||
|
|||||||
@ -42,7 +42,7 @@
|
|||||||
</button></a>
|
</button></a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<button class="btn btn-invisible circle" onclick="modeSwitch();" title="{{ i18n['switchTheme'] }}">
|
<button class="btn btn-invisible circle" onclick="modeSwitch();" title="{{ i18n['switchTheme'] }}" {%- if blogBase['themeMode']!='manual' -%}style="display:none;"{%- endif -%}>
|
||||||
<svg class="octicon" width="16" height="16" >
|
<svg class="octicon" width="16" height="16" >
|
||||||
<path id="themeSwitch" fill-rule="evenodd"></path>
|
<path id="themeSwitch" fill-rule="evenodd"></path>
|
||||||
</svg>
|
</svg>
|
||||||
@ -82,8 +82,14 @@ function openComments(){
|
|||||||
script.setAttribute("src","https://utteranc.es/client.js");
|
script.setAttribute("src","https://utteranc.es/client.js");
|
||||||
script.setAttribute("repo","{{ blogBase['repoName'] }}");
|
script.setAttribute("repo","{{ blogBase['repoName'] }}");
|
||||||
script.setAttribute("issue-term","title");
|
script.setAttribute("issue-term","title");
|
||||||
|
{%- if blogBase['themeMode']=='manual' -%}
|
||||||
if(localStorage.getItem("meek_theme")=="dark"){script.setAttribute("theme","dark-blue");}
|
if(localStorage.getItem("meek_theme")=="dark"){script.setAttribute("theme","dark-blue");}
|
||||||
else{script.setAttribute("theme","github-light");}
|
else{script.setAttribute("theme","github-light");}
|
||||||
|
{%- elif blogBase['themeMode']=='fix' -%}
|
||||||
|
script.setAttribute("theme","{{ blogBase['nightTheme'] }}");
|
||||||
|
{%- else -%}
|
||||||
|
script.setAttribute("theme","preferred-color-scheme");
|
||||||
|
{%- endif -%}
|
||||||
script.setAttribute("crossorigin","anonymous");
|
script.setAttribute("crossorigin","anonymous");
|
||||||
script.setAttribute("async","");
|
script.setAttribute("async","");
|
||||||
cm.appendChild(script);
|
cm.appendChild(script);
|
||||||
@ -102,7 +108,6 @@ function iFrameLoading(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
@ -44,7 +44,7 @@
|
|||||||
<path id="pathHome" fill-rule="evenodd"></path>
|
<path id="pathHome" fill-rule="evenodd"></path>
|
||||||
</svg>
|
</svg>
|
||||||
</button></a>
|
</button></a>
|
||||||
<button class="btn btn-invisible circle" onclick="modeSwitch()" title="{{ i18n['switchTheme'] }}">
|
<button class="btn btn-invisible circle" onclick="modeSwitch()" title="{{ i18n['switchTheme'] }}" {%- if blogBase['themeMode']!='manual' -%}style="display:none;"{%- endif -%}>
|
||||||
<svg class="octicon" width="16" height="16" >
|
<svg class="octicon" width="16" height="16" >
|
||||||
<path id="themeSwitch" fill-rule="evenodd"></path>
|
<path id="themeSwitch" fill-rule="evenodd"></path>
|
||||||
</svg>
|
</svg>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user