@jet-w/astro-blog 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-FXPGR372.js +0 -0
- package/dist/chunk-GYLSY3OJ.js +173 -0
- package/dist/config/index.d.ts +166 -0
- package/dist/config/index.js +38 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.js +59 -0
- package/dist/types/index.d.ts +75 -0
- package/dist/types/index.js +1 -0
- package/package.json +84 -0
- package/src/components/EChartsCard.vue +118 -0
- package/src/components/Mermaid.vue +73 -0
- package/src/components/about/ContentCard.astro +27 -0
- package/src/components/about/IconCard.astro +77 -0
- package/src/components/about/SocialLinks.astro +54 -0
- package/src/components/about/TagCard.astro +65 -0
- package/src/components/about/TagGroup.astro +33 -0
- package/src/components/about/TimelineCard.astro +52 -0
- package/src/components/blog/FloatingToc.vue +198 -0
- package/src/components/blog/Hero.astro +147 -0
- package/src/components/blog/NavigationTabs.vue +245 -0
- package/src/components/blog/PostCard.astro +161 -0
- package/src/components/blog/PostNavigation.astro +106 -0
- package/src/components/blog/RelatedPosts.astro +175 -0
- package/src/components/blog/TableOfContents.astro +153 -0
- package/src/components/blog/TagCloud.astro +91 -0
- package/src/components/home/FeaturedPostsSection.astro +54 -0
- package/src/components/home/QuickNavSection.astro +81 -0
- package/src/components/home/RecentPostsSection.astro +52 -0
- package/src/components/home/StatsSection.astro +44 -0
- package/src/components/layout/Footer.astro +103 -0
- package/src/components/layout/Header.astro +68 -0
- package/src/components/layout/Sidebar.astro +594 -0
- package/src/components/media/Bilibili.astro +114 -0
- package/src/components/media/Slides.astro +313 -0
- package/src/components/media/Video.astro +111 -0
- package/src/components/media/VideoPlayer.astro +89 -0
- package/src/components/media/YouTube.astro +92 -0
- package/src/components/pte/StudyCalendar.vue +1348 -0
- package/src/components/ui/Icon.astro +187 -0
- package/src/components/ui/MobileMenu.vue +201 -0
- package/src/components/ui/Pagination.astro +143 -0
- package/src/components/ui/SearchBox.vue +179 -0
- package/src/components/ui/SearchInterface.vue +409 -0
- package/src/components/ui/SidebarToggle.vue +57 -0
- package/src/components/ui/ThemeToggle.vue +90 -0
- package/src/layouts/AboutLayout.astro +18 -0
- package/src/layouts/BaseLayout.astro +362 -0
- package/src/layouts/PageLayout.astro +217 -0
- package/src/layouts/SlidesLayout.astro +320 -0
- package/src/plugins/rehype-clean-containers.mjs +24 -0
- package/src/plugins/rehype-relative-links.mjs +43 -0
- package/src/plugins/rehype-tabs.mjs +116 -0
- package/src/plugins/remark-containers.mjs +407 -0
- package/src/plugins/remark-mermaid.mjs +46 -0
- package/src/styles/global.css +870 -0
- package/src/styles/slides.css +220 -0
- package/src/utils/sidebar.ts +492 -0
- package/templates/default/astro.config.mjs +51 -0
- package/templates/default/content/pages/about.mdx +93 -0
- package/templates/default/content/pages/index.mdx +20 -0
- package/templates/default/content/posts/blog_docs/01-quick-start.md +162 -0
- package/templates/default/content/posts/blog_docs/02-frontmatter.md +277 -0
- package/templates/default/content/posts/blog_docs/03-markdown-basic.md +350 -0
- package/templates/default/content/posts/blog_docs/04-containers.md +331 -0
- package/templates/default/content/posts/blog_docs/05-code-blocks.md +388 -0
- package/templates/default/content/posts/blog_docs/06-mermaid.md +431 -0
- package/templates/default/content/posts/blog_docs/07-video.md +243 -0
- package/templates/default/content/posts/blog_docs/08-latex.md +382 -0
- package/templates/default/content/posts/blog_docs/09-icons.md +326 -0
- package/templates/default/content/posts/blog_docs/10-sidebar.md +445 -0
- package/templates/default/content/posts/blog_docs/11-config.md +334 -0
- package/templates/default/content/posts/blog_docs/12-slides.mdx +552 -0
- package/templates/default/content/posts/blog_docs/README.md +151 -0
- package/templates/default/content/slides/demo.md +146 -0
- package/templates/default/content/slides/docs/basic-demo.md +35 -0
- package/templates/default/content/slides/docs/code-demo.md +62 -0
- package/templates/default/content/slides/docs/echarts-demo.md +139 -0
- package/templates/default/content/slides/docs/fragment-demo.md +35 -0
- package/templates/default/content/slides/docs/math-demo.md +48 -0
- package/templates/default/content/slides/docs/mermaid-demo.md +105 -0
- package/templates/default/content/slides/docs/theme-demo.md +38 -0
- package/templates/default/content/slides/docs/vertical-demo.md +50 -0
- package/templates/default/package.json +31 -0
- package/templates/default/public/favicon-bak.svg +4 -0
- package/templates/default/public/images/avatar.jpg +0 -0
- package/templates/default/public/images/avatar.svg +142 -0
- package/templates/default/public/js/mermaid-container.js +402 -0
- package/templates/default/public/js/mermaid-init.js +131 -0
- package/templates/default/public/js/mermaid-render.js +98 -0
- package/templates/default/public/js/mermaid-simple.js +95 -0
- package/templates/default/public/js/tabs-init.js +86 -0
- package/templates/default/public/media/individual_portfolio/INDIVIDUAL PORTFOLIO.png +0 -0
- package/templates/default/public/slides/plugin/highlight/highlight.js +5 -0
- package/templates/default/public/slides/plugin/highlight/monokai.css +71 -0
- package/templates/default/public/slides/plugin/markdown/markdown.js +7 -0
- package/templates/default/public/slides/plugin/math/math.js +1 -0
- package/templates/default/public/slides/plugin/notes/notes.js +1 -0
- package/templates/default/public/slides/reveal.css +9 -0
- package/templates/default/public/slides/reveal.js +9 -0
- package/templates/default/public/slides/theme/beige.css +366 -0
- package/templates/default/public/slides/theme/black-contrast.css +362 -0
- package/templates/default/public/slides/theme/black.css +359 -0
- package/templates/default/public/slides/theme/blood.css +392 -0
- package/templates/default/public/slides/theme/dracula.css +385 -0
- package/templates/default/public/slides/theme/league.css +368 -0
- package/templates/default/public/slides/theme/moon.css +362 -0
- package/templates/default/public/slides/theme/night.css +360 -0
- package/templates/default/public/slides/theme/serif.css +363 -0
- package/templates/default/public/slides/theme/simple.css +362 -0
- package/templates/default/public/slides/theme/sky.css +370 -0
- package/templates/default/public/slides/theme/solarized.css +363 -0
- package/templates/default/public/slides/theme/white-contrast.css +362 -0
- package/templates/default/public/slides/theme/white.css +359 -0
- package/templates/default/public/slides/theme/white_contrast_compact_verbatim_headers.css +360 -0
- package/templates/default/public/test-complete.html +43 -0
- package/templates/default/public/test-mermaid.html +124 -0
- package/templates/default/src/config/index.ts +114 -0
- package/templates/default/src/content.config.ts +96 -0
- package/templates/default/src/pages/[...slug].astro +27 -0
- package/templates/default/src/pages/archives/[year]/[month]/page/[page].astro +176 -0
- package/templates/default/src/pages/archives/[year]/[month].astro +158 -0
- package/templates/default/src/pages/archives/index.astro +210 -0
- package/templates/default/src/pages/categories/[category]/page/[page].astro +218 -0
- package/templates/default/src/pages/categories/[category].astro +198 -0
- package/templates/default/src/pages/categories/index.astro +190 -0
- package/templates/default/src/pages/container-test.astro +79 -0
- package/templates/default/src/pages/mermaid-direct.html +78 -0
- package/templates/default/src/pages/posts/[...slug].astro +335 -0
- package/templates/default/src/pages/posts/index.astro +541 -0
- package/templates/default/src/pages/posts/page/[page].astro +146 -0
- package/templates/default/src/pages/rss.xml.ts +28 -0
- package/templates/default/src/pages/search-index.json.ts +21 -0
- package/templates/default/src/pages/search.astro +50 -0
- package/templates/default/src/pages/slides/[...slug].astro +54 -0
- package/templates/default/src/pages/slides/index.astro +135 -0
- package/templates/default/src/pages/tags/[tag]/page/[page].astro +211 -0
- package/templates/default/src/pages/tags/[tag].astro +191 -0
- package/templates/default/src/pages/tags/index.astro +167 -0
- package/templates/default/tailwind.config.mjs +78 -0
- package/templates/default/tsconfig.json +9 -0
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
/* Slides 专用样式 */
|
|
2
|
+
|
|
3
|
+
/* 返回按钮 */
|
|
4
|
+
.slides-back-btn {
|
|
5
|
+
position: fixed;
|
|
6
|
+
top: 20px;
|
|
7
|
+
left: 20px;
|
|
8
|
+
z-index: 100;
|
|
9
|
+
display: flex;
|
|
10
|
+
align-items: center;
|
|
11
|
+
justify-content: center;
|
|
12
|
+
width: 40px;
|
|
13
|
+
height: 40px;
|
|
14
|
+
background: rgba(0, 0, 0, 0.5);
|
|
15
|
+
border-radius: 50%;
|
|
16
|
+
color: white;
|
|
17
|
+
text-decoration: none;
|
|
18
|
+
opacity: 0.6;
|
|
19
|
+
transition: opacity 0.3s, transform 0.3s;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.slides-back-btn:hover {
|
|
23
|
+
opacity: 1;
|
|
24
|
+
transform: scale(1.1);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/* Reveal.js 自定义样式 */
|
|
28
|
+
.reveal {
|
|
29
|
+
font-family: 'Source Sans Pro', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/* 代码块样式增强 */
|
|
33
|
+
.reveal pre {
|
|
34
|
+
width: 100%;
|
|
35
|
+
max-width: 100%;
|
|
36
|
+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.reveal pre code {
|
|
40
|
+
max-height: 500px;
|
|
41
|
+
padding: 1em;
|
|
42
|
+
font-size: 0.9em;
|
|
43
|
+
line-height: 1.5;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/* 表格样式 */
|
|
47
|
+
.reveal table {
|
|
48
|
+
margin: 1em auto;
|
|
49
|
+
border-collapse: collapse;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.reveal table th,
|
|
53
|
+
.reveal table td {
|
|
54
|
+
padding: 0.5em 1em;
|
|
55
|
+
border: 1px solid rgba(255, 255, 255, 0.3);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.reveal table th {
|
|
59
|
+
background: rgba(255, 255, 255, 0.1);
|
|
60
|
+
font-weight: bold;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/* 列表样式 */
|
|
64
|
+
.reveal ul,
|
|
65
|
+
.reveal ol {
|
|
66
|
+
text-align: left;
|
|
67
|
+
display: inline-block;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.reveal li {
|
|
71
|
+
margin: 0.5em 0;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/* 链接样式 */
|
|
75
|
+
.reveal a {
|
|
76
|
+
text-decoration: underline;
|
|
77
|
+
text-decoration-style: dotted;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
.reveal a:hover {
|
|
81
|
+
text-decoration-style: solid;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/* 引用块样式 */
|
|
85
|
+
.reveal blockquote {
|
|
86
|
+
width: 90%;
|
|
87
|
+
padding: 1em;
|
|
88
|
+
font-style: italic;
|
|
89
|
+
background: rgba(255, 255, 255, 0.05);
|
|
90
|
+
border-left: 4px solid currentColor;
|
|
91
|
+
text-align: left;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/* 分栏布局支持 */
|
|
95
|
+
.reveal .columns {
|
|
96
|
+
display: flex;
|
|
97
|
+
gap: 2em;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
.reveal .columns > * {
|
|
101
|
+
flex: 1;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/* 幻灯片过渡动画优化 */
|
|
105
|
+
.reveal .slides section {
|
|
106
|
+
transition: all 0.4s ease;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/* 概览模式当前幻灯片高亮 */
|
|
110
|
+
.reveal.overview .slides section.present {
|
|
111
|
+
outline: 4px solid #42affa !important;
|
|
112
|
+
outline-offset: 4px;
|
|
113
|
+
box-shadow: 0 0 30px rgba(66, 175, 250, 0.6), 0 0 60px rgba(66, 175, 250, 0.3) !important;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/* 概览模式其他幻灯片变暗 */
|
|
117
|
+
.reveal.overview .slides section:not(.present) {
|
|
118
|
+
opacity: 0.6;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
.reveal.overview .slides section:not(.present):hover {
|
|
122
|
+
opacity: 0.9;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/* 进度条自定义 */
|
|
126
|
+
.reveal .progress {
|
|
127
|
+
height: 4px;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/* 控制按钮自定义 */
|
|
131
|
+
.reveal .controls {
|
|
132
|
+
bottom: 30px;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/* 演讲者备注提示 */
|
|
136
|
+
.reveal .speaker-notes-link {
|
|
137
|
+
position: fixed;
|
|
138
|
+
bottom: 20px;
|
|
139
|
+
right: 20px;
|
|
140
|
+
z-index: 100;
|
|
141
|
+
padding: 8px 16px;
|
|
142
|
+
background: rgba(0, 0, 0, 0.6);
|
|
143
|
+
color: white;
|
|
144
|
+
border-radius: 4px;
|
|
145
|
+
font-size: 12px;
|
|
146
|
+
opacity: 0.4;
|
|
147
|
+
transition: opacity 0.3s;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
.reveal .speaker-notes-link:hover {
|
|
151
|
+
opacity: 1;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/* Mermaid 图表容器 */
|
|
155
|
+
.reveal .mermaid {
|
|
156
|
+
background: rgba(255, 255, 255, 0.95);
|
|
157
|
+
padding: 1em;
|
|
158
|
+
border-radius: 8px;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/* 数学公式样式 */
|
|
162
|
+
.reveal .katex {
|
|
163
|
+
font-size: 1.1em;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
.reveal .katex-display {
|
|
167
|
+
margin: 1em 0;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/* Fragment 动画增强 */
|
|
171
|
+
.reveal .fragment.fade-in-then-out {
|
|
172
|
+
opacity: 0;
|
|
173
|
+
visibility: hidden;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
.reveal .fragment.fade-in-then-out.visible {
|
|
177
|
+
opacity: 1;
|
|
178
|
+
visibility: visible;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
.reveal .fragment.fade-in-then-out.current-fragment {
|
|
182
|
+
opacity: 1;
|
|
183
|
+
visibility: visible;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/* 高亮样式 */
|
|
187
|
+
.reveal .highlight {
|
|
188
|
+
background: linear-gradient(120deg, rgba(255, 255, 0, 0.3) 0%, rgba(255, 255, 0, 0.3) 100%);
|
|
189
|
+
padding: 0.1em 0.3em;
|
|
190
|
+
border-radius: 3px;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/* 响应式优化 */
|
|
194
|
+
@media (max-width: 768px) {
|
|
195
|
+
.slides-back-btn {
|
|
196
|
+
width: 36px;
|
|
197
|
+
height: 36px;
|
|
198
|
+
top: 10px;
|
|
199
|
+
left: 10px;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
.reveal pre code {
|
|
203
|
+
font-size: 0.7em;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
.reveal h1 {
|
|
207
|
+
font-size: 1.8em;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
.reveal h2 {
|
|
211
|
+
font-size: 1.4em;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/* 打印样式 */
|
|
216
|
+
@media print {
|
|
217
|
+
.slides-back-btn {
|
|
218
|
+
display: none;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
@@ -0,0 +1,492 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 侧边栏工具函数
|
|
3
|
+
* 处理配置解析和树形结构生成
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { CollectionEntry } from 'astro:content';
|
|
7
|
+
import type {
|
|
8
|
+
SidebarConfig,
|
|
9
|
+
SidebarGroup,
|
|
10
|
+
SidebarItem,
|
|
11
|
+
ScanConfig,
|
|
12
|
+
ManualConfig,
|
|
13
|
+
MixedConfig,
|
|
14
|
+
} from '../config/sidebar';
|
|
15
|
+
|
|
16
|
+
// 树节点类型
|
|
17
|
+
export interface TreeNode {
|
|
18
|
+
name: string;
|
|
19
|
+
slug?: string;
|
|
20
|
+
title?: string;
|
|
21
|
+
displayName?: string;
|
|
22
|
+
icon?: string;
|
|
23
|
+
badge?: string;
|
|
24
|
+
badgeType?: 'info' | 'success' | 'warning' | 'error';
|
|
25
|
+
children: TreeNode[];
|
|
26
|
+
isFolder: boolean;
|
|
27
|
+
isReadme?: boolean;
|
|
28
|
+
link?: string;
|
|
29
|
+
collapsed?: boolean;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// 处理后的侧边栏组
|
|
33
|
+
export interface ProcessedGroup {
|
|
34
|
+
type: 'tree' | 'items' | 'divider';
|
|
35
|
+
title: string;
|
|
36
|
+
icon?: string;
|
|
37
|
+
collapsed?: boolean;
|
|
38
|
+
tree?: TreeNode[];
|
|
39
|
+
items?: SidebarItem[];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* 从文章集合构建树形结构
|
|
44
|
+
*/
|
|
45
|
+
export function buildTreeFromPosts(
|
|
46
|
+
posts: CollectionEntry<'posts'>[],
|
|
47
|
+
scanPath: string = '',
|
|
48
|
+
options: {
|
|
49
|
+
maxDepth?: number;
|
|
50
|
+
exclude?: string[];
|
|
51
|
+
include?: string[];
|
|
52
|
+
sortBy?: 'name' | 'date' | 'title' | 'custom';
|
|
53
|
+
sortOrder?: 'asc' | 'desc';
|
|
54
|
+
} = {}
|
|
55
|
+
): TreeNode[] {
|
|
56
|
+
const { maxDepth, exclude = [], include = [], sortBy = 'name', sortOrder = 'asc' } = options;
|
|
57
|
+
|
|
58
|
+
// 过滤出指定路径下的文章
|
|
59
|
+
const filteredPosts = posts.filter(post => {
|
|
60
|
+
const postPath = post.id.toLowerCase();
|
|
61
|
+
const targetPath = scanPath.toLowerCase();
|
|
62
|
+
|
|
63
|
+
// 检查是否在指定路径下
|
|
64
|
+
if (targetPath && !postPath.startsWith(targetPath + '/') && postPath !== targetPath) {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// 检查排除规则
|
|
69
|
+
const pathParts = post.id.split('/');
|
|
70
|
+
for (const part of pathParts) {
|
|
71
|
+
if (exclude.some(pattern => matchPattern(part, pattern))) {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// 检查包含规则
|
|
77
|
+
if (include.length > 0) {
|
|
78
|
+
const matchesInclude = pathParts.some(part =>
|
|
79
|
+
include.some(pattern => matchPattern(part, pattern))
|
|
80
|
+
);
|
|
81
|
+
if (!matchesInclude) {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return true;
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
// 收集文件夹的 README 标题和图标
|
|
90
|
+
const folderTitles: Record<string, string> = {};
|
|
91
|
+
const folderIcons: Record<string, string> = {};
|
|
92
|
+
|
|
93
|
+
filteredPosts.forEach(post => {
|
|
94
|
+
const pathParts = post.id.split('/');
|
|
95
|
+
const fileName = pathParts[pathParts.length - 1].toLowerCase();
|
|
96
|
+
|
|
97
|
+
if (fileName === 'readme' || fileName === 'readme.md') {
|
|
98
|
+
const folderPath = pathParts.slice(0, -1).join('/');
|
|
99
|
+
if (folderPath) {
|
|
100
|
+
if (post.data.title) {
|
|
101
|
+
folderTitles[folderPath] = post.data.title;
|
|
102
|
+
}
|
|
103
|
+
if (post.data.icon) {
|
|
104
|
+
folderIcons[folderPath] = post.data.icon;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
// 构建树
|
|
111
|
+
const tree: TreeNode[] = [];
|
|
112
|
+
|
|
113
|
+
filteredPosts.forEach(post => {
|
|
114
|
+
// 移除 scanPath 前缀
|
|
115
|
+
let relativePath = post.id;
|
|
116
|
+
if (scanPath) {
|
|
117
|
+
const scanPathLower = scanPath.toLowerCase();
|
|
118
|
+
const postIdLower = post.id.toLowerCase();
|
|
119
|
+
if (postIdLower.startsWith(scanPathLower + '/')) {
|
|
120
|
+
relativePath = post.id.slice(scanPath.length + 1);
|
|
121
|
+
} else if (postIdLower === scanPathLower) {
|
|
122
|
+
relativePath = post.id.split('/').pop() || post.id;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const pathParts = relativePath.split('/');
|
|
127
|
+
|
|
128
|
+
// 检查深度限制
|
|
129
|
+
if (maxDepth !== undefined && pathParts.length > maxDepth) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
let currentLevel = tree;
|
|
134
|
+
let currentPath = scanPath;
|
|
135
|
+
|
|
136
|
+
pathParts.forEach((part, index) => {
|
|
137
|
+
const isLast = index === pathParts.length - 1;
|
|
138
|
+
const existing = currentLevel.find(n => n.name.toLowerCase() === part.toLowerCase());
|
|
139
|
+
|
|
140
|
+
currentPath = currentPath ? `${currentPath}/${part}` : part;
|
|
141
|
+
const isReadme = isLast && (part.toLowerCase() === 'readme' || part.toLowerCase() === 'readme.md');
|
|
142
|
+
|
|
143
|
+
if (existing) {
|
|
144
|
+
if (isLast) {
|
|
145
|
+
existing.slug = post.id;
|
|
146
|
+
existing.title = post.data.title;
|
|
147
|
+
existing.icon = post.data.icon;
|
|
148
|
+
existing.isReadme = isReadme;
|
|
149
|
+
} else {
|
|
150
|
+
// 更新文件夹信息
|
|
151
|
+
const folderPath = scanPath ? `${scanPath}/${pathParts.slice(0, index + 1).join('/')}` : pathParts.slice(0, index + 1).join('/');
|
|
152
|
+
if (folderTitles[folderPath]) {
|
|
153
|
+
existing.displayName = folderTitles[folderPath];
|
|
154
|
+
}
|
|
155
|
+
if (folderIcons[folderPath]) {
|
|
156
|
+
existing.icon = folderIcons[folderPath];
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
currentLevel = existing.children;
|
|
160
|
+
} else {
|
|
161
|
+
const folderPath = scanPath ? `${scanPath}/${pathParts.slice(0, index + 1).join('/')}` : pathParts.slice(0, index + 1).join('/');
|
|
162
|
+
const newNode: TreeNode = {
|
|
163
|
+
name: part,
|
|
164
|
+
slug: isLast ? post.id : undefined,
|
|
165
|
+
title: isLast ? post.data.title : undefined,
|
|
166
|
+
displayName: isLast ? post.data.title : folderTitles[folderPath],
|
|
167
|
+
icon: isLast ? post.data.icon : folderIcons[folderPath],
|
|
168
|
+
children: [],
|
|
169
|
+
isFolder: !isLast,
|
|
170
|
+
isReadme: isReadme,
|
|
171
|
+
};
|
|
172
|
+
currentLevel.push(newNode);
|
|
173
|
+
currentLevel = newNode.children;
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
// 排序并过滤 README
|
|
179
|
+
return sortTree(tree, sortBy, sortOrder);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* 排序树并过滤 README 文件
|
|
184
|
+
*/
|
|
185
|
+
function sortTree(
|
|
186
|
+
nodes: TreeNode[],
|
|
187
|
+
sortBy: 'name' | 'date' | 'title' | 'custom' = 'name',
|
|
188
|
+
sortOrder: 'asc' | 'desc' = 'asc'
|
|
189
|
+
): TreeNode[] {
|
|
190
|
+
const filtered = nodes.filter(node => !node.isReadme);
|
|
191
|
+
|
|
192
|
+
const sorted = filtered.sort((a, b) => {
|
|
193
|
+
// 文件夹优先
|
|
194
|
+
if (a.isFolder && !b.isFolder) return -1;
|
|
195
|
+
if (!a.isFolder && b.isFolder) return 1;
|
|
196
|
+
|
|
197
|
+
let comparison = 0;
|
|
198
|
+
switch (sortBy) {
|
|
199
|
+
case 'title':
|
|
200
|
+
comparison = (a.displayName || a.title || a.name).localeCompare(
|
|
201
|
+
b.displayName || b.title || b.name,
|
|
202
|
+
'zh-CN'
|
|
203
|
+
);
|
|
204
|
+
break;
|
|
205
|
+
case 'name':
|
|
206
|
+
default:
|
|
207
|
+
comparison = a.name.localeCompare(b.name, 'zh-CN', { numeric: true });
|
|
208
|
+
break;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
return sortOrder === 'desc' ? -comparison : comparison;
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
return sorted.map(node => ({
|
|
215
|
+
...node,
|
|
216
|
+
children: sortTree(node.children, sortBy, sortOrder),
|
|
217
|
+
}));
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* 简单的模式匹配(支持 * 通配符)
|
|
222
|
+
*/
|
|
223
|
+
function matchPattern(str: string, pattern: string): boolean {
|
|
224
|
+
if (pattern === '*') return true;
|
|
225
|
+
if (pattern.includes('*')) {
|
|
226
|
+
const regex = new RegExp('^' + pattern.replace(/\*/g, '.*') + '$', 'i');
|
|
227
|
+
return regex.test(str);
|
|
228
|
+
}
|
|
229
|
+
return str.toLowerCase() === pattern.toLowerCase();
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* 路径 glob 模式匹配
|
|
234
|
+
* 支持:
|
|
235
|
+
* - /posts/tech/** 匹配 /posts/tech 及其所有子路径
|
|
236
|
+
* - /posts/tech/* 匹配 /posts/tech 的直接子路径
|
|
237
|
+
* - /posts/tech 精确匹配
|
|
238
|
+
*/
|
|
239
|
+
export function matchPathPattern(currentPath: string, pattern: string): boolean {
|
|
240
|
+
// 规范化路径
|
|
241
|
+
const normalizedPath = currentPath.replace(/\/$/, '').toLowerCase();
|
|
242
|
+
const normalizedPattern = pattern.replace(/\/$/, '').toLowerCase();
|
|
243
|
+
|
|
244
|
+
// ** 匹配任意深度
|
|
245
|
+
if (normalizedPattern.endsWith('/**')) {
|
|
246
|
+
const basePath = normalizedPattern.slice(0, -3);
|
|
247
|
+
return normalizedPath === basePath || normalizedPath.startsWith(basePath + '/');
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// * 匹配单层
|
|
251
|
+
if (normalizedPattern.endsWith('/*')) {
|
|
252
|
+
const basePath = normalizedPattern.slice(0, -2);
|
|
253
|
+
if (normalizedPath === basePath) return true;
|
|
254
|
+
// 检查是否是直接子路径
|
|
255
|
+
if (normalizedPath.startsWith(basePath + '/')) {
|
|
256
|
+
const remaining = normalizedPath.slice(basePath.length + 1);
|
|
257
|
+
return !remaining.includes('/');
|
|
258
|
+
}
|
|
259
|
+
return false;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// 精确匹配
|
|
263
|
+
return normalizedPath === normalizedPattern;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* 检查侧边栏组是否应该在当前路径显示
|
|
268
|
+
*/
|
|
269
|
+
export function shouldShowGroup(
|
|
270
|
+
group: { showForPaths?: string[]; hideForPaths?: string[] },
|
|
271
|
+
currentPath: string
|
|
272
|
+
): boolean {
|
|
273
|
+
// 如果没有配置路径规则,默认显示
|
|
274
|
+
if (!group.showForPaths && !group.hideForPaths) {
|
|
275
|
+
return true;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// 检查隐藏规则
|
|
279
|
+
if (group.hideForPaths && group.hideForPaths.length > 0) {
|
|
280
|
+
for (const pattern of group.hideForPaths) {
|
|
281
|
+
if (matchPathPattern(currentPath, pattern)) {
|
|
282
|
+
return false;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// 检查显示规则
|
|
288
|
+
if (group.showForPaths && group.showForPaths.length > 0) {
|
|
289
|
+
for (const pattern of group.showForPaths) {
|
|
290
|
+
if (matchPathPattern(currentPath, pattern)) {
|
|
291
|
+
return true;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
// 配置了 showForPaths 但没有匹配,则不显示
|
|
295
|
+
return false;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
// 默认显示
|
|
299
|
+
return true;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* 根据当前路径过滤侧边栏组
|
|
304
|
+
*/
|
|
305
|
+
export function filterGroupsByPath(
|
|
306
|
+
groups: SidebarGroup[],
|
|
307
|
+
currentPath: string
|
|
308
|
+
): SidebarGroup[] {
|
|
309
|
+
return groups.filter(group => shouldShowGroup(group, currentPath));
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* 将手动配置的项目转换为树节点
|
|
314
|
+
*/
|
|
315
|
+
export function manualItemsToTree(items: SidebarItem[]): TreeNode[] {
|
|
316
|
+
return items.map(item => ({
|
|
317
|
+
name: item.title,
|
|
318
|
+
slug: item.slug,
|
|
319
|
+
title: item.title,
|
|
320
|
+
displayName: item.title,
|
|
321
|
+
icon: item.icon,
|
|
322
|
+
badge: item.badge,
|
|
323
|
+
badgeType: item.badgeType,
|
|
324
|
+
link: item.link,
|
|
325
|
+
children: item.children ? manualItemsToTree(item.children) : [],
|
|
326
|
+
isFolder: !!(item.children && item.children.length > 0),
|
|
327
|
+
collapsed: item.collapsed,
|
|
328
|
+
}));
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* 处理侧边栏配置,生成可渲染的数据结构
|
|
333
|
+
*/
|
|
334
|
+
export async function processSidebarConfig(
|
|
335
|
+
config: SidebarConfig,
|
|
336
|
+
posts: CollectionEntry<'posts'>[]
|
|
337
|
+
): Promise<ProcessedGroup[]> {
|
|
338
|
+
const processedGroups: ProcessedGroup[] = [];
|
|
339
|
+
|
|
340
|
+
for (const group of config.groups) {
|
|
341
|
+
const processed = await processGroup(group, posts);
|
|
342
|
+
if (processed) {
|
|
343
|
+
processedGroups.push(processed);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
return processedGroups;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* 处理单个侧边栏组
|
|
352
|
+
*/
|
|
353
|
+
async function processGroup(
|
|
354
|
+
group: SidebarGroup,
|
|
355
|
+
posts: CollectionEntry<'posts'>[]
|
|
356
|
+
): Promise<ProcessedGroup | null> {
|
|
357
|
+
switch (group.type) {
|
|
358
|
+
case 'scan': {
|
|
359
|
+
const scanConfig = group as ScanConfig;
|
|
360
|
+
const tree = buildTreeFromPosts(posts, scanConfig.scanPath, {
|
|
361
|
+
maxDepth: scanConfig.maxDepth,
|
|
362
|
+
exclude: scanConfig.exclude,
|
|
363
|
+
include: scanConfig.include,
|
|
364
|
+
sortBy: scanConfig.sortBy,
|
|
365
|
+
sortOrder: scanConfig.sortOrder,
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
return {
|
|
369
|
+
type: 'tree',
|
|
370
|
+
title: scanConfig.title,
|
|
371
|
+
icon: scanConfig.icon,
|
|
372
|
+
collapsed: scanConfig.collapsed,
|
|
373
|
+
tree,
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
case 'manual': {
|
|
378
|
+
const manualConfig = group as ManualConfig;
|
|
379
|
+
const tree = manualItemsToTree(manualConfig.items);
|
|
380
|
+
|
|
381
|
+
return {
|
|
382
|
+
type: 'tree',
|
|
383
|
+
title: manualConfig.title,
|
|
384
|
+
icon: manualConfig.icon,
|
|
385
|
+
collapsed: manualConfig.collapsed,
|
|
386
|
+
tree,
|
|
387
|
+
};
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
case 'mixed': {
|
|
391
|
+
const mixedConfig = group as MixedConfig;
|
|
392
|
+
const combinedTree: TreeNode[] = [];
|
|
393
|
+
|
|
394
|
+
for (const section of mixedConfig.sections) {
|
|
395
|
+
const processed = await processGroup(section, posts);
|
|
396
|
+
if (processed && processed.tree) {
|
|
397
|
+
// 将每个子部分作为一个文件夹节点
|
|
398
|
+
combinedTree.push({
|
|
399
|
+
name: section.title,
|
|
400
|
+
displayName: section.title,
|
|
401
|
+
icon: section.icon,
|
|
402
|
+
children: processed.tree,
|
|
403
|
+
isFolder: true,
|
|
404
|
+
collapsed: section.collapsed,
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
return {
|
|
410
|
+
type: 'tree',
|
|
411
|
+
title: mixedConfig.title,
|
|
412
|
+
icon: mixedConfig.icon,
|
|
413
|
+
collapsed: mixedConfig.collapsed,
|
|
414
|
+
tree: combinedTree,
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
case 'divider': {
|
|
419
|
+
return {
|
|
420
|
+
type: 'divider',
|
|
421
|
+
title: group.title || '',
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
default:
|
|
426
|
+
return null;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
/**
|
|
431
|
+
* 获取最新文章
|
|
432
|
+
*/
|
|
433
|
+
export function getRecentPosts(
|
|
434
|
+
posts: CollectionEntry<'posts'>[],
|
|
435
|
+
count: number = 5
|
|
436
|
+
): CollectionEntry<'posts'>[] {
|
|
437
|
+
return posts
|
|
438
|
+
.filter(p => p.data.pubDate)
|
|
439
|
+
.sort((a, b) => (b.data.pubDate?.getTime() ?? 0) - (a.data.pubDate?.getTime() ?? 0))
|
|
440
|
+
.slice(0, count);
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
/**
|
|
444
|
+
* 获取热门标签
|
|
445
|
+
*/
|
|
446
|
+
export function getPopularTags(
|
|
447
|
+
posts: CollectionEntry<'posts'>[],
|
|
448
|
+
count: number = 8
|
|
449
|
+
): Array<{ name: string; count: number; slug: string }> {
|
|
450
|
+
const tagCounts: Record<string, number> = {};
|
|
451
|
+
|
|
452
|
+
posts.forEach(post => {
|
|
453
|
+
(post.data.tags || []).forEach(tag => {
|
|
454
|
+
tagCounts[tag] = (tagCounts[tag] || 0) + 1;
|
|
455
|
+
});
|
|
456
|
+
});
|
|
457
|
+
|
|
458
|
+
return Object.entries(tagCounts)
|
|
459
|
+
.sort((a, b) => b[1] - a[1])
|
|
460
|
+
.slice(0, count)
|
|
461
|
+
.map(([name, count]) => ({
|
|
462
|
+
name,
|
|
463
|
+
count,
|
|
464
|
+
slug: name.toLowerCase().replace(/\s+/g, '-'),
|
|
465
|
+
}));
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
/**
|
|
469
|
+
* 获取归档数据
|
|
470
|
+
*/
|
|
471
|
+
export function getArchives(
|
|
472
|
+
posts: CollectionEntry<'posts'>[],
|
|
473
|
+
count: number = 6
|
|
474
|
+
): Array<{ year: number; month: number; count: number }> {
|
|
475
|
+
const archiveMap: Record<string, number> = {};
|
|
476
|
+
|
|
477
|
+
posts.forEach(post => {
|
|
478
|
+
if (post.data.pubDate) {
|
|
479
|
+
const date = new Date(post.data.pubDate);
|
|
480
|
+
const key = `${date.getFullYear()}-${date.getMonth() + 1}`;
|
|
481
|
+
archiveMap[key] = (archiveMap[key] || 0) + 1;
|
|
482
|
+
}
|
|
483
|
+
});
|
|
484
|
+
|
|
485
|
+
return Object.entries(archiveMap)
|
|
486
|
+
.sort((a, b) => b[0].localeCompare(a[0]))
|
|
487
|
+
.slice(0, count)
|
|
488
|
+
.map(([key, count]) => {
|
|
489
|
+
const [year, month] = key.split('-').map(Number);
|
|
490
|
+
return { year, month, count };
|
|
491
|
+
});
|
|
492
|
+
}
|