11<script setup lang="ts">
2- import { useData } from ' vitepress'
3- import DefaultTheme from ' vitepress/theme'
4- import { nextTick , provide } from ' vue'
2+ import { useData } from " vitepress" ;
3+ import DefaultTheme from " vitepress/theme" ;
4+ import { nextTick , provide } from " vue" ;
55
6- const { isDark } = useData ()
6+ const { isDark, page } = useData ();
77
88const enableTransitions = () =>
9- ' startViewTransition' in document &&
10- window .matchMedia (' (prefers-reduced-motion: no-preference)' ).matches
9+ " startViewTransition" in document &&
10+ window .matchMedia (" (prefers-reduced-motion: no-preference)" ).matches ;
1111
12- provide (' toggle-appearance' , async ({ clientX : x , clientY : y }: MouseEvent ) => {
12+ provide (" toggle-appearance" , async ({ clientX : x , clientY : y }: MouseEvent ) => {
1313 if (! enableTransitions ()) {
14- isDark .value = ! isDark .value
15- return
14+ isDark .value = ! isDark .value ;
15+ return ;
1616 }
1717
18- console .log (' toggle-appearance' , isDark .value )
18+ console .log (" toggle-appearance" , isDark .value );
1919
2020 const clipPath = [
2121 ` circle(0px at ${x }px ${y }px) ` ,
2222 ` circle(${Math .hypot (
2323 Math .max (x , innerWidth - x ),
2424 Math .max (y , innerHeight - y )
25- )}px at ${x }px ${y }px) `
26- ]
25+ )}px at ${x }px ${y }px) ` ,
26+ ];
2727
2828 // @ts-expect-error
2929 await document .startViewTransition (async () => {
30- isDark .value = ! isDark .value
31- await nextTick ()
32- }).ready
30+ isDark .value = ! isDark .value ;
31+ await nextTick ();
32+ }).ready ;
3333
3434 document .documentElement .animate (
3535 { clipPath: isDark .value ? clipPath .reverse () : clipPath },
3636 {
3737 duration: 300 ,
38- easing: ' ease-in' ,
39- pseudoElement: ` ::view-transition-${isDark .value ? ' old' : ' new' }(root) `
38+ easing: " ease-in" ,
39+ pseudoElement: ` ::view-transition-${isDark .value ? " old" : " new" }(root) ` ,
4040 }
41- )
42- })
41+ );
42+ });
4343 </script >
4444
4545<template >
46- <DefaultTheme .Layout />
46+ <DefaultTheme .Layout >
47+ <template
48+ #doc-before
49+ v-if ="
50+ page .filePath .startsWith (' posts/' ) && page .filePath !== ' posts/index.md'
51+ "
52+ >
53+ <a class =" back" href =" /posts/" > ❮   ; 返回目录 </a >
54+ </template >
55+ </DefaultTheme .Layout >
4756</template >
4857
4958<style >
@@ -70,4 +79,18 @@ provide('toggle-appearance', async ({ clientX: x, clientY: y }: MouseEvent) => {
7079.VPSwitchAppearance .check {
7180 transform : none !important ;
7281}
73- </style >
82+
83+ .back {
84+ display : inline-block ;
85+ padding : 8px 16px ;
86+ text-decoration : none ;
87+ color : var (--vp-c-brand-1 );
88+ font-size : 0.75rem ;
89+ font-weight : 600 ;
90+ background-color : var (--vp-c-bg-soft );
91+ border-radius : 12px ;
92+ margin-bottom : 12px ;
93+ margin-top : -32px ;
94+ margin-left : -5px ;
95+ }
96+ </style >
0 commit comments