Skip to content

Commit f02a728

Browse files
author
521xueweihan
committed
feat: 支持项目名
1 parent e32dcef commit f02a728

File tree

11 files changed

+31
-15
lines changed

11 files changed

+31
-15
lines changed

src/components/home/Item.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ interface ItemProps {
1010
item: {
1111
item_id?: string;
1212
rid?: string;
13+
1314
author_avatar: string;
1415
is_hot?: boolean;
1516
is_featured?: boolean;
@@ -27,6 +28,7 @@ interface ItemProps {
2728
updated_at?: string;
2829
clicks_total?: number;
2930
stars?: number;
31+
full_name?: string;
3032
};
3133
i18n_lang: string;
3234
index?: number;
@@ -65,7 +67,9 @@ const RepositoryItem = ({
6567
} = item;
6668

6769
const isDefaultType = itemType === 'default';
68-
const href = isDefaultType ? `/repository/${item_id}` : `/repository/${rid}`;
70+
const href = isDefaultType
71+
? `/repository/${item.full_name || item_id}`
72+
: `/repository/${item.full_name || rid}`;
6973

7074
// 动态绑定类名
7175
const hoverClassName = `transform shadow-lg transition-transform ${

src/components/periodical/item.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ const PeriodItem: NextPage<PeriodicalItemProps> = ({ item, index }) => {
9191
</div>
9292
</div>
9393
<div className='flex h-14 flex-1 flex-row items-center justify-end pr-1'>
94-
<NoPrefetchLink href={`/repository/${item.rid}`}>
94+
<NoPrefetchLink href={`/repository/${item.full_name}`}>
9595
<Button
9696
variant='white-outline'
9797
className='font-normal text-gray-700'

src/components/respository/Info.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,11 @@ const Info = ({ repo, t, i18n_lang }: RepositoryProps) => {
195195
};
196196

197197
const handleCopy = () => {
198-
const text = `${repo.name}${repo.title.trim()}。\n\n${t(
199-
'info.copy_desc'
200-
)}https://hellogithub.com/repository/${repo.rid}`;
198+
const text = `${repo.name}${
199+
i18n_lang == 'en' ? repo.title_en || repo.title : repo.title
200+
}\n\n${t('info.copy_desc')}https://hellogithub.com/repository/${
201+
repo.full_name
202+
}`;
201203
copy(text)
202204
? Message.success(t('info.copy_success'))
203205
: Message.error(t('info.copy_fail'));

src/components/side/Recommend.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ import { RecommendItem, SideProps } from '@/types/home';
1313
const RecommendList = ({ repositories }: { repositories: RecommendItem[] }) => (
1414
<div className='dark:text-gray-300'>
1515
{repositories.map((item) => (
16-
<Link prefetch={false} href={`/repository/${item.rid}`} key={item.rid}>
16+
<Link
17+
prefetch={false}
18+
href={`/repository/${item.full_name}`}
19+
key={item.rid}
20+
>
1721
<div className='flex cursor-pointer flex-row rounded-md py-2 hover:bg-gray-50 hover:text-blue-400 dark:text-gray-200 dark:hover:bg-gray-700 dark:hover:text-blue-400'>
1822
<div className='flex w-full items-center px-1'>
1923
<img

src/components/user/DynamicRecordList.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const RepoLink: React.FC<{ record: DynamicRecordItem; fallback?: string }> = ({
2626
if (!record) return <>{fallback}</>;
2727

2828
return (
29-
<CustomLink className='inline' href={`/repository/${record.item_id}`}>
29+
<CustomLink className='inline' href={`/repository/${record.full_name}`}>
3030
<span className='mx-1 cursor-pointer text-blue-500'>{record.name}</span>
3131
</CustomLink>
3232
);

src/components/user/RepoRecord.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ const RepoData = ({ data, setPage, showStatus }: RepoDataProps) => {
183183
const router = useRouter();
184184

185185
const onClickRepo = (item: RepoType) => {
186-
router.push(item.is_show ? `/repository/${item.rid}` : item.url);
186+
router.push(item.is_show ? `/repository/${item.full_name}` : item.url);
187187
};
188188

189189
if (!data?.data) return null;

src/pages/notification/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ const Notification = () => {
9696
})}
9797
<CustomLink
9898
className='mx-1 inline cursor-pointer text-blue-500'
99-
href={`/repository/${item.mid}`}
99+
href={`/repository/${item.repository?.full_name}`}
100100
>
101101
{item.repository?.full_name}
102102
</CustomLink>
@@ -117,7 +117,7 @@ const Notification = () => {
117117
{t('reply.desc')}
118118
<CustomLink
119119
className='inline cursor-pointer px-1 text-blue-500'
120-
href={`/repository/${item.repository?.rid}`}
120+
href={`/repository/${item.repository?.full_name}`}
121121
>
122122
{item.repository?.full_name}
123123
</CustomLink>
@@ -136,7 +136,7 @@ const Notification = () => {
136136
{item.more_content ? t('comment.desc') : t('comment.desc')}
137137
<CustomLink
138138
className='inline cursor-pointer px-1 text-blue-500'
139-
href={`/repository/${item.repository?.rid}`}
139+
href={`/repository/${item.repository?.full_name}`}
140140
>
141141
{item.repository?.full_name}
142142
</CustomLink>

src/pages/repository/[rid]/index.tsx renamed to src/pages/repository/[...slug]/index.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,12 @@ export const getServerSideProps: GetServerSideProps = async ({
6060
locale,
6161
}) => {
6262
const ip = getClientIP(req);
63-
const rid = query?.rid as string;
64-
const data = await getDetail(ip, rid);
63+
// 在 [...slug] 路由中,slug 是一个数组
64+
const slug = query?.slug as string[];
65+
const identifier = slug?.join('/') || '';
66+
67+
const data = await getDetail(ip, identifier);
68+
6569
if (data.success) {
6670
return {
6771
props: {

src/services/repository.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ import {
1919

2020
export const getDetail = async (
2121
ip: string,
22-
rid: string
22+
identifier: string
2323
): Promise<RepositorySuccessData> => {
2424
const req: RequestInit = {};
2525
req.headers = { 'x-real-ip': ip, 'x-forwarded-for': ip };
2626
const result = await fetcher<RepositorySuccessData>(
27-
makeUrl(`/repository/detail/${rid}`),
27+
makeUrl(`/repository/detail/${identifier}`),
2828
req
2929
);
3030
return result;

src/types/periodical.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export interface VolumeNum {
2222
export interface PeriodicalItem {
2323
rid: string;
2424
name: string;
25+
full_name: string;
2526
description: string;
2627
description_en: string;
2728
github_url: string;

src/types/user.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ export interface UserDetailInfo {
7070
export interface DynamicRecordItem {
7171
name: string;
7272
item_id: string;
73+
full_name: string;
7374
}
7475

7576
export interface DynamicRecord {

0 commit comments

Comments
 (0)