Skip to content

Commit 8843c7c

Browse files
committed
Update
1 parent ca5efa8 commit 8843c7c

File tree

5 files changed

+43
-24
lines changed

5 files changed

+43
-24
lines changed

.vitepress/theme/index.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@ import vSetup from '../components/vSetup.vue';
33
import vPageTips from '../components/vPageTips.vue';
44
import vDisplayList from '../components/vDisplayList.vue';
55
import vScratchPaper from '../components/vScratchPaper.vue';
6-
import { EnhanceAppContext, useData, useRoute } from 'vitepress';
6+
import { EnhanceAppContext, useRoute } from 'vitepress';
77
import googleAnalysis from './scripts/googleAnalysis';
8-
import giscusTalk from 'vitepress-plugin-comment-with-giscus';
98
import vImageViewer from 'vitepress-plugin-image-viewer/lib/vImageViewer.vue';
109
import imageViewer from 'vitepress-plugin-image-viewer';
1110
import vModal from '../components/vModal.vue';
1211
import 'viewerjs/dist/viewer.min.css';
13-
// import './styles/index.scss';
1412
import 'virtual:uno.css';
1513
import '../../package/App.scss';
1614
import { theme, install } from '../../package/App';
@@ -30,17 +28,16 @@ export default {
3028
},
3129
setup() {
3230
// 获取前言和路由
33-
const { frontmatter } = useData();
3431
const route = useRoute();
3532
imageViewer(route, '.vp-doc', { toolbar: true });
36-
giscusTalk({
37-
repo: 'T-miracle/blog',
38-
repoId: 'R_kgDOJCf-FQ',
39-
categoryId: 'DIC_kwDOJCf-Fc4CUohc',
40-
mapping: 'pathname'
41-
}, {
42-
frontmatter, route
43-
});
33+
// giscusTalk({
34+
// repo: 'T-miracle/blog',
35+
// repoId: 'R_kgDOJCf-FQ',
36+
// categoryId: 'DIC_kwDOJCf-Fc4CUohc',
37+
// mapping: 'pathname'
38+
// }, {
39+
// frontmatter, route
40+
// });
4441
googleAnalysis();
4542
}
4643
};

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
"uuid": "^11.0.3",
2626
"viewerjs": "^1.11.7",
2727
"vitepress": "^1.5.0",
28-
"vitepress-plugin-comment-with-giscus": "^1.1.15",
2928
"vitepress-plugin-image-viewer": "^1.1.6",
3029
"vue": "^3.5.13"
3130
},

package/components/NanoMain/index.vue

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
class="w-full h-full"
1414
:options="scrollbarOptions"
1515
defer
16+
@os-initialized="scrollbarInitialized"
1617
>
1718
<article
1819
ref="article"
@@ -21,14 +22,18 @@
2122
style="white-space: wrap;"
2223
:style="{ padding: articlePadding }"
2324
>
24-
<Content ref="content"/>
25+
<Content/>
2526
</article>
27+
<slot name="contentAfter">
28+
<!--<NanoGiscus/>-->
29+
</slot>
2630
</OverlayScrollbarsComponent>
2731
</div>
2832
</div>
2933
</template>
3034

3135
<script setup lang="ts">
36+
// import NanoGiscus from '@NanoUI/NanoGiscus/index.vue';
3237
import 'overlayscrollbars/styles/overlayscrollbars.css';
3338
import scrollbarOptions from '../../config/scrollbarOptions';
3439
import { OverlayScrollbarsComponent } from 'overlayscrollbars-vue';
@@ -39,7 +44,7 @@
3944
4045
const { page } = useData();
4146
const route = useRoute();
42-
const scrollbars = ref<any | null>(null);
47+
const scrollbars = ref<InstanceType<typeof OverlayScrollbarsComponent> | null>(null);
4348
const article = ref<HTMLElement | null>(null);
4449
4550
// Listen for routing changes and scroll to the top
@@ -51,29 +56,36 @@
5156
immediate: true
5257
});
5358
59+
// Listen for hash changes
5460
function hashChange() {
5561
if (location.hash) {
5662
const _hashText = decodeURIComponent(location.hash.replace('#', ''));
5763
emitter.emit('scroll-to-hash', _hashText);
5864
}
5965
}
6066
67+
function scrollbarInitialized() {
68+
// console.log('scrollbarInitialized');
69+
setTimeout(() => {
70+
hashChange();
71+
}, 0);
72+
}
73+
6174
onContentUpdated(() => {
75+
// console.log('content updated');
6276
setTimeout(() => {
6377
hashChange();
64-
}, 240);
78+
}, 0);
6579
});
6680
6781
const resizeObserver = ref<ResizeObserver | null>(null);
6882
const articlePadding = ref<string>('calc(var(--base-size))');
6983
7084
onMounted(() => {
71-
setTimeout(() => {
72-
hashChange();
73-
}, 240);
85+
// console.log('mounted');
7486
// Listen for scroll-to-hash events
7587
emitter.on('scroll-to-hash', (hash: string) => {
76-
if (hash === '' || hash === null || hash === undefined) {
88+
if (!hash) {
7789
return;
7890
}
7991
const target = document.getElementById(hash);
@@ -96,13 +108,16 @@
96108
for (const entry of entries) {
97109
const { target } = entry;
98110
const { clientWidth } = target as HTMLElement;
99-
if (clientWidth < 1280) {
111+
if (clientWidth < 768) {
100112
articlePadding.value = 'calc(var(--base-size))';
101113
} else {
102114
articlePadding.value = 'calc(var(--base-size)) calc(var(--base-size) * 2)';
103115
}
104116
}
105117
});
118+
resizeObserver.value.observe(article.value!);
119+
120+
scrollbars.value?.osInstance()?.update();
106121
});
107122
108123
onUnmounted(() => {

package/type.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { DefaultTheme } from 'vitepress/types/default-theme';
2+
import type { GiscusProps } from '@giscus/vue/dist/types';
23

34
export type SidebarType = DefaultTheme.SidebarItem & { id?: string, icon?: string, items?: SidebarType[] };
45

@@ -7,4 +8,5 @@ export type ThemeConfig = DefaultTheme.Config & {
78
motto: string;
89
backgrounds?: string[];
910
aboutMePath: string;
11+
giscus?: GiscusProps;
1012
}

package/utils/drag.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Date: 2021-09-22
1+
// Drag move handler function
22
export type HandlerFnParams<T> = {
33
// x-axis moving distance
44
x: number;
@@ -27,7 +27,7 @@ export type DragOptions<T> = {
2727
// Original data
2828
originalData: T | (() => T);
2929
// Handler function
30-
handlerFn?: (pos: HandlerFnParams<T>) => void;
30+
handlerFn?: (data: HandlerFnParams<T>) => void;
3131
// Before drag function
3232
beforeFn?: () => void;
3333
// After drag function
@@ -36,6 +36,12 @@ export type DragOptions<T> = {
3636

3737
/**
3838
* Drag the element to change the width of the child element
39+
* @param options Drag options
40+
* @param options.el The element to be dragged
41+
* @param options.originalData Original data (passed to handlerFn for use)
42+
* @param options.handlerFn Handler function
43+
* @param options.beforeFn Before drag do something
44+
* @param options.afterFn After drag do something
3945
*/
4046
export function drag<T>({ el, originalData, handlerFn, beforeFn, afterFn }: DragOptions<T>) {
4147
if (!el) {
@@ -49,7 +55,7 @@ export function drag<T>({ el, originalData, handlerFn, beforeFn, afterFn }: Drag
4955
const screenWith = document.documentElement.clientWidth;
5056
const screenHeight = document.documentElement.clientHeight;
5157

52-
const _originalData = originalData instanceof Function ? originalData() : originalData;
58+
const _originalData = originalData instanceof Function ? originalData.bind(null)() : originalData;
5359

5460
const dragEvent = (e: MouseEvent) => {
5561
const x = e.clientX - startX;

0 commit comments

Comments
 (0)