refactor: reorganize project structure and improve type definitions

- Split types into separate modules for better organization
- Move data files to dedicated directories with proper documentation
- Enhance i18n utilities with better type safety and performance
- Maintain backward compatibility with legacy imports
This commit is contained in:
joyzhao
2025-06-21 09:18:39 +08:00
parent e38ec6b12f
commit ea01dc6dd8
14 changed files with 784 additions and 523 deletions

78
src/types/blog.ts Normal file
View File

@@ -0,0 +1,78 @@
/**
* Blog types module
* Contains type definitions for blog functionality
*/
import type { Lang } from './i18n';
/**
* Author information interface
*/
export interface Author {
name: string;
bio?: string;
avatar?: string;
website?: string;
twitter?: string;
github?: string;
linkedin?: string;
}
/**
* Blog post interface
*/
export interface BlogPost {
title: string;
description: string;
image: string;
slug: string;
tags: string[];
tagId?: string[];
category?: string[];
categoryId?: string[];
date: string;
readTime: string;
url?: string;
}
/**
* Blog post frontmatter properties interface
*/
export interface FrontmatterProps {
title: string;
description?: string;
publishDate?: string;
date?: string; // Alternative field name for publish date
author?: string;
tags?: string[];
tagId?: string[]; // Tag unique identifier for multilingual tag routing
category?: string | string[];
categoryId?: string[] | string; // Category unique identifier for multilingual category routing
readingTime?: number;
readTime?: string; // Alternative field name for reading time
}
/**
* Author card component props
*/
export interface AuthorCardProps {
lang: Lang;
author?: Author;
}
/**
* Share buttons component props
*/
export interface ShareButtonsProps {
lang: Lang;
title: string;
url?: string;
}
/**
* Blog list component props
*/
export interface BlogListProps {
posts: BlogPost[];
lang: Lang;
baseUrl?: string; // Base URL for blog posts, defaults to '/blog/posts/'
}

22
src/types/components.ts Normal file
View File

@@ -0,0 +1,22 @@
/**
* Component types module
* Contains type definitions for UI components
*/
import type { Lang } from './i18n';
/**
* Skill item interface
*/
export interface SkillItem {
name: string;
icon: string;
color: string;
}
/**
* Skill section component props
*/
export interface SkillSectionProps {
title: string;
skills: SkillItem[];
}

88
src/types/data.ts Normal file
View File

@@ -0,0 +1,88 @@
/**
* Data types module
* Contains type definitions for all data structures used in the application
*/
import type { Lang } from './i18n.ts';
/**
* Multi-language text type
*/
export type LocalizedText = {
[K in Lang]: string;
};
/**
* Personal information interface
*/
export interface PersonalInfo {
name: string;
location: string;
avatar: string;
email: string;
github: string;
linkedin: string;
website: string;
twitter: string;
position: LocalizedText;
description: LocalizedText;
about: {
[K in Lang]: string[];
};
stats: {
repositories: number;
commits: string;
contributions: number;
};
skills: {
frontend: string[];
backend: string[];
database: string[];
devops: string[];
mobile: string[];
};
terminal: {
username: string;
};
}
/**
* Project image interface
*/
export interface ProjectImage {
bg: string;
hover: string;
text: string;
}
/**
* Project interface
*/
export interface Project {
id: string;
tag: string;
title: string;
icon: string;
color: string;
image: ProjectImage;
description: string[];
tech: string[];
link: string;
}
/**
* Service icon interface
*/
export interface ServiceIcon {
svg: string;
gradient: string;
}
/**
* Service interface
*/
export interface Service {
title: string;
icon: ServiceIcon;
items: string[];
color: string;
}

36
src/types/i18n.ts Normal file
View File

@@ -0,0 +1,36 @@
/**
* Internationalization types module
* Contains type definitions for i18n functionality
*/
import { languages } from '@/i18n/translations';
/**
* Language type definition
*/
export type Lang = keyof typeof languages;
/**
* UI translation keys type
*/
export type UiKeys = string;
/**
* Language switcher component props
*/
export interface LanguageSwitcherProps {
lang: Lang;
}
/**
* Glass header component props
*/
export interface GlassHeaderProps {
lang: Lang;
}
/**
* Footer component props
*/
export interface FooterProps {
lang?: Lang;
}

View File

@@ -1,163 +1,10 @@
/**
* 集中管理项目中的类型定义
* 这个文件包含了项目中常用的接口和类型定义,减少代码冗余和提高可维护性
* Types index module
* Re-exports all type modules to maintain backward compatibility
*/
import { languages } from '@/i18n/ui';
/**
* 语言类型定义
*/
export type Lang = keyof typeof languages;
/**
* 国际化文本键类型
*/
export type UiKeys = string;
/**
* 多语言文本类型
*/
export type LocalizedText = {
[K in Lang]: string;
};
/**
* 作者信息接口
*/
export interface Author {
name: string;
bio?: string;
avatar?: string;
website?: string;
twitter?: string;
github?: string;
linkedin?: string;
}
/**
* 博客文章接口
*/
export interface BlogPost {
title: string;
description: string;
image: string;
slug: string;
tags: string[];
tagId?: string[];
category?: string[];
categoryId?: string[];
date: string;
readTime: string;
url?: string;
}
/**
* 博客文章前置元数据接口
*/
export interface FrontmatterProps {
title: string;
description?: string;
publishDate?: string;
date?: string; // Alternative field name for publish date
author?: string;
tags?: string[];
tagId?: string[]; // 标签唯一标识符,用于多语言环境下的标签路由
category?: string | string[];
categoryId?: string[] | string; // 分类唯一标识符,用于多语言环境下的分类路由
readingTime?: number;
readTime?: string; // Alternative field name for reading time
}
/**
* 技能项接口
*/
export interface SkillItem {
name: string;
icon: string; // skillicons icon name
}
/**
* 个人信息接口
*/
export interface PersonalInfo {
name: string;
location: string;
avatar: string;
email: string;
github: string;
linkedin: string;
website: string;
twitter: string;
position: LocalizedText;
description: LocalizedText;
about: {
[K in Lang]: string[];
};
stats: {
repositories: number;
commits: string;
contributions: number;
};
skills: {
frontend: string[];
backend: string[];
database: string[];
devops: string[];
mobile: string[];
};
terminal: {
username: string;
};
}
/**
* 组件 Props 接口
*/
/**
* 作者卡片组件 Props
*/
export interface AuthorCardProps {
lang: Lang;
author?: Author;
}
/**
* 分享按钮组件 Props
*/
export interface ShareButtonsProps {
lang: Lang;
title: string;
url?: string;
}
/**
* 页脚组件 Props
*/
export interface FooterProps {
lang?: Lang;
}
/**
* 玻璃标题组件 Props
*/
export interface GlassHeaderProps {
lang: Lang;
}
/**
* 博客列表组件 Props
*/
export interface BlogListProps {
posts: BlogPost[];
lang: Lang;
baseUrl?: string; // Base URL for blog posts, defaults to '/blog/posts/'
}
/**
* 语言切换器组件 Props
*/
export interface LanguageSwitcherProps {
lang: Lang;
}
// Re-export all type modules
export * from './data';
export * from './i18n';
export * from './blog';
export * from './components';