@coffic/cosy-ui 0.6.36 → 0.6.40

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.
Binary file
@@ -0,0 +1,32 @@
1
+ ---
2
+ import { Image } from 'astro:assets';
3
+ import bookCover from '../assets/book.png';
4
+
5
+ interface Props {
6
+ title: string;
7
+ link: string;
8
+ }
9
+
10
+ const { title, link } = Astro.props;
11
+ ---
12
+
13
+ <div>
14
+ <a href={link} class="justify-center flex no-underline text-base-content">
15
+ <div class="w-56 h-80">
16
+ <div
17
+ class="bg-gradient-to-br w-full h-full from-accent/50 to-primary/30 rounded-3xl shadow-lg backdrop-blur-sm">
18
+ <div
19
+ class="bg-base-100/60 w-full h-full rounded-3xl border border-base-content/30 hover:scale-105 hover:shadow-2xl transform duration-200 backdrop-filter backdrop-blur-sm">
20
+ <div class="card-body p-1 h-full">
21
+ <Image src={bookCover} alt={title} class="h-3/5 w-full" />
22
+ <div>
23
+ <h2 class="text-lg text-center font-medium">
24
+ {title}
25
+ </h2>
26
+ </div>
27
+ </div>
28
+ </div>
29
+ </div>
30
+ </div>
31
+ </a>
32
+ </div>
@@ -1,6 +1,6 @@
1
1
 
2
-
3
2
  export { default as Card } from './Card.astro';
3
+ export { default as CardCourse } from './CardCourse.astro';
4
4
  export { default as CardBasic } from './CardBasic.astro';
5
5
  export { default as CardWithImage } from './CardWithImage.astro';
6
6
  export { default as CardLink } from './CardLink.astro';
package/dist/cosy.ts ADDED
@@ -0,0 +1,6 @@
1
+ import { Logger } from './utils/logger';
2
+
3
+ export const NAME = 'Cosy-UI';
4
+ export const ERROR_PREFIX = 'Cosy-UI: ';
5
+
6
+ export const cosyLogger = new Logger(NAME);
@@ -1,5 +1,6 @@
1
1
  import { getCollection, getEntry, type CollectionEntry, type DataEntryMap } from 'astro:content';
2
- import { logger } from '../utils/logger';
2
+ import { cosyLogger, ERROR_PREFIX } from '../cosy';
3
+ import type { BaseDoc } from '..';
3
4
 
4
5
  /**
5
6
  * BaseDB 是所有数据库类的基类,提供了通用的文档操作功能。
@@ -24,172 +25,207 @@ import { logger } from '../utils/logger';
24
25
  * @template Doc - 文档类型,通常是自定义的文档类
25
26
  */
26
27
  export abstract class BaseDB<
27
- Collection extends keyof DataEntryMap,
28
- Entry extends CollectionEntry<Collection>,
29
- Doc,
28
+ Collection extends keyof DataEntryMap,
29
+ Entry extends CollectionEntry<Collection>,
30
+ Doc extends BaseDoc<Collection, Entry>,
30
31
  > {
31
- /** 集合名称,必须在子类中指定 */
32
- protected abstract collectionName: Collection;
33
-
34
- /**
35
- * 创建文档实例的方法,必须在子类中实现
36
- * @param entry - 集合条目
37
- * @returns 文档实例
38
- */
39
- protected abstract createDoc(entry: Entry): Doc;
40
-
41
- /**
42
- * 获取所有文档的ID
43
- * @returns 返回所有文档的ID数组
44
- */
45
- async getAllIds(): Promise<string[]> {
46
- const entries = await getCollection(this.collectionName);
47
- return entries.map((entry) => entry.id);
48
- }
49
-
50
- /**
51
- * 获取集合中的所有条目
52
- * @returns 返回所有条目的数组
53
- */
54
- async getEntries(): Promise<Entry[]> {
55
- const entries = await getCollection(this.collectionName);
56
- return entries.map((entry) => entry as Entry);
57
- }
58
-
59
- /**
60
- * 获取指定深度的文档
61
- * 深度是指文档 ID 中斜杠的数量加1
62
- * 例如:
63
- * - "blog.md" 深度为1
64
- * - "zh-cn/blog.md" 深度为2
65
- * - "zh-cn/tech/blog.md" 深度为3
66
- *
67
- * @param depth - 文档深度
68
- * @returns 返回指定深度的文档数组
69
- */
70
- async getDocsByDepth(depth: number): Promise<Doc[]> {
71
- const entries = await getCollection(
72
- this.collectionName,
73
- ({ id }) => id.split('/').length === depth
74
- );
75
- return entries.map((entry) => this.createDoc(entry as Entry));
76
- }
77
-
78
- /**
79
- * 根据ID查找单个文档
80
- * @param id - 文档ID
81
- * @returns 返回找到的文档,如果不存在则返回null
82
- */
83
- async find(id: string): Promise<Doc | null> {
84
- const debug = false;
85
- if (debug) {
86
- logger.info(`查找文档,ID: ${id}`);
87
- }
88
-
89
- if (typeof id !== 'string') {
90
- throw new Error('ID must be a string, but got ' + typeof id);
91
- }
92
-
93
- // 获取所有文档的ID并排好顺序
94
- if (debug) {
95
- const allIds = (await this.getAllIds()).sort();
96
- logger.array('所有文档的ID', allIds);
97
- }
98
-
99
- // 根据ID查找文档
100
- const entry = await getEntry(this.collectionName, id);
101
- return entry ? this.createDoc(entry as Entry) : null;
102
- }
103
-
104
- /**
105
- * 获取指定文档的直接子文档(不包括更深层级的文档)
106
- * 例如对于文档 "zh-cn/blog":
107
- * - "zh-cn/blog/post1.md" 会被包含
108
- * - "zh-cn/blog/2024/post2.md" 不会被包含
109
- *
110
- * @param parentId - 父文档ID
111
- * @returns 返回子文档数组
112
- */
113
- async getChildren(parentId: string): Promise<Doc[]> {
114
- const parentLevel = parentId.split('/').length;
115
- const childrenLevel = parentLevel + 1;
116
-
117
- const entries = await getCollection(
118
- this.collectionName,
119
- ({ id }) => id.startsWith(parentId) && id.split('/').length === childrenLevel
120
- );
121
-
122
- return entries.map((entry) => this.createDoc(entry as Entry));
123
- }
124
-
125
- /**
126
- * 获取指定文档的所有后代文档(包括所有层级)
127
- * 例如对于文档 "zh-cn/blog",以下都会被包含:
128
- * - "zh-cn/blog/post1.md"
129
- * - "zh-cn/blog/2024/post2.md"
130
- * - "zh-cn/blog/2024/tech/post3.md"
131
- *
132
- * @param parentId - 父文档ID
133
- * @returns 返回所有后代文档数组
134
- */
135
- async getDescendantDocs(parentId: string): Promise<Doc[]> {
136
- const entries = await getCollection(this.collectionName, ({ id }) => id.startsWith(parentId));
137
- return entries.map((entry) => this.createDoc(entry as Entry));
138
- }
139
-
140
- /**
141
- * 获取指定语言的顶级文档
142
- * 通过检查文档ID是否以指定语言代码开头来筛选
143
- *
144
- * @param lang - 语言代码(如 'zh-cn', 'en')
145
- * @returns 返回指定语言的顶级文档数组
146
- */
147
- async allDocsByLang(lang: string): Promise<Doc[]> {
148
- const debug = false;
149
- const docs = await this.getDocsByDepth(2);
150
-
151
- if (debug) {
152
- logger.array('所有顶级文档', docs);
153
- }
154
-
155
- return docs.filter((doc) => {
156
- const id = (doc as any).getId();
157
- return id && typeof id === 'string' && id.startsWith(lang);
158
- });
159
- }
160
-
161
- /**
162
- * 获取用于 Astro 静态路由生成的路径参数
163
- * 为每个文档生成包含语言和slug的路径参数
164
- *
165
- * @returns 返回路径参数数组,每个元素包含 lang slug
166
- * @example
167
- * ```typescript
168
- * const paths = await db.getStaticPaths();
169
- * // 返回格式:
170
- * // [
171
- * // { params: { lang: 'zh-cn', slug: 'post1' } },
172
- * // { params: { lang: 'en', slug: 'post1' } }
173
- * // ]
174
- * ```
175
- */
176
- async getStaticPaths() {
177
- const debug = false;
178
- const docs = await this.getDescendantDocs('');
179
- const paths = docs.map((doc) => {
180
- const docWithMethods = doc as any;
181
- return {
182
- params: {
183
- lang: docWithMethods.getLang?.() || '',
184
- slug: docWithMethods.getSlug?.() || '',
185
- },
186
- };
187
- });
188
-
189
- if (debug) {
190
- logger.array('所有文档的路径', paths);
191
- }
192
-
193
- return paths;
194
- }
32
+ /** 集合名称,必须在子类中指定 */
33
+ protected abstract collectionName: Collection;
34
+
35
+ /**
36
+ * 创建文档实例的方法,必须在子类中实现
37
+ * @param entry - 集合条目
38
+ * @returns 文档实例
39
+ */
40
+ protected abstract createDoc(entry: Entry): Doc;
41
+
42
+ /**
43
+ * 获取所有文档的ID
44
+ * @returns 返回所有文档的ID数组
45
+ */
46
+ protected async getAllIds(): Promise<string[]> {
47
+ const entries = await getCollection(this.collectionName);
48
+ return entries.map(entry => entry.id);
49
+ }
50
+
51
+ /**
52
+ * 获取集合中的所有条目
53
+ * @returns 返回所有条目的数组
54
+ */
55
+ protected async getEntries(): Promise<Entry[]> {
56
+ return await getCollection(this.collectionName);
57
+ }
58
+
59
+ /**
60
+ * 获取指定深度的文档
61
+ * 深度是指文档 ID 中斜杠的数量加1
62
+ * 例如:
63
+ * - "blog.md" 深度为1
64
+ * - "zh-cn/blog.md" 深度为2
65
+ * - "zh-cn/tech/blog.md" 深度为3
66
+ *
67
+ * @param depth - 文档深度
68
+ * @returns 返回指定深度的文档数组
69
+ */
70
+ protected async getDocsByDepth(depth: number): Promise<Doc[]> {
71
+ const entries = await getCollection(
72
+ this.collectionName,
73
+ ({ id }: { id: string }) => id.split('/').length === depth
74
+ );
75
+
76
+ if (entries.length === 0) {
77
+ cosyLogger.warn(`[BaseDB] 没有找到深度为${depth}的文档(collection=${this.collectionName as string})`);
78
+ const allEntries = await getCollection(this.collectionName);
79
+ cosyLogger.array('[BaseDB] 所有文档', allEntries.map(entry => entry.id));
80
+ return [];
81
+ }
82
+
83
+ return entries.map(entry => this.createDoc(entry as Entry));
84
+ }
85
+
86
+ /**
87
+ * 根据ID查找单个文档
88
+ * @param id - 文档ID
89
+ * @param debug - 是否启用调试模式, 默认为false
90
+ * @throws 如果ID不是字符串类型,则抛出错误
91
+ * @throws 如果文档不存在,则返回null
92
+ * @throws 如果发生其他错误,则抛出错误
93
+ * @returns 返回找到的文档,如果不存在则返回null
94
+ */
95
+ async find(id: string, debug: boolean = false): Promise<Doc | null> {
96
+ if (debug) {
97
+ cosyLogger.info(`查找文档,ID: ${id}`);
98
+ }
99
+
100
+ if (id == undefined) {
101
+ cosyLogger.error('ID is undefined');
102
+ throw new Error(ERROR_PREFIX + 'ID is undefined');
103
+ }
104
+
105
+ if (typeof id !== 'string') {
106
+ cosyLogger.error('ID must be a string, but got ' + typeof id);
107
+ cosyLogger.debug(id);
108
+ throw new Error(ERROR_PREFIX + 'ID must be a string, but got ' + typeof id);
109
+ }
110
+
111
+ // 获取所有文档的ID并排好顺序
112
+ if (debug) {
113
+ const allIds = (await this.getAllIds()).sort();
114
+ cosyLogger.array('所有文档的ID', allIds);
115
+ }
116
+
117
+ // 根据ID查找文档
118
+ const entry = await getEntry(this.collectionName, id);
119
+ return entry ? this.createDoc(entry as Entry) : null;
120
+ }
121
+
122
+ /**
123
+ * 获取指定文档的直接子文档(不包括更深层级的文档)
124
+ * 例如对于文档 "zh-cn/blog":
125
+ * - "zh-cn/blog/post1.md" 会被包含
126
+ * - "zh-cn/blog/2024/post2.md" 不会被包含
127
+ *
128
+ * @param parentId - 父文档ID
129
+ * @returns 返回子文档数组
130
+ */
131
+ async getChildren(parentId: string): Promise<Doc[]> {
132
+ const parentLevel = parentId.split('/').length;
133
+ const childrenLevel = parentLevel + 1;
134
+
135
+ const entries = await getCollection(
136
+ this.collectionName,
137
+ ({ id }: { id: string }) => id.startsWith(parentId) && id.split('/').length === childrenLevel
138
+ );
139
+
140
+ return entries.map(entry => this.createDoc(entry as Entry));
141
+ }
142
+
143
+ /**
144
+ * 获取指定文档的所有后代文档(包括所有层级)
145
+ * 例如对于文档 "zh-cn/blog",以下都会被包含:
146
+ * - "zh-cn/blog/post1.md"
147
+ * - "zh-cn/blog/2024/post2.md"
148
+ * - "zh-cn/blog/2024/tech/post3.md"
149
+ *
150
+ * @param parentId - 父文档ID
151
+ * @returns 返回所有后代文档数组
152
+ */
153
+ async getDescendantDocs(parentId: string): Promise<Doc[]> {
154
+ const entries = await getCollection(this.collectionName, ({ id }: { id: string }) => id.startsWith(parentId));
155
+ return entries.map(entry => this.createDoc(entry as Entry));
156
+ }
157
+
158
+ /**
159
+ * 获取指定语言和级别的文档
160
+ * 通过检查文档ID是否以指定语言代码开头来筛选
161
+ *
162
+ * @param lang - 语言代码(如 'zh-cn', 'en')
163
+ * @param level - 文档级别
164
+ * @returns 返回指定语言和级别的文档数组
165
+ */
166
+ protected async allDocsByLangAndLevel(lang: string, level: number = 1, debug: boolean = false): Promise<Doc[]> {
167
+ const collectionName = this.collectionName as string;
168
+ const docs = await this.getDocsByDepth(level);
169
+
170
+ if (debug) {
171
+ cosyLogger.array(`[BaseDB] 所有${level}级文档(lang=any,collection=${collectionName})`, docs);
172
+ }
173
+
174
+ if (docs.length === 0) {
175
+ cosyLogger.warn(`[BaseDB] 没有找到${level}级文档(lang=any,collection=${collectionName})`);
176
+ return [];
177
+ }
178
+
179
+ const filteredDocs = docs.filter((doc) => {
180
+ const id = (doc as any).getId();
181
+ return id && typeof id === 'string' && id.startsWith(lang);
182
+ });
183
+
184
+ if (debug) {
185
+ cosyLogger.array(`[BaseDB] 所有${level}级文档(lang=${lang},collection=${collectionName})`, filteredDocs);
186
+ }
187
+
188
+ if (filteredDocs.length === 0) {
189
+ cosyLogger.warn(`[BaseDB] 没有找到${level}级文档(lang=${lang},collection=${collectionName})`);
190
+ cosyLogger.array(`[BaseDB] 所有${level}级文档`, docs.map((doc) => doc.getId()));
191
+ return [];
192
+ }
193
+
194
+ return filteredDocs;
195
+ }
196
+
197
+ /**
198
+ * 获取用于 Astro 静态路由生成的路径参数
199
+ * 为每个文档生成包含语言和slug的路径参数
200
+ *
201
+ * @returns 返回路径参数数组,每个元素包含 lang 和 slug
202
+ * @example
203
+ * ```typescript
204
+ * const paths = await db.getStaticPaths();
205
+ * // 返回格式:
206
+ * // [
207
+ * // { params: { lang: 'zh-cn', slug: 'post1' } },
208
+ * // { params: { lang: 'en', slug: 'post1' } }
209
+ * // ]
210
+ * ```
211
+ */
212
+ async getStaticPaths() {
213
+ const debug = false;
214
+ const docs = await this.getDescendantDocs('');
215
+ const paths = docs.map((doc) => {
216
+ const docWithMethods = doc as any;
217
+ return {
218
+ params: {
219
+ lang: docWithMethods.getLang?.() || '',
220
+ slug: docWithMethods.getSlug?.() || '',
221
+ },
222
+ };
223
+ });
224
+
225
+ if (debug) {
226
+ cosyLogger.array('所有文档的路径', paths);
227
+ }
228
+
229
+ return paths;
230
+ }
195
231
  }
@@ -1,6 +1,6 @@
1
1
  import BlogDoc from '../entities/BlogDoc';
2
2
  import type Tag from '../entities/Tag';
3
- import { logger } from '../utils/logger';
3
+ import { cosyLogger } from '../cosy';
4
4
  import { type CollectionEntry } from 'astro:content';
5
5
  import { BaseDB } from './BaseDB';
6
6
 
@@ -40,7 +40,7 @@ class BlogDB extends BaseDB<typeof COLLECTION_BLOG, BlogEntry, BlogDoc> {
40
40
  const entries = await this.getDocsByDepth(2);
41
41
 
42
42
  if (debug) {
43
- logger.array('所有博客文档', entries);
43
+ cosyLogger.array('所有博客文档', entries);
44
44
  }
45
45
 
46
46
  return entries;
@@ -62,10 +62,10 @@ class BlogDB extends BaseDB<typeof COLLECTION_BLOG, BlogEntry, BlogDoc> {
62
62
  /**
63
63
  * 获取用于 Astro 静态路由生成的路径参数,专门配合 [lang]/blogs/[slug].astro 使用
64
64
  *
65
+ * @param debug - 是否开启调试模式
65
66
  * @returns 返回路径参数数组
66
67
  */
67
- async getStaticPaths() {
68
- const debug = false;
68
+ async getStaticPaths(debug: boolean = false) {
69
69
  const docs = await this.allBlogs();
70
70
 
71
71
  const paths = docs.map((doc) => {
@@ -78,7 +78,7 @@ class BlogDB extends BaseDB<typeof COLLECTION_BLOG, BlogEntry, BlogDoc> {
78
78
  });
79
79
 
80
80
  if (debug) {
81
- logger.array('所有博客文档的路径', paths);
81
+ cosyLogger.array('所有博客文档的路径', paths);
82
82
  }
83
83
 
84
84
  return paths;
@@ -123,7 +123,7 @@ class BlogDB extends BaseDB<typeof COLLECTION_BLOG, BlogEntry, BlogDoc> {
123
123
  const posts = await this.allBlogsByLang(lang);
124
124
 
125
125
  if (debug) {
126
- logger.array('posts', posts);
126
+ cosyLogger.array('posts', posts);
127
127
  }
128
128
 
129
129
  if (posts.length === 0) {
@@ -140,7 +140,7 @@ class BlogDB extends BaseDB<typeof COLLECTION_BLOG, BlogEntry, BlogDoc> {
140
140
  });
141
141
 
142
142
  if (debug) {
143
- logger.array('tags', Array.from(tagsMap.values()));
143
+ cosyLogger.array('tags', Array.from(tagsMap.values()));
144
144
  }
145
145
 
146
146
  return Array.from(tagsMap.values());
@@ -187,7 +187,7 @@ class BlogDB extends BaseDB<typeof COLLECTION_BLOG, BlogEntry, BlogDoc> {
187
187
  });
188
188
 
189
189
  if (debug) {
190
- logger.array('所有的标签路径', paths);
190
+ cosyLogger.array('所有的标签路径', paths);
191
191
  }
192
192
 
193
193
  return paths;
@@ -11,9 +11,9 @@ export type CourseEntry = CollectionEntry<typeof COLLECTION_COURSE>;
11
11
  * 目录结构:
12
12
  * ```
13
13
  * courses/
14
- * ├── zh-cn/
15
- * │ ├── web-development/
16
- * │ │ ├── index.md
14
+ * ├── zh-cn/ # 中文版本
15
+ * │ ├── web-development/ # 课程1
16
+ * │ │ ├── index.md # 课程文档
17
17
  * │ │ ├── chapter1
18
18
  * │ │ │ ├── index.md
19
19
  * │ │ │ ├── content.md
@@ -22,10 +22,10 @@ export type CourseEntry = CollectionEntry<typeof COLLECTION_COURSE>;
22
22
  * │ │ ├── index.md
23
23
  * │ │ ├── content.md
24
24
  * │ │ └── ...
25
- * │ └── mobile-dev/
25
+ * │ └── mobile-dev/ # 课程2
26
26
  * │ ├── index.md
27
27
  * │ └── ...
28
- * └── en/
28
+ * └── en/ # 英文版本
29
29
  * └── ...
30
30
  * ```
31
31
  */
@@ -1,7 +1,7 @@
1
1
  import { type CollectionEntry } from 'astro:content';
2
2
  import { BaseDB } from './BaseDB';
3
3
  import ExperimentDoc from '../entities/ExperimentDoc';
4
- import { logger } from '../utils/logger';
4
+ import { cosyLogger } from '../cosy';
5
5
 
6
6
  export const COLLECTION_EXPERIMENT = 'experiments' as const;
7
7
  export type ExperimentEntry = CollectionEntry<typeof COLLECTION_EXPERIMENT>;
@@ -13,7 +13,7 @@ export type ExperimentEntry = CollectionEntry<typeof COLLECTION_EXPERIMENT>;
13
13
  * ```
14
14
  * experiments/
15
15
  * ├── safari_itp/ # 实验目录
16
- * │ ├── images/ # 实验图片资源
16
+ * │ ├── images/ # 实验图片资源
17
17
  * │ ├── components/ # 课程组件
18
18
  * │ ├── en/ # 英文版本
19
19
  * │ │ ├── index.mdx # 课程首页
@@ -61,14 +61,14 @@ class ExperimentDB extends BaseDB<typeof COLLECTION_EXPERIMENT, ExperimentEntry,
61
61
  /**
62
62
  * 获取用于 Astro 静态路由生成的路径参数
63
63
  *
64
+ * @param debug - 是否开启调试模式
64
65
  * @returns 返回路径参数数组
65
66
  */
66
- async getStaticPaths() {
67
- const debug = false;
67
+ async getStaticPaths(debug: boolean = false) {
68
68
  const docs = await this.getEntries();
69
69
 
70
70
  if (debug) {
71
- logger.array('所有文档', docs);
71
+ cosyLogger.array('所有文档', docs);
72
72
  }
73
73
 
74
74
  const paths = docs.map((doc) => {
@@ -91,7 +91,7 @@ class ExperimentDB extends BaseDB<typeof COLLECTION_EXPERIMENT, ExperimentEntry,
91
91
  });
92
92
 
93
93
  if (debug) {
94
- logger.array('所有文档的路径', paths);
94
+ cosyLogger.array('所有文档的路径', paths);
95
95
  }
96
96
 
97
97
  return paths;
@@ -1,7 +1,7 @@
1
1
  import { type CollectionEntry } from 'astro:content';
2
2
  import { BaseDB } from './BaseDB';
3
3
  import LessonDoc from '../entities/LessonDoc';
4
- import { logger } from '../utils/logger';
4
+ import { cosyLogger } from '../cosy';
5
5
 
6
6
  export const COLLECTION_LESSON = 'lessons' as const;
7
7
  export type LessonEntry = CollectionEntry<typeof COLLECTION_LESSON>;
@@ -60,15 +60,15 @@ class LessonDB extends BaseDB<typeof COLLECTION_LESSON, LessonEntry, LessonDoc>
60
60
 
61
61
  /**
62
62
  * 获取用于 Astro 静态路由生成的路径参数
63
- *
63
+ *
64
+ * @param debug - 是否开启调试模式
64
65
  * @returns 返回路径参数数组
65
66
  */
66
- async getStaticPaths() {
67
- const debug = false;
67
+ async getStaticPaths(debug: boolean = false) {
68
68
  const docs = await this.getEntries();
69
69
 
70
70
  if (debug) {
71
- logger.array('所有文档', docs);
71
+ cosyLogger.array('所有文档', docs);
72
72
  }
73
73
 
74
74
  const paths = docs.map((doc) => {
@@ -91,7 +91,7 @@ class LessonDB extends BaseDB<typeof COLLECTION_LESSON, LessonEntry, LessonDoc>
91
91
  });
92
92
 
93
93
  if (debug) {
94
- logger.array('所有文档的路径', paths);
94
+ cosyLogger.array('所有文档的路径', paths);
95
95
  }
96
96
 
97
97
  return paths;
@@ -1,5 +1,5 @@
1
1
  import MetaDoc from '../entities/MetaDoc';
2
- import { logger } from '../utils/logger';
2
+ import { cosyLogger } from '../cosy';
3
3
  import { type CollectionEntry } from 'astro:content';
4
4
  import { BaseDB } from './BaseDB';
5
5
 
@@ -47,10 +47,10 @@ class MetaDB extends BaseDB<typeof COLLECTION_META, MetaEntry, MetaDoc> {
47
47
  /**
48
48
  * 获取用于 Astro 静态路由生成的路径参数,专门配合 [lang]/meta/[slug].astro 使用
49
49
  *
50
+ * @param debug - 是否开启调试模式
50
51
  * @returns 返回路径参数数组
51
52
  */
52
- async getStaticPaths() {
53
- const debug = false;
53
+ async getStaticPaths(debug: boolean = false) {
54
54
  const docs = await this.getDescendantDocs('');
55
55
 
56
56
  const paths = docs.map((doc) => {
@@ -63,7 +63,7 @@ class MetaDB extends BaseDB<typeof COLLECTION_META, MetaEntry, MetaDoc> {
63
63
  });
64
64
 
65
65
  if (debug) {
66
- logger.array('所有元数据文档的路径', paths);
66
+ cosyLogger.array('所有元数据文档的路径', paths);
67
67
  }
68
68
 
69
69
  return paths;