@coffic/cosy-ui 0.9.3 → 0.9.5
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/app.css +1 -1
- package/dist/index-astro.ts +3 -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/dist/src-astro/empty-state/EmptyState.astro +100 -0
- package/dist/src-astro/empty-state/index.ts +2 -0
- package/dist/src-astro/empty-state/types.ts +70 -0
- package/dist/src-astro/layout-dashboard/DashboardLayout.astro +2 -1
- package/dist/src-astro/layout-dashboard/DashboardTopNavbar.astro +2 -26
- 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,119 +0,0 @@
|
|
1
|
-
import type { ExperimentEntry } from '../database/ExperimentDB';
|
2
|
-
import { experimentDB } from '../database/ExperimentDB';
|
3
|
-
import { cosyLogger } from '../cosy';
|
4
|
-
import { SidebarItemEntity } from './SidebarItem';
|
5
|
-
import { LinkUtil } from '../../src/utils/link';
|
6
|
-
import { COLLECTION_EXPERIMENT } from '../database/ExperimentDB';
|
7
|
-
import { BaseDoc } from './BaseDoc';
|
8
|
-
import type { IHeadingType } from '../types/heading';
|
9
|
-
|
10
|
-
export default class ExperimentDoc extends BaseDoc<
|
11
|
-
typeof COLLECTION_EXPERIMENT,
|
12
|
-
ExperimentEntry
|
13
|
-
> {
|
14
|
-
constructor(entry: ExperimentEntry) {
|
15
|
-
super(entry);
|
16
|
-
}
|
17
|
-
|
18
|
-
isBook(): boolean {
|
19
|
-
return this.entry.id.split('/').length === 2;
|
20
|
-
}
|
21
|
-
|
22
|
-
async getBookId(): Promise<string> {
|
23
|
-
return this.getTopDocId();
|
24
|
-
}
|
25
|
-
|
26
|
-
async getBook(): Promise<ExperimentDoc | null> {
|
27
|
-
const bookId = await this.getBookId();
|
28
|
-
return await experimentDB.find(bookId);
|
29
|
-
}
|
30
|
-
|
31
|
-
getLink(): string {
|
32
|
-
const debug = false;
|
33
|
-
const lang = this.getLang();
|
34
|
-
const link = LinkUtil.getExperimentLink(lang, this.getId());
|
35
|
-
|
36
|
-
if (debug) {
|
37
|
-
cosyLogger.info(`获取 ${this.entry.id} 的链接: ${link}`);
|
38
|
-
}
|
39
|
-
|
40
|
-
return link;
|
41
|
-
}
|
42
|
-
|
43
|
-
/**
|
44
|
-
* 获取文档的语言
|
45
|
-
*
|
46
|
-
* 文档的 id 格式为 `book-id/zh-cn/chapter-id/lesson-id`
|
47
|
-
*
|
48
|
-
* @returns 语言
|
49
|
-
*/
|
50
|
-
override getLang(): string {
|
51
|
-
const debug = false;
|
52
|
-
|
53
|
-
const parts = this.entry.id.split('/');
|
54
|
-
const lang = parts[1];
|
55
|
-
|
56
|
-
if (debug) {
|
57
|
-
cosyLogger.info(`获取 ${this.entry.id} 的语言: ${lang}`);
|
58
|
-
}
|
59
|
-
|
60
|
-
return lang;
|
61
|
-
}
|
62
|
-
|
63
|
-
getHTML(): string {
|
64
|
-
const debug = false;
|
65
|
-
|
66
|
-
if (debug) {
|
67
|
-
cosyLogger.info(`获取 ${this.entry.id} 的 HTML`);
|
68
|
-
}
|
69
|
-
|
70
|
-
return this.entry.rendered?.html || '';
|
71
|
-
}
|
72
|
-
|
73
|
-
getHeadings(): IHeadingType[] {
|
74
|
-
const debug = false;
|
75
|
-
|
76
|
-
if (debug) {
|
77
|
-
cosyLogger.info(`获取 ${this.entry.id} 的 headings`);
|
78
|
-
}
|
79
|
-
|
80
|
-
return (this.entry.rendered?.metadata?.headings as IHeadingType[]) || [];
|
81
|
-
}
|
82
|
-
|
83
|
-
async getTopDoc(): Promise<ExperimentDoc | null> {
|
84
|
-
const bookId = await this.getBookId();
|
85
|
-
return await experimentDB.find(bookId);
|
86
|
-
}
|
87
|
-
|
88
|
-
async getChildren(): Promise<ExperimentDoc[]> {
|
89
|
-
return await experimentDB.getChildren(this.entry.id);
|
90
|
-
}
|
91
|
-
|
92
|
-
async getDescendants(): Promise<ExperimentDoc[]> {
|
93
|
-
return await experimentDB.getDescendantDocs(this.entry.id);
|
94
|
-
}
|
95
|
-
|
96
|
-
override async toSidebarItem(): Promise<SidebarItemEntity> {
|
97
|
-
const debug = false;
|
98
|
-
|
99
|
-
const children = await this.getChildren();
|
100
|
-
let childItems = await Promise.all(
|
101
|
-
children.map((child) => child.toSidebarItem())
|
102
|
-
);
|
103
|
-
|
104
|
-
if (this.isBook()) {
|
105
|
-
childItems = [...childItems];
|
106
|
-
}
|
107
|
-
|
108
|
-
if (debug) {
|
109
|
-
cosyLogger.info(`${this.entry.id} 的侧边栏项目`);
|
110
|
-
console.log(childItems);
|
111
|
-
}
|
112
|
-
|
113
|
-
return new SidebarItemEntity({
|
114
|
-
text: this.getTitle(),
|
115
|
-
items: childItems,
|
116
|
-
link: this.getLink(),
|
117
|
-
});
|
118
|
-
}
|
119
|
-
}
|
@@ -1,153 +0,0 @@
|
|
1
|
-
import type { LessonEntry } from '../database/LessonDB';
|
2
|
-
import { lessonDB } from '../database/LessonDB';
|
3
|
-
import { cosyLogger } from '../cosy';
|
4
|
-
import { SidebarItemEntity } from './SidebarItem';
|
5
|
-
import { LinkUtil } from '../../src/utils/link';
|
6
|
-
import { COLLECTION_LESSON } from '../database/LessonDB';
|
7
|
-
import { BaseDoc } from './BaseDoc';
|
8
|
-
import type { IHeadingType } from '../types/heading';
|
9
|
-
|
10
|
-
/**
|
11
|
-
* 课程文档类,配合 LessonDB 使用
|
12
|
-
*
|
13
|
-
* 目录结构:
|
14
|
-
* ```
|
15
|
-
* lessons/
|
16
|
-
* ├── build_your_own_web_toolbox/ # 课程目录
|
17
|
-
* │ ├── images/ # 课程图片资源
|
18
|
-
* │ ├── components/ # 课程组件
|
19
|
-
* │ ├── en/ # 英文版本
|
20
|
-
* │ │ ├── index.mdx # 课程首页
|
21
|
-
* │ │ ├── 1.mdx # 第一章
|
22
|
-
* │ │ └── 2.mdx # 第二章
|
23
|
-
* │ └── zh-cn/ # 中文版本
|
24
|
-
* │ ├── index.mdx # 课程首页
|
25
|
-
* │ ├── 1.mdx # 第一章
|
26
|
-
* │ └── 2.mdx # 第二章
|
27
|
-
* └── learn_astro/ # 另一个课程
|
28
|
-
* ├── en/
|
29
|
-
* │ ├── index.mdx
|
30
|
-
* │ ├── 1.mdx
|
31
|
-
* │ └── 2.mdx
|
32
|
-
* └── zh-cn/
|
33
|
-
* ├── index.mdx
|
34
|
-
* ├── 1.mdx
|
35
|
-
* └── 2.mdx
|
36
|
-
* ```
|
37
|
-
*
|
38
|
-
* 说明:
|
39
|
-
* - 每个课程(如 build_your_own_web_toolbox)是一个独立的目录
|
40
|
-
* - 课程目录可以包含多语言版本(en, zh-cn 等)
|
41
|
-
* - 每个语言版本包含完整的课程内容
|
42
|
-
* - 课程目录可以作为 git 子模块独立管理
|
43
|
-
*/
|
44
|
-
export default class LessonDoc extends BaseDoc<
|
45
|
-
typeof COLLECTION_LESSON,
|
46
|
-
LessonEntry
|
47
|
-
> {
|
48
|
-
constructor(entry: LessonEntry) {
|
49
|
-
super(entry);
|
50
|
-
}
|
51
|
-
|
52
|
-
isBook(): boolean {
|
53
|
-
return this.entry.id.split('/').length === 2;
|
54
|
-
}
|
55
|
-
|
56
|
-
async getBookId(): Promise<string> {
|
57
|
-
return this.getTopDocId();
|
58
|
-
}
|
59
|
-
|
60
|
-
async getBook(): Promise<LessonDoc | null> {
|
61
|
-
const bookId = await this.getBookId();
|
62
|
-
return await lessonDB.find(bookId);
|
63
|
-
}
|
64
|
-
|
65
|
-
getLink(): string {
|
66
|
-
const debug = false;
|
67
|
-
const lang = this.getLang();
|
68
|
-
const link = LinkUtil.getLessonLink(lang, this.getId());
|
69
|
-
|
70
|
-
if (debug) {
|
71
|
-
cosyLogger.info(`获取 ${this.entry.id} 的链接: ${link}`);
|
72
|
-
}
|
73
|
-
|
74
|
-
return link;
|
75
|
-
}
|
76
|
-
|
77
|
-
/**
|
78
|
-
* 获取文档的语言
|
79
|
-
*
|
80
|
-
* 文档的 id 格式为 `book-id/zh-cn/chapter-id/lesson-id`
|
81
|
-
*
|
82
|
-
* @returns 语言
|
83
|
-
*/
|
84
|
-
override getLang(): string {
|
85
|
-
const debug = false;
|
86
|
-
|
87
|
-
const parts = this.entry.id.split('/');
|
88
|
-
const lang = parts[1];
|
89
|
-
|
90
|
-
if (debug) {
|
91
|
-
cosyLogger.info(`获取 ${this.entry.id} 的语言: ${lang}`);
|
92
|
-
}
|
93
|
-
|
94
|
-
return lang;
|
95
|
-
}
|
96
|
-
|
97
|
-
getHTML(): string {
|
98
|
-
const debug = false;
|
99
|
-
|
100
|
-
if (debug) {
|
101
|
-
cosyLogger.info(`获取 ${this.entry.id} 的 HTML`);
|
102
|
-
}
|
103
|
-
|
104
|
-
return this.entry.rendered?.html || '';
|
105
|
-
}
|
106
|
-
|
107
|
-
getHeadings(): IHeadingType[] {
|
108
|
-
const debug = false;
|
109
|
-
|
110
|
-
if (debug) {
|
111
|
-
cosyLogger.info(`获取 ${this.entry.id} 的 headings`);
|
112
|
-
}
|
113
|
-
|
114
|
-
return (this.entry.rendered?.metadata?.headings as IHeadingType[]) || [];
|
115
|
-
}
|
116
|
-
|
117
|
-
async getTopDoc(): Promise<LessonDoc | null> {
|
118
|
-
const bookId = await this.getBookId();
|
119
|
-
return await lessonDB.find(bookId);
|
120
|
-
}
|
121
|
-
|
122
|
-
async getChildren(): Promise<LessonDoc[]> {
|
123
|
-
return await lessonDB.getChildren(this.entry.id);
|
124
|
-
}
|
125
|
-
|
126
|
-
async getDescendants(): Promise<LessonDoc[]> {
|
127
|
-
return await lessonDB.getDescendantDocs(this.entry.id);
|
128
|
-
}
|
129
|
-
|
130
|
-
override async toSidebarItem(): Promise<SidebarItemEntity> {
|
131
|
-
const debug = false;
|
132
|
-
|
133
|
-
const children = await this.getChildren();
|
134
|
-
let childItems = await Promise.all(
|
135
|
-
children.map((child) => child.toSidebarItem())
|
136
|
-
);
|
137
|
-
|
138
|
-
if (this.isBook()) {
|
139
|
-
childItems = [...childItems];
|
140
|
-
}
|
141
|
-
|
142
|
-
if (debug) {
|
143
|
-
cosyLogger.info(`${this.entry.id} 的侧边栏项目`);
|
144
|
-
console.log(childItems);
|
145
|
-
}
|
146
|
-
|
147
|
-
return new SidebarItemEntity({
|
148
|
-
text: this.getTitle(),
|
149
|
-
items: childItems,
|
150
|
-
link: this.getLink(),
|
151
|
-
});
|
152
|
-
}
|
153
|
-
}
|
@@ -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
|