英文:
How can I add in the URL to open docsify in dark/lightmode
问题
我有一个使用docsify制作文档的网站。现在我想根据我的网站状态在暗/亮模式之间切换文档。我在文档中没有找到任何相关内容。
是否可以向URL添加参数以启动docsify站点的暗模式?
我使用以下脚本来实现暗模式:
<script
src="//cdn.jsdelivr.net/npm/docsify-darklight-theme@latest/dist/index.min.js"
type="text/javascript">
</script>
和
<link
rel="stylesheet"
href="//cdn.jsdelivr.net/npm/docsify-darklight-theme@latest/dist/style.min.css"
title="docsify-darklight-theme"
type="text/css"
/>
英文:
I have a website that uses docsify for documentation. Now I want the documentation to open in dark/light mode depending on what state my site is in. I have not found anything in the documentation.
Is it possible to add a parameter to the URL to start the docsify site in darkmode?
I use this script for darkmode:
<script
src="//cdn.jsdelivr.net/npm/docsify-darklight-theme@latest/dist/index.min.js"
type="text/javascript">
</script>
&
<link
rel="stylesheet"
href="//cdn.jsdelivr.net/npm/docsify-darklight-theme@latest/dist/style.min.css"
title="docsify-darklight-theme"
type="text/css"
/>
答案1
得分: 0
我添加了这段代码到加载主题脚本之前的脚本部分:
const theme = new URLSearchParams(window.location.href).get('theme');
if(theme){
const setTheme = theme == "dark" ? "dark" : "light";
localStorage.setItem('DARK_LIGHT_THEME', setTheme);
}
现在我可以在我的URL中添加一个主题参数来改变文档的主题:
http://DOMAIN/docsify/#/?&theme=dark
英文:
I added this to my script section before loading the theme script:
const theme = new URLSearchParams(window.location.href).get('theme');
if(theme){
const setTheme = theme == "dark" ? "dark" : "light";
localStorage.setItem('DARK_LIGHT_THEME', setTheme);
}
Now I can add a theme parameter to my URL that changes the theme of the documentation:
http://DOMAIN/docsify/#/?&theme=dark
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论