|
1 | 1 | --- |
2 | 2 | import type { MarkdownHeading } from "astro"; |
3 | | -import { widgetManager } from "@/utils/widget-manager"; |
4 | 3 | import Announcement from "@/components/widget/Announcement.astro"; |
| 4 | +import Calendar from "@/components/widget/Calendar.astro"; |
5 | 5 | import Categories from "@/components/widget/Categories.astro"; |
| 6 | +import MusicPlayer from "@/components/widget/MusicPlayer.svelte"; |
6 | 7 | import Profile from "@/components/widget/Profile.astro"; |
| 8 | +import SiteStats from "@/components/widget/SiteStats.astro"; |
7 | 9 | import Tags from "@/components/widget/Tags.astro"; |
8 | 10 | import TOC from "@/components/widget/TOC.astro"; |
9 | | -import MusicPlayer from "@/components/widget/MusicPlayer.svelte"; |
10 | | -import SiteStats from "@/components/widget/SiteStats.astro"; |
11 | | -import Calendar from "@/components/widget/Calendar.astro"; |
| 11 | +import { widgetManager } from "@/utils/widget-manager"; |
12 | 12 |
|
13 | 13 | interface Props { |
14 | | - class?: string; |
15 | | - headings?: MarkdownHeading[]; |
| 14 | + class?: string; |
| 15 | + headings?: MarkdownHeading[]; |
16 | 16 | } |
17 | 17 |
|
18 | 18 | const { class: className, headings } = Astro.props; |
19 | 19 |
|
20 | 20 | // 获取右侧边栏的组件列表 |
21 | 21 | const topComponents = widgetManager.getComponentsByPosition("top", "right"); |
22 | | -const stickyComponents = widgetManager.getComponentsByPosition("sticky", "right"); |
| 22 | +const stickyComponents = widgetManager.getComponentsByPosition( |
| 23 | + "sticky", |
| 24 | + "right", |
| 25 | +); |
23 | 26 |
|
24 | 27 | // 组件映射表 |
25 | 28 | const componentMap = { |
26 | | - profile: Profile, |
27 | | - announcement: Announcement, |
28 | | - categories: Categories, |
29 | | - tags: Tags, |
30 | | - toc: TOC, |
31 | | - "music-player": MusicPlayer, |
32 | | - "site-stats": SiteStats, |
33 | | - calendar: Calendar, |
| 29 | + profile: Profile, |
| 30 | + announcement: Announcement, |
| 31 | + categories: Categories, |
| 32 | + tags: Tags, |
| 33 | + toc: TOC, |
| 34 | + "music-player": MusicPlayer, |
| 35 | + "site-stats": SiteStats, |
| 36 | + calendar: Calendar, |
34 | 37 | }; |
35 | 38 |
|
36 | 39 | // 渲染组件的辅助函数 |
37 | 40 | function renderComponent(component: any, index: number, _components: any[]) { |
38 | | - const ComponentToRender = |
39 | | - componentMap[component.type as keyof typeof componentMap]; |
40 | | - if (!ComponentToRender) return null; |
| 41 | + const ComponentToRender = |
| 42 | + componentMap[component.type as keyof typeof componentMap]; |
| 43 | + if (!ComponentToRender) return null; |
41 | 44 |
|
42 | | - const componentClass = widgetManager.getComponentClass(component, index); |
43 | | - const componentStyle = widgetManager.getComponentStyle(component, index); |
| 45 | + const componentClass = widgetManager.getComponentClass(component, index); |
| 46 | + const componentStyle = widgetManager.getComponentStyle(component, index); |
44 | 47 |
|
45 | | - return { |
46 | | - Component: ComponentToRender, |
47 | | - props: { |
48 | | - class: componentClass, |
49 | | - style: componentStyle, |
50 | | - headings: component.type === "toc" ? headings : undefined, |
51 | | - ...component.customProps, |
52 | | - }, |
53 | | - }; |
| 48 | + return { |
| 49 | + Component: ComponentToRender, |
| 50 | + props: { |
| 51 | + class: componentClass, |
| 52 | + style: componentStyle, |
| 53 | + headings: component.type === "toc" ? headings : undefined, |
| 54 | + ...component.customProps, |
| 55 | + }, |
| 56 | + }; |
54 | 57 | } |
55 | 58 | --- |
56 | 59 |
|
@@ -129,8 +132,8 @@ function renderComponent(component: any, index: number, _components: any[]) { |
129 | 132 | window.addEventListener('resize', () => this.updateResponsiveDisplay()); |
130 | 133 |
|
131 | 134 | // 监听SWUP内容替换事件 |
132 | | - if (typeof window !== 'undefined' && window.swup) { |
133 | | - window.swup.hooks.on('content:replace', () => { |
| 135 | + if (typeof window !== 'undefined' && (window as any).swup) { |
| 136 | + (window as any).swup.hooks.on('content:replace', () => { |
134 | 137 | // 延迟执行以确保DOM已更新 |
135 | 138 | setTimeout(() => { |
136 | 139 | this.updateResponsiveDisplay(); |
|
0 commit comments