refactor(types): centralize type definitions in shared types file

Move all interface and type definitions to src/types/index.ts to reduce code duplication and improve maintainability. This includes types for components, blog posts, personal info, and localization.
This commit is contained in:
joyzhao
2025-06-19 11:26:47 +08:00
parent acd0fa4bb9
commit 25281f4459
15 changed files with 180 additions and 91 deletions

158
src/types/index.ts Normal file
View File

@@ -0,0 +1,158 @@
/**
* 集中管理项目中的类型定义
* 这个文件包含了项目中常用的接口和类型定义,减少代码冗余和提高可维护性
*/
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[];
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[];
category?: 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;
}