Skip to content

Commit

Permalink
Merge pull request #555 from MH4GF/renew-article-list
Browse files Browse the repository at this point in the history
renew article list
  • Loading branch information
MH4GF authored Dec 22, 2024
2 parents 9b74e09 + ce68dbd commit 3401d92
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 60 deletions.
22 changes: 0 additions & 22 deletions app/(pages)/articles/page.tsx

This file was deleted.

12 changes: 8 additions & 4 deletions app/_features/articles/ArticleList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ export const ArticleList = ({ tag }: Props): JSX.Element => {
const articlesMeta = getArticlesMeta({ tag });

return (
<div className="grid gap-12">
{articlesMeta.map((article) => (
<ArticleListItem key={article.title} {...article} />
))}
<div className="blur-enter-content">
<h1 className="text-xl">All Writing</h1>

<div className="mt-12 grid gap-6 blur-enter-content enter-step-80">
{articlesMeta.map((article) => (
<ArticleListItem key={article.title} {...article} />
))}
</div>
</div>
);
};
26 changes: 11 additions & 15 deletions app/_features/articles/ArticleListItem.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ExternalLinkIcon, Time } from "../../_components";
import { MoveUpRight } from "lucide-react";
import { Time } from "../../_components";
import { format } from "../../_utils";
import { UniversalLink } from "../viewTransition";

import { Tag } from "./Tag";
import type { ArticleMeta } from "./type";

type Props = ArticleMeta;
Expand All @@ -12,26 +12,22 @@ export const ArticleListItem = ({
href,
externalLink,
publishedAt: _publishedAt,
tags,
}: Props) => {
const publishedAt = format(_publishedAt);

return (
<article className="grid gap-4">
<h2 className="text-xl">
<UniversalLink href={href} isExternal={externalLink} isEnabledUnderline>
<article className="flex gap-2 items-center justify-between">
<h2 className="text-base font-normal">
<UniversalLink href={href} isExternal={externalLink} isEnabledHoveredUnderline>
{title}
{externalLink && <ExternalLinkIcon />}
{externalLink && (
<MoveUpRight className="mb-[-3px] ml-0.5 inline-block h-4 w-auto align-top text-zinc-500 dark:text-zinc-400" />
)}
</UniversalLink>
</h2>
<div className="flex justify-between">
<div className="flex gap-2">
{tags.map((tag) => (
<Tag key={tag} tag={tag} />
))}
</div>
<Time dateTime={publishedAt}>{publishedAt}</Time>
</div>
<Time dateTime={publishedAt} className="shrink-0">
{publishedAt}
</Time>
</article>
);
};
10 changes: 2 additions & 8 deletions app/_features/articles/Tag.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { UniversalLink } from "../viewTransition";

import { tagLabelMap } from "./constants";
import type { TagEnum } from "./type";

Expand All @@ -11,12 +9,8 @@ export const Tag = ({ tag }: Props) => {
const label = tagLabelMap[tag];

return (
<UniversalLink
href={`/articles/tags/${tag}`}
isEnabledUnderline
className="rounded-sm border border-zinc-200 px-1 py-0.5 text-xs text-zinc-500 dark:hover:text-zinc-500 dark:text-zinc-400 hover:text-zinc-700"
>
<span className="rounded-sm border border-zinc-600 px-1 py-0.5 text-xs text-zinc-500">
{label}
</UniversalLink>
</span>
);
};
17 changes: 15 additions & 2 deletions app/_features/viewTransition/UniversalLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,27 @@ import { isSameOrigin } from "./isSameOrigin";
const animatedUnderline =
"no-underline transition-colors duration-300 border-b border-solid border-zinc-200 hover:border-zinc-500 dark:border-zinc-700 dark:hover:border-zinc-500";

const hoveredUnderline =
"no-underline hover:border-b hover:border-solid hover:border-zinc-200 dark:hover:border-zinc-700";

type Props = LinkProps & {
isExternal?: boolean;
isEnabledUnderline?: boolean;
isEnabledHoveredUnderline?: boolean;
};

export const UniversalLink = forwardRef<HTMLAnchorElement, Props>(
({ isExternal, isEnabledUnderline = false, className: _className, ...props }: Props, ref) => {
const className = `${_className || ""} ${isEnabledUnderline ? animatedUnderline : ""}`;
(
{
isExternal,
isEnabledUnderline = false,
isEnabledHoveredUnderline = false,
className: _className,
...props
}: Props,
ref,
) => {
const className = `${_className || ""} ${isEnabledUnderline ? animatedUnderline : isEnabledHoveredUnderline ? hoveredUnderline : ""}`;

if (isExternal || !isSameOrigin(props.href)) {
return (
Expand Down
4 changes: 2 additions & 2 deletions app/articles/[slug]/__tests__/page.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ test.describe("Command Palette", () => {
await page.getByRole("option", { name: "All Writing" }).click();

await expect(page.getByRole("dialog")).not.toBeVisible();
await expect(page.getByRole("heading", { name: "Articles RSS" })).toBeVisible();
await expect(page.getByRole("heading", { name: "All Writing" })).toBeVisible();
});

test("Navigate to `Source of this site` on another tab", async ({ page }) => {
Expand All @@ -63,7 +63,7 @@ test.describe("Command Palette", () => {
await page.keyboard.press("Enter");

await expect(page.getByRole("dialog")).not.toBeVisible();
await expect(page.getByRole("heading", { name: "Articles RSS" })).toBeVisible();
await expect(page.getByRole("heading", { name: "All Writing" })).toBeVisible();
});

test("Navigate to `Source of this site` with Enter key", async ({ page }) => {
Expand Down
8 changes: 1 addition & 7 deletions app/articles/[slug]/_features/ArticleMetaDetail.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import Image from "next/image";

import { MyAvatar, Time } from "@/app/_components";
import { Tag } from "@/app/_features";
import { format } from "@/app/_utils";
import type { Article } from "contentlayer/generated";
import type { FC } from "react";
Expand All @@ -11,7 +10,7 @@ interface Props {
}

export const ArticleMetaDetail: FC<Props> = ({
article: { headingImage, title, publishedAt: _publishedAt, tags },
article: { headingImage, title, publishedAt: _publishedAt },
}) => {
const publishedAt = format(new Date(_publishedAt));

Expand Down Expand Up @@ -45,11 +44,6 @@ export const ArticleMetaDetail: FC<Props> = ({
<span className="text-sm text-foreground-sub leading-none">5 min read</span>
</div>
</div>
<div className="mt-4 md:mt-8 flex justify-center gap-2">
{tags.map((tag) => (
<Tag key={tag} tag={tag} />
))}
</div>
</div>
);
};
15 changes: 15 additions & 0 deletions app/articles/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type { Metadata } from "next";

import { ArticleList } from "../_features";

export default function Page() {
return (
<main className="max-w-3xl mx-auto py-16 md:py-32 px-4 md:px-0">
<ArticleList />
</main>
);
}

export const metadata: Metadata = {
title: "Articles",
};
4 changes: 4 additions & 0 deletions app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@
animation-delay: calc(var(--enter-initial) + var(--enter-stage) * var(--enter-step));
}

.blur-enter-content.enter-step-80 > * {
--enter-step: 80ms;
}

.blur-enter-content > *:nth-child(1) {
--enter-stage: 1;
}
Expand Down

0 comments on commit 3401d92

Please sign in to comment.