File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11const giscusPlugin = ( hook , vm ) => {
22 hook . ready ( ( ) => {
3+ // Move giscus container to content area.
34 const content = document . querySelector ( '.content' )
45 const giscusContainer = document . querySelector ( `.giscus` )
56 if ( content && giscusContainer ) {
67 content . appendChild ( giscusContainer )
78 }
9+ // Add theme toggle event.
10+ const themeToggle = document . getElementById ( 'docsify-darklight-theme' )
11+ if ( themeToggle ) {
12+ themeToggle . addEventListener ( 'click' , ( ) => toggleGiscusTheme ( themeToggle ) )
13+ toggleGiscusTheme ( themeToggle )
14+ }
815 } )
916}
1017
18+ const toggleGiscusTheme = ( toggle ) => {
19+ const iframe = document . querySelector ( '.giscus-frame' )
20+ if ( iframe ) {
21+ // Check if dark mode is enabled.
22+ const isDark = toggle . getAttribute ( 'data-link-title' ) === 'dark'
23+ const theme = isDark ? 'dark_dimmed' : 'light'
24+ // Replace `theme` parameter in iframe src.
25+ const src = iframe . getAttribute ( 'src' )
26+ const newSrc = src . replace (
27+ / t h e m e = [ ^ & ] * / ,
28+ `theme=${ theme } `
29+ )
30+ iframe . setAttribute ( 'src' , newSrc )
31+ }
32+ }
33+
1134$docsify . plugins . push ( giscusPlugin )
Original file line number Diff line number Diff line change 7272 data-reactions-enabled ="1 "
7373 data-emit-metadata ="0 "
7474 data-input-position ="bottom "
75- data-theme ="preferred_color_scheme "
75+ data-theme ="light "
7676 data-lang ="zh-CN "
7777 data-loading ="lazy "
7878 crossorigin ="anonymous "
You can’t perform that action at this time.
0 commit comments