@coffic/cosy-ui 0.4.7 → 0.4.9
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/database/BaseDB.ts +2 -2
- package/dist/models/BaseDoc.ts +1 -1
- package/dist/utils/link.ts +1 -1
- package/package.json +1 -1
- package/dist/database/MetaDB.ts +0 -75
package/dist/database/BaseDB.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { getCollection, getEntry, type CollectionEntry, type DataEntryMap } from "astro:content";
|
2
|
-
import { logger } from "
|
2
|
+
import { logger } from "../utils/logger";
|
3
3
|
|
4
4
|
/**
|
5
5
|
* BaseDB 是所有数据库类的基类,提供了通用的文档操作功能。
|
@@ -23,7 +23,7 @@ import { logger } from "@/utils/logger";
|
|
23
23
|
* @template Entry - Collection 对应的条目类型
|
24
24
|
* @template Doc - 文档类型,通常是自定义的文档类
|
25
25
|
*/
|
26
|
-
export
|
26
|
+
export abstract class BaseDB<
|
27
27
|
Collection extends keyof DataEntryMap,
|
28
28
|
Entry extends CollectionEntry<Collection>,
|
29
29
|
Doc
|
package/dist/models/BaseDoc.ts
CHANGED
@@ -5,7 +5,7 @@ import { logger } from "../utils/logger";
|
|
5
5
|
/**
|
6
6
|
* 文档基类,提供所有文档类型共享的基本功能
|
7
7
|
*/
|
8
|
-
export
|
8
|
+
export abstract class BaseDoc<Collection extends keyof DataEntryMap, T extends CollectionEntry<Collection>> implements SidebarProvider {
|
9
9
|
protected entry: T;
|
10
10
|
|
11
11
|
constructor(entry: T) {
|
package/dist/utils/link.ts
CHANGED
package/package.json
CHANGED
package/dist/database/MetaDB.ts
DELETED
@@ -1,75 +0,0 @@
|
|
1
|
-
import MetaDoc from "@/models/MetaDoc";
|
2
|
-
import { logger } from "@/utils/logger";
|
3
|
-
import { type CollectionEntry } from "astro:content";
|
4
|
-
import BaseDB from "./BaseDB";
|
5
|
-
|
6
|
-
export const COLLECTION_NAME = 'meta' as const;
|
7
|
-
export type MetaEntry = CollectionEntry<typeof COLLECTION_NAME>;
|
8
|
-
|
9
|
-
/**
|
10
|
-
* 元数据数据库类,用于管理网站的元数据内容集合(如"关于我们"等页面)
|
11
|
-
*
|
12
|
-
* 目录结构:
|
13
|
-
* ```
|
14
|
-
* meta/
|
15
|
-
* ├── zh-cn/ # 中文内容
|
16
|
-
* │ ├── about.md # 关于我们
|
17
|
-
* │ ├── advice.md # 建议
|
18
|
-
* └── en/ # 英文内容
|
19
|
-
* ├── about.md
|
20
|
-
* ├── privacy.md
|
21
|
-
* └── terms.md
|
22
|
-
* ```
|
23
|
-
*/
|
24
|
-
class MetaDB extends BaseDB<typeof COLLECTION_NAME, MetaEntry, MetaDoc> {
|
25
|
-
protected collectionName = COLLECTION_NAME;
|
26
|
-
|
27
|
-
protected createDoc(entry: MetaEntry): MetaDoc {
|
28
|
-
return new MetaDoc(entry);
|
29
|
-
}
|
30
|
-
|
31
|
-
/**
|
32
|
-
* 获取指定文档的兄弟文档
|
33
|
-
* 例如:对于 'zh-cn/about',会返回 'zh-cn' 下的文档
|
34
|
-
*
|
35
|
-
* @param targetId - 目标文档ID
|
36
|
-
* @returns 返回兄弟文档数组(包括目标文档本身)
|
37
|
-
*/
|
38
|
-
async getSiblings(targetId: string): Promise<MetaDoc[]> {
|
39
|
-
const target = await this.find(targetId);
|
40
|
-
if (!target) {
|
41
|
-
return [];
|
42
|
-
}
|
43
|
-
const docs = await this.getDocsByDepth(2);
|
44
|
-
return docs.filter(doc => doc.getLang() === target.getLang());
|
45
|
-
}
|
46
|
-
|
47
|
-
/**
|
48
|
-
* 获取用于 Astro 静态路由生成的路径参数,专门配合 [lang]/meta/[slug].astro 使用
|
49
|
-
*
|
50
|
-
* @returns 返回路径参数数组
|
51
|
-
*/
|
52
|
-
async getStaticPaths() {
|
53
|
-
const debug = false;
|
54
|
-
const docs = await this.getDescendantDocs('');
|
55
|
-
|
56
|
-
const paths = docs.map((doc) => {
|
57
|
-
return {
|
58
|
-
params: {
|
59
|
-
lang: doc.getLang(),
|
60
|
-
slug: doc.getSlug(),
|
61
|
-
},
|
62
|
-
};
|
63
|
-
});
|
64
|
-
|
65
|
-
if (debug) {
|
66
|
-
logger.array('所有元数据文档的路径', paths);
|
67
|
-
}
|
68
|
-
|
69
|
-
return paths;
|
70
|
-
}
|
71
|
-
}
|
72
|
-
|
73
|
-
// 创建并导出单例实例
|
74
|
-
const metaDB = new MetaDB();
|
75
|
-
export default metaDB;
|