@coffic/cosy-ui 0.5.12 → 0.6.2

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.
Files changed (40) hide show
  1. package/README.md +2 -31
  2. package/dist/collections/ArticleCollection.ts +19 -0
  3. package/dist/collections/BlogCollection.ts +28 -0
  4. package/dist/collections/CourseCollection.ts +11 -0
  5. package/dist/collections/ExperimentCollection.ts +18 -0
  6. package/dist/collections/LessonCollection.ts +25 -0
  7. package/dist/collections/MetaCollection.ts +17 -0
  8. package/dist/components/containers/Main.astro +2 -2
  9. package/dist/components/data-display/TeamMembers.astro +1 -1
  10. package/dist/components/display/Card.astro +0 -3
  11. package/dist/components/display/CodeBlock.astro +1 -2
  12. package/dist/components/display/Modal.astro +1 -2
  13. package/dist/components/icons/SearchIcon.astro +30 -34
  14. package/dist/components/icons/SunCloudyIcon.astro +35 -39
  15. package/dist/components/layouts/AppLayout.astro +2 -2
  16. package/dist/components/layouts/BaseLayout.astro +4 -3
  17. package/dist/components/layouts/Footer.astro +8 -14
  18. package/dist/components/layouts/Header.astro +6 -6
  19. package/dist/components/layouts/Sidebar.astro +2 -2
  20. package/dist/components/layouts/SidebarNav.astro +6 -6
  21. package/dist/components/navigation/TableOfContents.astro +6 -3
  22. package/dist/components/typography/Article.astro +2 -2
  23. package/dist/components/typography/Text.astro +1 -1
  24. package/dist/entities/MetaDoc.ts +10 -10
  25. package/dist/entities/SidebarItem.ts +68 -72
  26. package/dist/entities/Tag.ts +9 -9
  27. package/dist/index.ts +21 -1
  28. package/dist/types/article.ts +19 -19
  29. package/dist/types/footer.ts +4 -13
  30. package/dist/types/header.ts +4 -4
  31. package/dist/types/heading.ts +8 -8
  32. package/dist/types/layout.ts +59 -59
  33. package/dist/types/main.ts +68 -57
  34. package/dist/types/meta.ts +49 -49
  35. package/dist/types/nav.ts +1 -0
  36. package/dist/types/product.ts +10 -0
  37. package/dist/types/sidebar.ts +29 -26
  38. package/dist/types/static-path.ts +1 -1
  39. package/dist/utils/lang_package.ts +205 -206
  40. package/package.json +3 -3
@@ -1,4 +1,4 @@
1
- import { SidebarItem } from './SidebarItem';
1
+ import { SidebarItemEntity } from './SidebarItem';
2
2
  import type { MetaEntry } from '../database/MetaDB';
3
3
  import { LinkUtil } from '../utils/link';
4
4
  import { BaseDoc } from './BaseDoc';
@@ -44,12 +44,12 @@ export default class MetaDoc extends BaseDoc<typeof COLLECTION_NAME, MetaEntry>
44
44
  /**
45
45
  * 获取兄弟文档的侧边栏项目
46
46
  */
47
- async getSiblingSidebarItems(): Promise<SidebarItem[]> {
47
+ async getSiblingSidebarItems(): Promise<SidebarItemEntity[]> {
48
48
  const siblings = await this.getSiblingDocs();
49
49
  const siblingItems = await Promise.all(
50
50
  siblings.map((sibling) => {
51
- return new SidebarItem({
52
- label: sibling.getTitle(),
51
+ return new SidebarItemEntity({
52
+ text: sibling.getTitle(),
53
53
  link: sibling.getLink(),
54
54
  });
55
55
  })
@@ -61,9 +61,9 @@ export default class MetaDoc extends BaseDoc<typeof COLLECTION_NAME, MetaEntry>
61
61
  * 重写侧边栏项目方法
62
62
  * 对于元数据页面,我们不显示子项目
63
63
  */
64
- override async toSidebarItem(): Promise<SidebarItem> {
65
- return new SidebarItem({
66
- label: this.getTitle(),
64
+ override async toSidebarItem(): Promise<SidebarItemEntity> {
65
+ return new SidebarItemEntity({
66
+ text: this.getTitle(),
67
67
  link: this.getLink(),
68
68
  });
69
69
  }
@@ -72,9 +72,9 @@ export default class MetaDoc extends BaseDoc<typeof COLLECTION_NAME, MetaEntry>
72
72
  * 重写顶级侧边栏项目方法
73
73
  * 对于元数据页面,我们显示所有兄弟页面作为侧边栏项目
74
74
  */
75
- async getTopSidebarItem(): Promise<SidebarItem> {
76
- return new SidebarItem({
77
- label: '了解我们',
75
+ async getTopSidebarItem(): Promise<SidebarItemEntity> {
76
+ return new SidebarItemEntity({
77
+ text: '了解我们',
78
78
  items: await this.getSiblingSidebarItems(),
79
79
  link: '',
80
80
  });
@@ -1,79 +1,75 @@
1
- import { type SidebarItem } from '../types/sidebar';
1
+ import { type ISidebarItem } from '../types/sidebar';
2
2
 
3
3
  /**
4
4
  * 侧边栏项目类
5
5
  * 用于构建网站的侧边栏导航
6
6
  */
7
- export class SidebarItemEntity implements SidebarItem {
8
- text: string;
9
- href: string;
10
- items: SidebarItem[];
7
+ export class SidebarItemEntity implements ISidebarItem {
8
+ text: string;
9
+ href: string;
10
+ items: ISidebarItem[];
11
11
 
12
- constructor(props: {
13
- text: string;
14
- link?: string;
15
- items?: SidebarItem[];
16
- }) {
17
- this.text = props.text;
18
- this.href = props.link || '';
19
- this.items = props.items || [];
20
- }
12
+ constructor(props: { text: string; link?: string; items?: ISidebarItem[] }) {
13
+ this.text = props.text;
14
+ this.href = props.link || '';
15
+ this.items = props.items || [];
16
+ }
21
17
 
22
- /**
23
- * 添加子项目
24
- * @param item 要添加的子项目
25
- */
26
- addItem(item: SidebarItemEntity): void {
27
- this.items.push(item);
28
- }
18
+ /**
19
+ * 添加子项目
20
+ * @param item 要添加的子项目
21
+ */
22
+ addItem(item: SidebarItemEntity): void {
23
+ this.items.push(item);
24
+ }
29
25
 
30
- /**
31
- * 获取所有子项目
32
- * @returns 子项目数组
33
- */
34
- getItems(): SidebarItemEntity[] {
35
- return this.items.map(item => new SidebarItemEntity(item));
36
- }
26
+ /**
27
+ * 获取所有子项目
28
+ * @returns 子项目数组
29
+ */
30
+ getItems(): SidebarItemEntity[] {
31
+ return this.items.map((item) => new SidebarItemEntity(item));
32
+ }
37
33
 
38
- /**
39
- * 获取项目标签
40
- * @returns 项目标签
41
- */
42
- getLabel(): string {
43
- return this.text;
44
- }
34
+ /**
35
+ * 获取项目标签
36
+ * @returns 项目标签
37
+ */
38
+ getLabel(): string {
39
+ return this.text;
40
+ }
45
41
 
46
- /**
47
- * 获取项目链接
48
- * @returns 项目链接
49
- */
50
- getLink(): string {
51
- return this.href;
52
- }
42
+ /**
43
+ * 获取项目链接
44
+ * @returns 项目链接
45
+ */
46
+ getLink(): string {
47
+ return this.href;
48
+ }
53
49
 
54
- /**
55
- * 获取包括自身在内的所有项目
56
- * @returns 包括自身在内的所有项目
57
- */
58
- getItemsIncludingSelf(): SidebarItemEntity[] {
59
- return [this, ...this.getItems()];
60
- }
50
+ /**
51
+ * 获取包括自身在内的所有项目
52
+ * @returns 包括自身在内的所有项目
53
+ */
54
+ getItemsIncludingSelf(): SidebarItemEntity[] {
55
+ return [this, ...this.getItems()];
56
+ }
61
57
 
62
- /**
63
- * 判断是否是分组(有子项目)
64
- * @returns 是否是分组
65
- */
66
- isGroup(): boolean {
67
- return this.items.length > 0;
68
- }
58
+ /**
59
+ * 判断是否是分组(有子项目)
60
+ * @returns 是否是分组
61
+ */
62
+ isGroup(): boolean {
63
+ return this.items.length > 0;
64
+ }
69
65
 
70
- /**
71
- * 判断是否不是分组
72
- * @returns 是否不是分组
73
- */
74
- isNotGroup(): boolean {
75
- return !this.isGroup();
76
- }
66
+ /**
67
+ * 判断是否不是分组
68
+ * @returns 是否不是分组
69
+ */
70
+ isNotGroup(): boolean {
71
+ return !this.isGroup();
72
+ }
77
73
  }
78
74
 
79
75
  /**
@@ -81,13 +77,13 @@ export class SidebarItemEntity implements SidebarItem {
81
77
  * 实现此接口的类可以提供侧边栏项目
82
78
  */
83
79
  export interface SidebarProvider {
84
- /**
85
- * 转换为侧边栏项目
86
- */
87
- toSidebarItem(): Promise<SidebarItemEntity>;
80
+ /**
81
+ * 转换为侧边栏项目
82
+ */
83
+ toSidebarItem(): Promise<SidebarItemEntity>;
88
84
 
89
- /**
90
- * 获取顶级侧边栏项目
91
- */
92
- getTopSidebarItem?(): Promise<SidebarItemEntity>;
93
- }
85
+ /**
86
+ * 获取顶级侧边栏项目
87
+ */
88
+ getTopSidebarItem?(): Promise<SidebarItemEntity>;
89
+ }
@@ -1,6 +1,6 @@
1
1
  import blogDB from '../database/BlogDB';
2
- import { SidebarItem } from './SidebarItem';
3
- import { type TagStaticPath } from '../types/static-path';
2
+ import { SidebarItemEntity } from './SidebarItem';
3
+ import { type ITagStaticPath } from '../types/static-path';
4
4
  import { LinkUtil } from '../utils/link';
5
5
 
6
6
  export class Tag {
@@ -14,25 +14,25 @@ export class Tag {
14
14
  this.lang = lang;
15
15
  }
16
16
 
17
- toSidebarItem(lang: string): SidebarItem {
18
- return new SidebarItem({
19
- label: this.name,
17
+ toSidebarItem(lang: string): SidebarItemEntity {
18
+ return new SidebarItemEntity({
19
+ text: this.name,
20
20
  link: LinkUtil.getTagLink(lang, this.name),
21
21
  });
22
22
  }
23
23
 
24
- toTagPath(): TagStaticPath {
24
+ toTagPath(): ITagStaticPath {
25
25
  return {
26
26
  params: { slug: this.lang + '/blogs/tag/' + this.name },
27
27
  props: { tag: this.name },
28
28
  };
29
29
  }
30
30
 
31
- static async makeRootSidebarItem(lang: string): Promise<SidebarItem> {
31
+ static async makeRootSidebarItem(lang: string): Promise<SidebarItemEntity> {
32
32
  const tags = await blogDB.getTagsByLang(lang);
33
33
 
34
- return new SidebarItem({
35
- label: 'Tags',
34
+ return new SidebarItemEntity({
35
+ text: 'Tags',
36
36
  link: LinkUtil.getTagLink(lang, ''),
37
37
  items: tags.map((tag: Tag) => tag.toSidebarItem(lang)),
38
38
  });
package/dist/index.ts CHANGED
@@ -7,6 +7,14 @@ export { default as Alert } from './components/base/Alert.astro';
7
7
  export { default as Speak } from './components/base/Speak.astro';
8
8
  export { default as Module } from './components/base/Module.astro';
9
9
 
10
+ // Collections
11
+ export * from './collections/ArticleCollection';
12
+ export * from './collections/BlogCollection';
13
+ export * from './collections/CourseCollection';
14
+ export * from './collections/ExperimentCollection';
15
+ export * from './collections/LessonCollection';
16
+ export * from './collections/MetaCollection';
17
+
10
18
  // Navigation
11
19
  export { default as ThemeSwitcher } from './components/navigation/ThemeSwitcher.astro';
12
20
  export { default as TableOfContents } from './components/navigation/TableOfContents.astro';
@@ -91,10 +99,22 @@ export * from './types/layout';
91
99
  export * from './types/header';
92
100
  export * from './types/heading';
93
101
  export * from './types/meta';
102
+ export * from './types/nav';
103
+ export * from './types/product';
104
+ export * from './types/footer';
105
+ export * from './types/static-path';
94
106
  export type { ImageProvider, ImageOptions } from './utils/image';
95
107
 
96
- // Models
108
+ // Entities
97
109
  export * from './entities/BaseDoc';
110
+ export * from './entities/BlogDoc';
111
+ export * from './entities/CourseDoc';
112
+ export * from './entities/ExperimentDoc';
113
+ export * from './entities/Heading';
114
+ export * from './entities/LessonDoc';
115
+ export * from './entities/MetaDoc';
116
+ export * from './entities/SidebarItem';
117
+ export * from './entities/Tag';
98
118
 
99
119
  // Database
100
120
  export * from './database/BaseDB';
@@ -1,22 +1,22 @@
1
- export interface ArticleProps {
2
- /**
3
- * 文章的类名
4
- */
5
- class?: string;
1
+ export interface IArticleProps {
2
+ /**
3
+ * 文章的类名
4
+ */
5
+ class?: string;
6
6
 
7
- /**
8
- * 类名列表
9
- */
10
- 'class:list'?: any;
7
+ /**
8
+ * 类名列表
9
+ */
10
+ 'class:list'?: any;
11
11
 
12
- /**
13
- * 内联样式
14
- */
15
- style?: string;
12
+ /**
13
+ * 内联样式
14
+ */
15
+ style?: string;
16
16
 
17
- /**
18
- * 文章宽度
19
- * @default "medium"
20
- */
21
- width?: 'narrow' | 'medium' | 'wide' | 'full';
22
- }
17
+ /**
18
+ * 文章宽度
19
+ * @default "medium"
20
+ */
21
+ width?: 'narrow' | 'medium' | 'wide' | 'full';
22
+ }
@@ -1,15 +1,6 @@
1
- export interface Logo {
2
- src: string;
3
- alt: string;
4
- }
5
-
6
- export interface Product {
7
- name: string;
8
- href: string;
9
- external?: boolean;
10
- }
1
+ import type { ILogo, IProduct } from './product';
11
2
 
12
- export interface FooterProps {
3
+ export interface IFooterProps {
13
4
  /**
14
5
  * 关于链接
15
6
  */
@@ -79,7 +70,7 @@ export interface FooterProps {
79
70
  /**
80
71
  * 徽标
81
72
  */
82
- logo?: Logo;
73
+ logo?: ILogo;
83
74
 
84
75
  /**
85
76
  * 媒体链接
@@ -104,7 +95,7 @@ export interface FooterProps {
104
95
  /**
105
96
  * 产品
106
97
  */
107
- products?: Product[];
98
+ products?: IProduct[];
108
99
 
109
100
  /**
110
101
  * 站点名称
@@ -1,4 +1,6 @@
1
- export interface HeaderProps {
1
+ import type { INavItem } from './nav';
2
+
3
+ export interface IHeaderProps {
2
4
  /**
3
5
  * 侧边栏是否默认展开
4
6
  * @default false
@@ -30,7 +32,7 @@ export interface HeaderProps {
30
32
  /**
31
33
  * 导航菜单项
32
34
  */
33
- navItems?: NavItem[];
35
+ navItems?: INavItem[];
34
36
 
35
37
  /**
36
38
  * 是否显示侧边栏切换按钮
@@ -60,5 +62,3 @@ export interface HeaderProps {
60
62
 
61
63
  navPosition?: 'start' | 'center' | 'end';
62
64
  }
63
-
64
- export type NavItem = { href: string; label: string };
@@ -1,13 +1,13 @@
1
1
  /**
2
2
  * 表示文档中的标题结构
3
3
  */
4
- export interface Heading {
5
- /** 标题深度,如 h1=1, h2=2, h3=3 等 */
6
- depth: number;
4
+ export interface IHeadingType {
5
+ /** 标题深度,如 h1=1, h2=2, h3=3 等 */
6
+ depth: number;
7
7
 
8
- /** 标题的唯一标识符,用于锚点链接 */
9
- slug: string;
8
+ /** 标题的唯一标识符,用于锚点链接 */
9
+ slug: string;
10
10
 
11
- /** 标题文本内容 */
12
- text: string;
13
- }
11
+ /** 标题文本内容 */
12
+ text: string;
13
+ }
@@ -1,71 +1,71 @@
1
- import type { FooterProps } from "./footer";
2
- import type { HeaderProps } from "./header";
3
- import type { MainContentProps } from "./main";
4
- import type { MetaProps } from "./meta";
5
- import type { SidebarProps } from "./sidebar";
1
+ import type { IFooterProps } from './footer';
2
+ import type { IHeaderProps } from './header';
3
+ import type { IMainContentProps } from './main';
4
+ import type { IMetaProps } from './meta';
5
+ import type { ISidebarProps } from './sidebar';
6
6
 
7
- export interface AppLayoutProps {
8
- /**
9
- * 是否显示侧边栏
10
- * @default true
11
- */
12
- showSidebar?: boolean;
7
+ export interface IAppLayoutProps {
8
+ /**
9
+ * 是否显示侧边栏
10
+ * @default true
11
+ */
12
+ showSidebar?: boolean;
13
13
 
14
- /**
15
- * 是否显示页眉
16
- * @default true
17
- */
18
- showHeader?: boolean;
14
+ /**
15
+ * 是否显示页眉
16
+ * @default true
17
+ */
18
+ showHeader?: boolean;
19
19
 
20
- /**
21
- * 是否显示页脚
22
- * @default true
23
- */
24
- showFooter?: boolean;
20
+ /**
21
+ * 是否显示页脚
22
+ * @default true
23
+ */
24
+ showFooter?: boolean;
25
25
 
26
- /**
27
- * 自定义头部内容
28
- */
29
- head?: astroHTML.JSX.Element;
26
+ /**
27
+ * 自定义头部内容
28
+ */
29
+ head?: astroHTML.JSX.Element;
30
30
 
31
- /**
32
- * 自定义头部内容
33
- */
34
- headerConfig: HeaderProps;
31
+ /**
32
+ * 自定义头部内容
33
+ */
34
+ headerConfig: IHeaderProps;
35
35
 
36
- /**
37
- * 侧边栏配置
38
- */
39
- sidebarConfig: SidebarProps;
36
+ /**
37
+ * 侧边栏配置
38
+ */
39
+ sidebarConfig: ISidebarProps;
40
40
 
41
- /**
42
- * 主内容配置
43
- */
44
- mainContentConfig: MainContentProps;
41
+ /**
42
+ * 主内容配置
43
+ */
44
+ mainContentConfig: IMainContentProps;
45
45
 
46
- /**
47
- * 页面类名
48
- */
49
- class?: string;
46
+ /**
47
+ * 页面类名
48
+ */
49
+ class?: string;
50
50
 
51
- /**
52
- * 类名列表
53
- */
54
- 'class:list'?: any;
51
+ /**
52
+ * 类名列表
53
+ */
54
+ 'class:list'?: any;
55
55
 
56
- /**
57
- * 调试模式,显示各个部分的边框
58
- * @default false
59
- */
60
- debug?: boolean;
56
+ /**
57
+ * 调试模式,显示各个部分的边框
58
+ * @default false
59
+ */
60
+ debug?: boolean;
61
61
 
62
- /**
63
- * 元数据配置
64
- */
65
- metaConfig: MetaProps;
62
+ /**
63
+ * 元数据配置
64
+ */
65
+ metaConfig: IMetaProps;
66
66
 
67
- /**
68
- * 页脚相关配置
69
- */
70
- footerConfig: FooterProps;
71
- }
67
+ /**
68
+ * 页脚相关配置
69
+ */
70
+ footerConfig: IFooterProps;
71
+ }