@coffic/cosy-ui 0.9.4 → 0.9.6
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/index-astro.ts +2 -19
- package/dist/index-collection.ts +1 -105
- package/dist/src-astro/collection/entities/BaseDoc.ts +28 -0
- package/dist/src-astro/collection/entities/BlogDoc.ts +221 -0
- package/dist/src-astro/collection/entities/CourseDoc.ts +254 -0
- package/dist/src-astro/collection/entities/ExperimentDoc.ts +169 -0
- package/dist/src-astro/collection/entities/LessonDoc.ts +203 -0
- package/dist/src-astro/collection/entities/MetaDoc.ts +115 -0
- package/dist/src-astro/{entities → collection/entities}/SidebarItem.ts +17 -17
- package/dist/src-astro/collection/entities/Tag.ts +42 -0
- package/dist/src-astro/collection/index.ts +11 -0
- package/dist/src-astro/collection/repos/BaseRepo.ts +276 -0
- package/dist/src-astro/collection/repos/BlogRepo.ts +226 -0
- package/dist/src-astro/collection/repos/CourseRepo.ts +137 -0
- package/dist/src-astro/collection/repos/ExperimentRepo.ts +121 -0
- package/dist/src-astro/collection/repos/LessonRepo.ts +128 -0
- package/dist/src-astro/collection/repos/MetaRepo.ts +89 -0
- package/package.json +1 -1
- package/dist/src-astro/database/BaseDB.ts +0 -264
- package/dist/src-astro/database/BlogDB.ts +0 -198
- package/dist/src-astro/database/CourseDB.ts +0 -90
- package/dist/src-astro/database/ExperimentDB.ts +0 -106
- package/dist/src-astro/database/LessonDB.ts +0 -106
- package/dist/src-astro/database/MetaDB.ts +0 -74
- package/dist/src-astro/database/index.ts +0 -3
- package/dist/src-astro/entities/BaseDoc.ts +0 -207
- package/dist/src-astro/entities/BlogDoc.ts +0 -107
- package/dist/src-astro/entities/CourseDoc.ts +0 -102
- package/dist/src-astro/entities/ExperimentDoc.ts +0 -119
- package/dist/src-astro/entities/LessonDoc.ts +0 -153
- package/dist/src-astro/entities/MetaDoc.ts +0 -93
- package/dist/src-astro/entities/Tag.ts +0 -42
- /package/dist/src-astro/{entities → collection/entities}/Feature.ts +0 -0
@@ -1,93 +0,0 @@
|
|
1
|
-
import { SidebarItemEntity } from './SidebarItem';
|
2
|
-
import type { MetaEntry } from '../database/MetaDB';
|
3
|
-
import { LinkUtil } from '../../src/utils/link';
|
4
|
-
import { BaseDoc } from './BaseDoc';
|
5
|
-
import { metaDB } from '../database/MetaDB';
|
6
|
-
import { COLLECTION_META } from '../database/MetaDB';
|
7
|
-
|
8
|
-
export default class MetaDoc extends BaseDoc<
|
9
|
-
typeof COLLECTION_META,
|
10
|
-
MetaEntry
|
11
|
-
> {
|
12
|
-
constructor(entry: MetaEntry) {
|
13
|
-
super(entry);
|
14
|
-
}
|
15
|
-
|
16
|
-
static fromEntry(entry: MetaEntry) {
|
17
|
-
return new MetaDoc(entry);
|
18
|
-
}
|
19
|
-
|
20
|
-
getTopDoc(): Promise<MetaDoc | null> {
|
21
|
-
return Promise.resolve(null);
|
22
|
-
}
|
23
|
-
|
24
|
-
getChildren(): Promise<MetaDoc[]> {
|
25
|
-
return Promise.resolve([]);
|
26
|
-
}
|
27
|
-
|
28
|
-
getLink(): string {
|
29
|
-
return LinkUtil.getMetaLink(this.getLang(), this.getSlug());
|
30
|
-
}
|
31
|
-
|
32
|
-
getLang(): string {
|
33
|
-
return this.entry.id.split('/')[0];
|
34
|
-
}
|
35
|
-
|
36
|
-
/**
|
37
|
-
* 获取元数据页面的 slug
|
38
|
-
* 例如:
|
39
|
-
* ID: zh-cn/about 的 slug 为 about
|
40
|
-
* ID: en/privacy 的 slug 为 privacy
|
41
|
-
*/
|
42
|
-
override getSlug(): string {
|
43
|
-
// 从 ID 中获取 slug,即删除以/分割后的第一个元素
|
44
|
-
return this.getId().split('/').slice(1).join('/');
|
45
|
-
}
|
46
|
-
|
47
|
-
/**
|
48
|
-
* 获取兄弟文档
|
49
|
-
* 例如:对于 'zh-cn/about',会返回 'zh-cn' 下的其他文档
|
50
|
-
*/
|
51
|
-
async getSiblingDocs(): Promise<MetaDoc[]> {
|
52
|
-
return await metaDB.getSiblings(this.entry.id);
|
53
|
-
}
|
54
|
-
|
55
|
-
/**
|
56
|
-
* 获取兄弟文档的侧边栏项目
|
57
|
-
*/
|
58
|
-
async getSiblingSidebarItems(): Promise<SidebarItemEntity[]> {
|
59
|
-
const siblings = await this.getSiblingDocs();
|
60
|
-
const siblingItems = await Promise.all(
|
61
|
-
siblings.map((sibling) => {
|
62
|
-
return new SidebarItemEntity({
|
63
|
-
text: sibling.getTitle(),
|
64
|
-
link: sibling.getLink(),
|
65
|
-
});
|
66
|
-
})
|
67
|
-
);
|
68
|
-
return siblingItems;
|
69
|
-
}
|
70
|
-
|
71
|
-
/**
|
72
|
-
* 重写侧边栏项目方法
|
73
|
-
* 对于元数据页面,我们不显示子项目
|
74
|
-
*/
|
75
|
-
override async toSidebarItem(): Promise<SidebarItemEntity> {
|
76
|
-
return new SidebarItemEntity({
|
77
|
-
text: this.getTitle(),
|
78
|
-
link: this.getLink(),
|
79
|
-
});
|
80
|
-
}
|
81
|
-
|
82
|
-
/**
|
83
|
-
* 重写顶级侧边栏项目方法
|
84
|
-
* 对于元数据页面,我们显示所有兄弟页面作为侧边栏项目
|
85
|
-
*/
|
86
|
-
async getTopSidebarItem(): Promise<SidebarItemEntity> {
|
87
|
-
return new SidebarItemEntity({
|
88
|
-
text: '了解我们',
|
89
|
-
items: await this.getSiblingSidebarItems(),
|
90
|
-
link: '',
|
91
|
-
});
|
92
|
-
}
|
93
|
-
}
|
@@ -1,42 +0,0 @@
|
|
1
|
-
import { blogDB } from '../database/BlogDB';
|
2
|
-
import { SidebarItemEntity } from './SidebarItem';
|
3
|
-
import { type ITagStaticPath } from '../types/static-path';
|
4
|
-
import { LinkUtil } from '../../src/utils/link';
|
5
|
-
|
6
|
-
export class Tag {
|
7
|
-
name: string;
|
8
|
-
lang: string;
|
9
|
-
count: number;
|
10
|
-
|
11
|
-
constructor(name: string, count: number, lang: string) {
|
12
|
-
this.name = name;
|
13
|
-
this.count = count;
|
14
|
-
this.lang = lang;
|
15
|
-
}
|
16
|
-
|
17
|
-
toSidebarItem(lang: string): SidebarItemEntity {
|
18
|
-
return new SidebarItemEntity({
|
19
|
-
text: this.name,
|
20
|
-
link: LinkUtil.getTagLink(lang, this.name),
|
21
|
-
});
|
22
|
-
}
|
23
|
-
|
24
|
-
toTagPath(): ITagStaticPath {
|
25
|
-
return {
|
26
|
-
params: { slug: this.lang + '/blogs/tag/' + this.name },
|
27
|
-
props: { tag: this.name },
|
28
|
-
};
|
29
|
-
}
|
30
|
-
|
31
|
-
static async makeRootSidebarItem(lang: string): Promise<SidebarItemEntity> {
|
32
|
-
const tags = await blogDB.getTagsByLang(lang);
|
33
|
-
|
34
|
-
return new SidebarItemEntity({
|
35
|
-
text: 'Tags',
|
36
|
-
link: LinkUtil.getTagLink(lang, ''),
|
37
|
-
items: tags.map((tag: Tag) => tag.toSidebarItem(lang)),
|
38
|
-
});
|
39
|
-
}
|
40
|
-
}
|
41
|
-
|
42
|
-
export default Tag;
|
File without changes
|