-
-
Notifications
You must be signed in to change notification settings - Fork 753
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Innei <i@innei.in>
- Loading branch information
Showing
17 changed files
with
239 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { dehydrate } from '@tanstack/react-query' | ||
import type { Metadata } from 'next' | ||
|
||
import { QueryHydrate } from '~/components/common/QueryHydrate' | ||
import { NormalContainer } from '~/components/layout/container/Normal' | ||
import { isShallowEqualArray } from '~/lib/_' | ||
import { attachUA } from '~/lib/attach-ua' | ||
import { getQueryClient } from '~/utils/query-client.server' | ||
|
||
import { getPageBySlugQuery } from './query' | ||
|
||
export const generateMetadata = async ( | ||
props: NextPageParams<{ | ||
slug: string | ||
}>, | ||
) => { | ||
attachUA() | ||
const queryClient = getQueryClient() | ||
|
||
const query = getPageBySlugQuery(props.params.slug) | ||
|
||
const data = await queryClient.fetchQuery(query) | ||
|
||
return { | ||
title: `分类 · ${data.name}`, | ||
} satisfies Metadata | ||
} | ||
export default async function Layout( | ||
props: NextPageParams<{ | ||
slug: string | ||
}>, | ||
) { | ||
attachUA() | ||
const queryClient = getQueryClient() | ||
const query = getPageBySlugQuery(props.params.slug) | ||
const queryKey = query.queryKey | ||
await queryClient.fetchQuery(query) | ||
return ( | ||
<QueryHydrate | ||
state={dehydrate(queryClient, { | ||
shouldDehydrateQuery: (query) => { | ||
// @ts-expect-error | ||
return isShallowEqualArray(query.queryKey, queryKey) | ||
}, | ||
})} | ||
> | ||
<NormalContainer>{props.children}</NormalContainer> | ||
</QueryHydrate> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
'use client' | ||
|
||
import { useQuery } from '@tanstack/react-query' | ||
import Link from 'next/link' | ||
import { useParams } from 'next/navigation' | ||
|
||
import { TimelineList } from '~/components/ui/list/TimelineList' | ||
import { BottomToUpSoftScaleTransitionView } from '~/components/ui/transition/BottomToUpSoftScaleTransitionView' | ||
import { BottomToUpTransitionView } from '~/components/ui/transition/BottomToUpTransitionView' | ||
|
||
import { getPageBySlugQuery } from './query' | ||
|
||
export default function Page() { | ||
const { slug } = useParams() | ||
const { data } = useQuery({ | ||
...getPageBySlugQuery(slug), | ||
enabled: false, | ||
}) | ||
if (!data) throw new Error('data is lost :(') | ||
const { name, children } = data | ||
|
||
return ( | ||
<BottomToUpSoftScaleTransitionView> | ||
<header className="prose"> | ||
<h1>分类 - {name}</h1> | ||
|
||
<h3 className="font-light"> | ||
{children.length | ||
? `当前共有 ${children.length} 篇文章,加油!` | ||
: `这里还有没有内容呢,再接再厉!`} | ||
</h3> | ||
</header> | ||
|
||
<main className="mt-10 text-zinc-950/80 dark:text-zinc-50/80"> | ||
<TimelineList> | ||
{children.map((child, i) => { | ||
const date = new Date(child.created) | ||
|
||
return ( | ||
<BottomToUpTransitionView | ||
key={child.id} | ||
delay={700 + 50 * i} | ||
as="li" | ||
className="flex min-w-0 items-center justify-between leading-loose" | ||
> | ||
<Link | ||
prefetch={false} | ||
target="_blank" | ||
href={`/posts/${slug}/${child.slug}`} | ||
className="min-w-0 truncate" | ||
> | ||
{child.title} | ||
</Link> | ||
<span className="meta"> | ||
{(date.getMonth() + 1).toString().padStart(2, '0')}/ | ||
{date.getDate().toString().padStart(2, '0')}/ | ||
{date.getFullYear()} | ||
</span> | ||
</BottomToUpTransitionView> | ||
) | ||
})} | ||
</TimelineList> | ||
</main> | ||
</BottomToUpSoftScaleTransitionView> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { defineQuery } from '~/queries/helper' | ||
import { apiClient } from '~/utils/request' | ||
|
||
export const getPageBySlugQuery = (slug: string) => | ||
defineQuery({ | ||
queryKey: ['category', slug], | ||
queryFn: async ({ queryKey }) => { | ||
const [, slug] = queryKey | ||
|
||
const data = await apiClient.category.getCategoryByIdOrSlug(slug) | ||
|
||
return { | ||
...data, | ||
} | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +0,0 @@ | ||
.timeline { | ||
position: relative; | ||
|
||
@apply min-w-0 flex-1 list-inside justify-between; | ||
|
||
& > li::before { | ||
content: ''; | ||
position: absolute; | ||
left: -1.05rem; | ||
bottom: 0; | ||
border-left: 1px solid theme(colors.accent); | ||
} | ||
|
||
& > li:first-child:last-child::before { | ||
border-left: 0; | ||
} | ||
|
||
& > li:not(:first-child):not(:last-child)::before { | ||
top: 0; | ||
} | ||
|
||
& > li:first-child::before { | ||
top: 50%; | ||
} | ||
|
||
& > li:last-child::before { | ||
bottom: 50%; | ||
top: 0; | ||
} | ||
|
||
& > li { | ||
position: relative; | ||
list-style-type: none; | ||
|
||
line-height: 1.6; | ||
padding: 3px 0; | ||
margin: 0 0 0 1rem; | ||
} | ||
|
||
& > li::after { | ||
content: ''; | ||
left: -1.28rem; | ||
top: 50%; | ||
transform: translateY(-50%); | ||
height: 0.5rem; | ||
width: 0.5rem; | ||
border-radius: 50%; | ||
position: absolute; | ||
background-color: theme(colors.accent); | ||
} | ||
} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
import clsx from 'clsx' | ||
|
||
import styles from './TimelineList.module.css' | ||
|
||
export const TimelineList: Component = ({ children, className }) => { | ||
return <ul className={clsx(styles['timeline'], className)}>{children}</ul> | ||
return <ul className={clsx('shiro-timeline', className)}>{children}</ul> | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ | |
@import './clerk.css'; | ||
@import './image-zoom.css'; | ||
@import './toastify.css'; | ||
@import './theme.css'; |
Oops, something went wrong.