Skip to content

Commit 210903a

Browse files
committed
Fix theme flashing and add dark mode support for SVG figures
- Apply theme immediately in <head> before page render to prevent flash - Add CSS filter for SVG figures in /assets/figures/ to invert colors in dark mode
1 parent 69c0b23 commit 210903a

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

blogs/_includes/head-custom.html

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
<!-- 立即应用主题,防止闪烁 -->
2+
<script>
3+
(function() {
4+
var theme = localStorage.getItem('theme') || 'dark';
5+
document.documentElement.setAttribute('data-theme', theme);
6+
})();
7+
</script>
8+
19
{% include mathjax.html %}
210

311
<!-- Mermaid 图表支持 -->
@@ -296,6 +304,20 @@
296304
[data-theme="light"] .tikz-container svg {
297305
filter: none;
298306
}
307+
308+
/* 本地编译的 SVG 图片深色模式适配 */
309+
img[src*="/assets/figures/"] {
310+
filter: invert(1) hue-rotate(180deg);
311+
max-width: 100%;
312+
height: auto;
313+
display: block;
314+
margin: 1em auto;
315+
background: transparent;
316+
}
317+
318+
[data-theme="light"] img[src*="/assets/figures/"] {
319+
filter: none;
320+
}
299321
</style>
300322

301323
<script>

0 commit comments

Comments
 (0)