@coffic/cosy-ui 0.3.67 → 0.4.3
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/components/containers/Container.astro +2 -2
- package/dist/components/containers/Main.astro +41 -54
- package/dist/components/data-display/Products.astro +197 -0
- package/dist/components/layouts/AppLayout.astro +254 -0
- package/dist/components/layouts/BaseLayout.astro +3 -52
- package/dist/components/layouts/Footer.astro +141 -113
- package/dist/components/layouts/Header.astro +10 -292
- package/dist/components/layouts/Sidebar.astro +55 -31
- package/dist/components/layouts/SidebarNav.astro +1 -11
- package/dist/components/typography/Article.astro +8 -30
- package/dist/index.ts +4 -2
- package/dist/types/article.ts +22 -0
- package/dist/types/footer.ts +119 -22
- package/dist/types/header.ts +70 -0
- package/dist/types/layout.ts +71 -10
- package/dist/types/main.ts +69 -0
- package/dist/types/meta.ts +50 -0
- package/dist/types/sidebar.ts +38 -0
- package/dist/utils/language.ts +23 -8
- package/package.json +2 -2
- package/dist/components/layouts/DocumentationLayout.astro +0 -624
package/dist/types/footer.ts
CHANGED
@@ -10,37 +10,134 @@ export interface Product {
|
|
10
10
|
}
|
11
11
|
|
12
12
|
export interface FooterProps {
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
/**
|
14
|
+
* 关于链接
|
15
|
+
*/
|
16
|
+
aboutLink?: string;
|
17
|
+
|
18
|
+
/**
|
19
|
+
* 博客链接
|
20
|
+
*/
|
21
|
+
blogLink?: string;
|
22
|
+
|
23
|
+
/**
|
24
|
+
* 职业链接
|
25
|
+
*/
|
26
|
+
careersLink?: string;
|
27
|
+
|
28
|
+
/**
|
29
|
+
* 公司名称
|
30
|
+
*/
|
16
31
|
company: string;
|
32
|
+
|
33
|
+
/**
|
34
|
+
* 联系链接
|
35
|
+
*/
|
36
|
+
contactLink?: string;
|
37
|
+
|
38
|
+
/**
|
39
|
+
* 版权信息
|
40
|
+
*/
|
17
41
|
copyright: string;
|
18
|
-
|
42
|
+
|
43
|
+
/**
|
44
|
+
* 调试模式
|
45
|
+
*/
|
19
46
|
debug?: boolean;
|
47
|
+
|
48
|
+
/**
|
49
|
+
* 是否启用日志输出
|
50
|
+
* @default false
|
51
|
+
*/
|
52
|
+
enableLogging?: boolean;
|
53
|
+
|
54
|
+
/**
|
55
|
+
* 常见问题链接
|
56
|
+
*/
|
57
|
+
faqLink?: string;
|
58
|
+
|
59
|
+
/**
|
60
|
+
* 历史链接
|
61
|
+
*/
|
62
|
+
historyLink?: string;
|
63
|
+
|
64
|
+
/**
|
65
|
+
* 首页链接
|
66
|
+
*/
|
67
|
+
homeLink: string;
|
68
|
+
|
69
|
+
/**
|
70
|
+
* ICP备案号
|
71
|
+
*/
|
20
72
|
icp?: string;
|
73
|
+
|
74
|
+
/**
|
75
|
+
* 激励标语
|
76
|
+
*/
|
77
|
+
inspirationalSlogan: string;
|
78
|
+
|
79
|
+
/**
|
80
|
+
* 语言代码,默认自动检测
|
81
|
+
*/
|
82
|
+
lang?: string;
|
83
|
+
|
84
|
+
/**
|
85
|
+
* 徽标
|
86
|
+
*/
|
21
87
|
logo?: Logo;
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
88
|
+
|
89
|
+
/**
|
90
|
+
* 媒体链接
|
91
|
+
*/
|
92
|
+
mediaLink?: string;
|
93
|
+
|
94
|
+
/**
|
95
|
+
* 新闻链接
|
96
|
+
*/
|
97
|
+
newsLink?: string;
|
98
|
+
|
99
|
+
/**
|
100
|
+
* 合作伙伴链接
|
101
|
+
*/
|
102
|
+
partnersLink?: string;
|
103
|
+
|
104
|
+
/**
|
105
|
+
* 隐私链接
|
106
|
+
*/
|
26
107
|
privacyLink?: string;
|
108
|
+
|
109
|
+
/**
|
110
|
+
* 产品
|
111
|
+
*/
|
112
|
+
products?: Product[];
|
113
|
+
|
114
|
+
/**
|
115
|
+
* 站点名称
|
116
|
+
*/
|
117
|
+
siteName: string;
|
118
|
+
|
119
|
+
/**
|
120
|
+
* 标语
|
121
|
+
*/
|
122
|
+
slogan: string;
|
123
|
+
|
124
|
+
/**
|
125
|
+
* 社交链接
|
126
|
+
*/
|
27
127
|
socialLinks?: string[];
|
128
|
+
|
129
|
+
/**
|
130
|
+
* 团队链接
|
131
|
+
*/
|
28
132
|
teamLink?: string;
|
29
|
-
|
30
|
-
newsLink?: string;
|
31
|
-
historyLink?: string;
|
32
|
-
partnersLink?: string;
|
33
|
-
blogLink?: string;
|
34
|
-
faqLink?: string;
|
35
|
-
mediaLink?: string;
|
36
|
-
techStackLink?: string;
|
133
|
+
|
37
134
|
/**
|
38
|
-
*
|
135
|
+
* 技术栈链接
|
39
136
|
*/
|
40
|
-
|
137
|
+
techStackLink?: string;
|
138
|
+
|
41
139
|
/**
|
42
|
-
*
|
43
|
-
* @default false
|
140
|
+
* 条款链接
|
44
141
|
*/
|
45
|
-
|
46
|
-
}
|
142
|
+
termsLink?: string;
|
143
|
+
}
|
@@ -0,0 +1,70 @@
|
|
1
|
+
export interface HeaderProps {
|
2
|
+
/**
|
3
|
+
* 基础路径,用于处理网站部署在二级目录的情况
|
4
|
+
* @default ""
|
5
|
+
*/
|
6
|
+
basePath?: string;
|
7
|
+
|
8
|
+
/**
|
9
|
+
* 当前语言代码
|
10
|
+
*/
|
11
|
+
currentLocale?: string;
|
12
|
+
|
13
|
+
/**
|
14
|
+
* 侧边栏是否默认展开
|
15
|
+
* @default false
|
16
|
+
*/
|
17
|
+
defaultSidebarOpen?: boolean;
|
18
|
+
|
19
|
+
/**
|
20
|
+
* 导航栏高度
|
21
|
+
* @default "md"
|
22
|
+
*/
|
23
|
+
height?: '3xs' | '2xs' | 'xs' | 'sm' | 'md' | 'lg' | 'xl';
|
24
|
+
|
25
|
+
/**
|
26
|
+
* 语言选项列表
|
27
|
+
*/
|
28
|
+
languages?: Array<{ code: string; name: string }>;
|
29
|
+
|
30
|
+
/**
|
31
|
+
* Logo图片元数据
|
32
|
+
*/
|
33
|
+
logo: ImageMetadata;
|
34
|
+
|
35
|
+
/**
|
36
|
+
* Logo 链接地址
|
37
|
+
* @default "/"
|
38
|
+
*/
|
39
|
+
logoHref?: string;
|
40
|
+
|
41
|
+
/**
|
42
|
+
* 导航菜单项
|
43
|
+
*/
|
44
|
+
navItems?: Array<{
|
45
|
+
href: string;
|
46
|
+
label: string;
|
47
|
+
match: (path: string) => boolean;
|
48
|
+
}>;
|
49
|
+
|
50
|
+
/**
|
51
|
+
* 是否显示侧边栏切换按钮
|
52
|
+
* @default false
|
53
|
+
*/
|
54
|
+
showSidebarToggle?: boolean;
|
55
|
+
|
56
|
+
/**
|
57
|
+
* 社交链接
|
58
|
+
*/
|
59
|
+
socialLinks?: Array<{
|
60
|
+
name: string;
|
61
|
+
url: string;
|
62
|
+
icon: any;
|
63
|
+
}>;
|
64
|
+
|
65
|
+
/**
|
66
|
+
* 是否固定在顶部
|
67
|
+
* @default true
|
68
|
+
*/
|
69
|
+
sticky?: boolean;
|
70
|
+
}
|
package/dist/types/layout.ts
CHANGED
@@ -1,10 +1,71 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
}
|
6
|
-
|
7
|
-
export interface
|
8
|
-
|
9
|
-
|
10
|
-
|
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";
|
6
|
+
|
7
|
+
export interface AppLayoutProps {
|
8
|
+
/**
|
9
|
+
* 是否显示侧边栏
|
10
|
+
* @default true
|
11
|
+
*/
|
12
|
+
showSidebar?: boolean;
|
13
|
+
|
14
|
+
/**
|
15
|
+
* 是否显示页眉
|
16
|
+
* @default true
|
17
|
+
*/
|
18
|
+
showHeader?: boolean;
|
19
|
+
|
20
|
+
/**
|
21
|
+
* 是否显示页脚
|
22
|
+
* @default true
|
23
|
+
*/
|
24
|
+
showFooter?: boolean;
|
25
|
+
|
26
|
+
/**
|
27
|
+
* 自定义头部内容
|
28
|
+
*/
|
29
|
+
head?: astroHTML.JSX.Element;
|
30
|
+
|
31
|
+
/**
|
32
|
+
* 自定义头部内容
|
33
|
+
*/
|
34
|
+
headerConfig: HeaderProps;
|
35
|
+
|
36
|
+
/**
|
37
|
+
* 侧边栏配置
|
38
|
+
*/
|
39
|
+
sidebarConfig: SidebarProps;
|
40
|
+
|
41
|
+
/**
|
42
|
+
* 主内容配置
|
43
|
+
*/
|
44
|
+
mainContentConfig: MainContentProps;
|
45
|
+
|
46
|
+
/**
|
47
|
+
* 页面类名
|
48
|
+
*/
|
49
|
+
class?: string;
|
50
|
+
|
51
|
+
/**
|
52
|
+
* 类名列表
|
53
|
+
*/
|
54
|
+
'class:list'?: any;
|
55
|
+
|
56
|
+
/**
|
57
|
+
* 调试模式,显示各个部分的边框
|
58
|
+
* @default false
|
59
|
+
*/
|
60
|
+
debug?: boolean;
|
61
|
+
|
62
|
+
/**
|
63
|
+
* 元数据配置
|
64
|
+
*/
|
65
|
+
metaConfig: MetaProps;
|
66
|
+
|
67
|
+
/**
|
68
|
+
* 页脚相关配置
|
69
|
+
*/
|
70
|
+
footerConfig: FooterProps;
|
71
|
+
}
|
@@ -0,0 +1,69 @@
|
|
1
|
+
export interface MainContentProps {
|
2
|
+
/**
|
3
|
+
* 容器大小
|
4
|
+
* @default "md"
|
5
|
+
*/
|
6
|
+
size?: 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'full';
|
7
|
+
|
8
|
+
/**
|
9
|
+
* 水平内边距(通过 Container 组件的 padding 属性设置)
|
10
|
+
* @default "md"
|
11
|
+
*/
|
12
|
+
padding?: 'none' | 'sm' | 'md' | 'lg' | 'xl';
|
13
|
+
|
14
|
+
/**
|
15
|
+
* 布局方式
|
16
|
+
* @default 'column'
|
17
|
+
*/
|
18
|
+
layout?: 'row' | 'column';
|
19
|
+
|
20
|
+
/**
|
21
|
+
* 当前语言
|
22
|
+
*/
|
23
|
+
currentLocale?: string;
|
24
|
+
|
25
|
+
/**
|
26
|
+
* 垂直内边距
|
27
|
+
* @default "md"
|
28
|
+
*/
|
29
|
+
verticalPadding?: 'none' | 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl' | '3xl' | '4xl' | '5xl' | string;
|
30
|
+
|
31
|
+
/**
|
32
|
+
* 是否居中显示内容
|
33
|
+
* @default true
|
34
|
+
*/
|
35
|
+
centered?: boolean;
|
36
|
+
|
37
|
+
/**
|
38
|
+
* 是否为文章布局
|
39
|
+
* @default false
|
40
|
+
*/
|
41
|
+
isArticle?: boolean;
|
42
|
+
|
43
|
+
/**
|
44
|
+
* 是否显示目录
|
45
|
+
* @default false
|
46
|
+
*/
|
47
|
+
showTableOfContents?: boolean;
|
48
|
+
|
49
|
+
/**
|
50
|
+
* 背景颜色
|
51
|
+
* @default undefined
|
52
|
+
*/
|
53
|
+
backgroundColor?: 'primary' | 'secondary' | 'tertiary' | 'light' | 'dark' | string;
|
54
|
+
|
55
|
+
/**
|
56
|
+
* HTML id 属性
|
57
|
+
*/
|
58
|
+
id?: string;
|
59
|
+
|
60
|
+
/**
|
61
|
+
* 类名
|
62
|
+
*/
|
63
|
+
class?: string;
|
64
|
+
|
65
|
+
/**
|
66
|
+
* 类名列表
|
67
|
+
*/
|
68
|
+
'class:list'?: any;
|
69
|
+
}
|
@@ -0,0 +1,50 @@
|
|
1
|
+
export interface MetaProps {
|
2
|
+
title: string;
|
3
|
+
description: string;
|
4
|
+
keywords: string;
|
5
|
+
author: string;
|
6
|
+
robots: string;
|
7
|
+
|
8
|
+
/**
|
9
|
+
* 基础路径,用于处理网站部署在二级目录的情况
|
10
|
+
* @default ""
|
11
|
+
*/
|
12
|
+
basePath?: string;
|
13
|
+
|
14
|
+
/**
|
15
|
+
* 站点名称
|
16
|
+
*/
|
17
|
+
siteName?: string;
|
18
|
+
|
19
|
+
/**
|
20
|
+
* 页面语言
|
21
|
+
* @default "zh-CN"
|
22
|
+
*/
|
23
|
+
lang?: string;
|
24
|
+
|
25
|
+
/**
|
26
|
+
* 是否包含视口元标签
|
27
|
+
* @default true
|
28
|
+
*/
|
29
|
+
viewport?: boolean;
|
30
|
+
|
31
|
+
/**
|
32
|
+
* 自定义CSS
|
33
|
+
*/
|
34
|
+
customStyles?: string;
|
35
|
+
|
36
|
+
/**
|
37
|
+
* 自定义头部内容
|
38
|
+
*/
|
39
|
+
head?: astroHTML.JSX.Element;
|
40
|
+
|
41
|
+
/**
|
42
|
+
* 页面类名
|
43
|
+
*/
|
44
|
+
class?: string;
|
45
|
+
|
46
|
+
/**
|
47
|
+
* 类名列表
|
48
|
+
*/
|
49
|
+
'class:list'?: any;
|
50
|
+
}
|
@@ -0,0 +1,38 @@
|
|
1
|
+
export interface SidebarItem {
|
2
|
+
href: string;
|
3
|
+
text: string;
|
4
|
+
items?: SidebarItem[];
|
5
|
+
}
|
6
|
+
|
7
|
+
export interface SidebarSection {
|
8
|
+
title: string;
|
9
|
+
items: SidebarItem[];
|
10
|
+
}
|
11
|
+
|
12
|
+
export interface SidebarProps {
|
13
|
+
/**
|
14
|
+
* 侧边栏项目
|
15
|
+
*/
|
16
|
+
sidebarItems: SidebarSection[];
|
17
|
+
|
18
|
+
/**
|
19
|
+
* 桌面端类名
|
20
|
+
*/
|
21
|
+
class?: string;
|
22
|
+
|
23
|
+
/**
|
24
|
+
* 是否开启调试模式,显示边框
|
25
|
+
* @default false
|
26
|
+
*/
|
27
|
+
debug?: boolean;
|
28
|
+
|
29
|
+
/**
|
30
|
+
* 侧边栏顶部外边距
|
31
|
+
*/
|
32
|
+
marginTop?: 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl' | '3xl' | '4xl' | '5xl' | string;
|
33
|
+
|
34
|
+
/**
|
35
|
+
* 侧边栏底部外边距
|
36
|
+
*/
|
37
|
+
marginBottom?: 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl' | '3xl' | '4xl' | '5xl' | string;
|
38
|
+
}
|
package/dist/utils/language.ts
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
*/
|
6
6
|
|
7
7
|
// 支持的语言列表
|
8
|
-
export const SUPPORTED_LANGUAGES = ['en', 'zh-cn'] as const;
|
8
|
+
export const SUPPORTED_LANGUAGES = ['en', 'zh-cn', 'zh'] as const;
|
9
9
|
export type SupportedLanguage = typeof SUPPORTED_LANGUAGES[number];
|
10
10
|
|
11
11
|
// 语言来源枚举
|
@@ -49,21 +49,34 @@ export function getValidLanguage(lang?: string): SupportedLanguage {
|
|
49
49
|
|
50
50
|
/**
|
51
51
|
* 从URL中提取语言代码
|
52
|
+
* @param url 当前URL(可选)
|
52
53
|
* @returns 从URL中提取的语言代码,如果无法提取则返回undefined
|
53
54
|
*/
|
54
|
-
function getLanguageFromURL(): string | undefined {
|
55
|
-
|
55
|
+
function getLanguageFromURL(url?: string): string | undefined {
|
56
|
+
let currentUrl = url;
|
57
|
+
|
58
|
+
if (currentUrl === undefined) {
|
59
|
+
if (typeof window === 'undefined') return undefined;
|
60
|
+
currentUrl = window.location.href;
|
61
|
+
}
|
56
62
|
|
57
63
|
// 尝试从路径中提取语言代码
|
58
64
|
// 例如: /zh-cn/components/button
|
59
|
-
const pathMatch =
|
65
|
+
const pathMatch = currentUrl.match(/^\/([\w-]+)\//);
|
60
66
|
if (pathMatch && isLanguageSupported(pathMatch[1])) {
|
61
67
|
return pathMatch[1];
|
62
68
|
}
|
63
69
|
|
70
|
+
// 如果网站运行在二级目录,则从路径中提取语言代码
|
71
|
+
// 例如: /docs/zh-cn/components/button
|
72
|
+
const pathMatch2 = currentUrl.match(/^\/([^\/]+)\/([\w-]+)\//);
|
73
|
+
if (pathMatch2 && isLanguageSupported(pathMatch2[2])) {
|
74
|
+
return pathMatch2[2];
|
75
|
+
}
|
76
|
+
|
64
77
|
// 尝试从查询参数中提取语言代码
|
65
78
|
// 例如: ?lang=zh-cn
|
66
|
-
const urlParams = new URLSearchParams(
|
79
|
+
const urlParams = new URLSearchParams(currentUrl.split('?')[1]);
|
67
80
|
const langParam = urlParams.get('lang');
|
68
81
|
if (langParam && isLanguageSupported(langParam)) {
|
69
82
|
return langParam;
|
@@ -101,11 +114,12 @@ function getLanguageFromBrowser(): string | undefined {
|
|
101
114
|
|
102
115
|
/**
|
103
116
|
* 自动检测当前语言
|
117
|
+
* @param url 当前URL(可选)
|
104
118
|
* @returns 检测到的语言信息,包括语言代码和来源
|
105
119
|
*/
|
106
|
-
|
120
|
+
function detectLanguage(url?: string): LanguageInfo {
|
107
121
|
// 尝试从URL中获取语言
|
108
|
-
const urlLang = getLanguageFromURL();
|
122
|
+
const urlLang = getLanguageFromURL(url);
|
109
123
|
if (urlLang) {
|
110
124
|
return {
|
111
125
|
code: urlLang as SupportedLanguage,
|
@@ -132,9 +146,10 @@ export function detectLanguage(): LanguageInfo {
|
|
132
146
|
/**
|
133
147
|
* 获取当前语言
|
134
148
|
* @param userLang 用户指定的语言(可选)
|
149
|
+
* @param url 当前URL(可选)
|
135
150
|
* @returns 当前应使用的语言信息,包括语言代码和来源
|
136
151
|
*/
|
137
|
-
export function getCurrentLanguage(userLang?: string): LanguageInfo {
|
152
|
+
export function getCurrentLanguage(userLang?: string, url?: string): LanguageInfo {
|
138
153
|
// 如果用户指定了语言,优先使用用户指定的语言
|
139
154
|
if (userLang) {
|
140
155
|
if (isLanguageSupported(userLang)) {
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@coffic/cosy-ui",
|
3
|
-
"version": "0.3
|
3
|
+
"version": "0.4.3",
|
4
4
|
"description": "An astro component library",
|
5
5
|
"author": {
|
6
6
|
"name": "nookery",
|
@@ -17,7 +17,7 @@
|
|
17
17
|
"astro",
|
18
18
|
"cosy-ui"
|
19
19
|
],
|
20
|
-
"homepage": "https://github.
|
20
|
+
"homepage": "https://cofficlab.github.io/cosy-ui/en/",
|
21
21
|
"publishConfig": {
|
22
22
|
"access": "public"
|
23
23
|
},
|