@@ -3,11 +3,11 @@ document.addEventListener('DOMContentLoaded', ready, false);
3
3
const THEME_PREF_STORAGE_KEY = "theme-preference" ;
4
4
const THEME_TO_ICON_CLASS = {
5
5
'dark' : 'feather-moon' ,
6
- 'light' :'feather-sun'
6
+ 'light' : 'feather-sun'
7
7
} ;
8
8
const THEME_TO_ICON_TEXT_CLASS = {
9
9
'dark' : 'Dark mode' ,
10
- 'light' :'Light mode'
10
+ 'light' : 'Light mode'
11
11
} ;
12
12
let toggleIcon = '' ;
13
13
let darkThemeCss = '' ;
@@ -24,7 +24,7 @@ function ready() {
24
24
setThemeByUserPref ( ) ;
25
25
26
26
if ( document . querySelector ( 'main#content > .container' ) !== null &&
27
- document . querySelector ( 'main#content > .container' ) . classList . contains ( 'post' ) ) {
27
+ document . querySelector ( 'main#content > .container' ) . classList . contains ( 'post' ) ) {
28
28
if ( document . getElementById ( 'TableOfContents' ) !== null ) {
29
29
fixTocItemsIndent ( ) ;
30
30
createScrollSpy ( ) ;
@@ -38,6 +38,26 @@ function ready() {
38
38
// Do the injection
39
39
SVGInjector ( svgsToInject ) ;
40
40
41
+ const observer = new MutationObserver ( ( ) => {
42
+ normalizeSvgPaths ( ) ;
43
+ } ) ;
44
+
45
+ observer . observe ( document . body , { childList : true , subtree : true } ) ;
46
+
47
+ function normalizeSvgPaths ( ) {
48
+ document . querySelectorAll ( '.nav-link a .svg-inject' ) . forEach ( path => {
49
+ const bbox = path . getBBox ( ) ;
50
+ const scaleX = 20 / bbox . width ;
51
+ const scaleY = 20 / bbox . height ;
52
+ const scale = Math . min ( scaleX , scaleY ) ;
53
+
54
+ path . setAttribute ( 'transform' , `scale(${ scale } ) translate(${ - bbox . x } , ${ - bbox . y } )` ) ;
55
+ path . setAttribute ( 'stroke' , 'currentColor' ) ;
56
+ path . setAttribute ( 'stroke-width' , '1' ) ;
57
+ path . setAttribute ( 'fill' , 'transparent' ) ;
58
+ } ) ;
59
+ }
60
+
41
61
document . getElementById ( 'hamburger-menu-toggle' ) . addEventListener ( 'click' , ( ) => {
42
62
const hamburgerMenu = document . getElementsByClassName ( 'nav-hamburger-list' ) [ 0 ]
43
63
const hamburgerMenuToggleTarget = document . getElementById ( "hamburger-menu-toggle-target" )
@@ -62,22 +82,22 @@ window.addEventListener('scroll', () => {
62
82
63
83
function fixTocItemsIndent ( ) {
64
84
document . querySelectorAll ( '#TableOfContents a' ) . forEach ( $tocItem => {
65
- const itemId = $tocItem . getAttribute ( "href" ) . substring ( 1 )
66
- $tocItem . classList . add ( HEADING_TO_TOC_CLASS [ document . getElementById ( itemId ) . tagName ] ) ;
85
+ const itemId = $tocItem . getAttribute ( "href" ) . substring ( 1 )
86
+ $tocItem . classList . add ( HEADING_TO_TOC_CLASS [ document . getElementById ( itemId ) . tagName ] ) ;
67
87
} ) ;
68
88
}
69
89
70
90
function createScrollSpy ( ) {
71
91
var elements = document . querySelectorAll ( '#toc a' ) ;
72
- document . addEventListener ( 'scroll' , function ( ) {
73
- elements . forEach ( function ( element ) {
74
- const boundingRect = document . getElementById ( element . getAttribute ( 'href' ) . substring ( 1 ) ) . getBoundingClientRect ( ) ;
75
- if ( boundingRect . top <= 55 && boundingRect . bottom >= 0 ) {
76
- elements . forEach ( function ( elem ) {
77
- elem . classList . remove ( 'active' ) ;
78
- } ) ;
79
- element . classList . add ( 'active' ) ;
80
- }
92
+ document . addEventListener ( 'scroll' , function ( ) {
93
+ elements . forEach ( function ( element ) {
94
+ const boundingRect = document . getElementById ( element . getAttribute ( 'href' ) . substring ( 1 ) ) . getBoundingClientRect ( ) ;
95
+ if ( boundingRect . top <= 55 && boundingRect . bottom >= 0 ) {
96
+ elements . forEach ( function ( elem ) {
97
+ elem . classList . remove ( 'active' ) ;
98
+ } ) ;
99
+ element . classList . add ( 'active' ) ;
100
+ }
81
101
} ) ;
82
102
} ) ;
83
103
}
@@ -97,10 +117,10 @@ function toggleHeaderShadow(scrollY) {
97
117
function setThemeByUserPref ( ) {
98
118
darkThemeCss = document . getElementById ( "dark-theme" ) ;
99
119
const savedTheme = localStorage . getItem ( THEME_PREF_STORAGE_KEY ) ||
100
- ( window . matchMedia ( '(prefers-color-scheme: dark)' ) . matches ? 'dark' : 'light' ) ;
120
+ ( window . matchMedia ( '(prefers-color-scheme: dark)' ) . matches ? 'dark' : 'light' ) ;
101
121
const darkThemeToggles = document . querySelectorAll ( '.dark-theme-toggle' ) ;
102
122
setTheme ( savedTheme , darkThemeToggles ) ;
103
- darkThemeToggles . forEach ( el => el . addEventListener ( 'click' , toggleTheme , { capture : true } ) )
123
+ darkThemeToggles . forEach ( el => el . addEventListener ( 'click' , toggleTheme , { capture : true } ) )
104
124
}
105
125
106
126
function toggleTheme ( event ) {
0 commit comments