Skip to content

Commit

Permalink
Merge pull request #15 from KokiSakano/fix/blog
Browse files Browse the repository at this point in the history
ブログのレスポンシブ対応リファクタ
  • Loading branch information
k35o authored Jun 23, 2023
2 parents b1ded3f + e90c0ed commit cf4207b
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 32 deletions.
72 changes: 51 additions & 21 deletions src/app/blog/components/blog-card/blog-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,65 @@ export const BlogCard = <T extends string>({
title,
tags,
}: {
link: Route<T>;
link: string;
emotion: string;
title: string;
tags: [string?, string?, string?, string?, string?];
}) => {
const isExternal = link.startsWith('http');
return (
<section className="h-40 rounded-md bg-white shadow-md">
<Link href={link}>
<div className="flex gap-6 p-4">
<div className="flex h-32 w-32 shrink-0 items-center justify-center rounded-md bg-gray-200 text-7xl">
{emotion}
{isExternal ? (
<a href={link} target="_blank" rel="noopener noreferrer">
<div className="flex gap-6 p-4">
<div className="flex h-32 w-32 shrink-0 items-center justify-center rounded-md bg-gray-200 text-7xl">
{emotion}
</div>
<div className="flex w-full flex-col justify-around">
<h3 className="line-clamp-3 text-2xl font-medium">
{title}
</h3>
{tags.length > 0 && (
<div className="hidden justify-end gap-2 md:flex">
{tags.map((tag) => {
if (!tag) {
return null;
}
return <TextTag key={tag} text={tag} />;
})}
</div>
)}
</div>
</div>
<div className="flex w-full flex-col justify-around">
<h3 className="line-clamp-3 text-2xl font-medium">
{title}
</h3>
{tags.length > 0 && (
<div className="hidden justify-end gap-2 md:flex">
{tags.map((tag) => {
if (!tag) {
return null;
}
return <TextTag key={tag} text={tag} />;
})}
</div>
)}
</a>
) : (
<Link
href={link as Route<T>}
target="_blank"
rel="noopener noreferrer"
>
<div className="flex gap-6 p-4">
<div className="flex h-32 w-32 shrink-0 items-center justify-center rounded-md bg-gray-200 text-7xl">
{emotion}
</div>
<div className="flex w-full flex-col justify-around">
<h3 className="line-clamp-3 text-2xl font-medium">
{title}
</h3>
{tags.length > 0 && (
<div className="hidden justify-end gap-2 md:flex">
{tags.map((tag) => {
if (!tag) {
return null;
}
return <TextTag key={tag} text={tag} />;
})}
</div>
)}
</div>
</div>
</div>
</Link>
</Link>
)}
</section>
);
};
29 changes: 19 additions & 10 deletions src/components/anchor/anchor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,25 @@ export const Anchor = ({
children: ReactNode;
}) => {
const isExternal = href.startsWith('http');
const Component = isExternal ? 'a' : Link;
return (
<Component
className="cursor-pointer text-blue-600 hover:underline"
// TODO: 手動キャストせずに判別できる方法が出たら直す
href={href as Route}
target={isExternal ? '_blank' : undefined}
rel={isExternal ? 'noopener noreferrer' : undefined}
>
{children}
</Component>
<>
{isExternal ? (
<a
href={href}
target="_blank"
rel="noopener noreferrer"
className="cursor-pointer text-blue-600 hover:underline"
>
{children}
</a>
) : (
<Link
href={href as Route}
className="cursor-pointer text-blue-600 hover:underline"
>
{children}
</Link>
)}
</>
);
};
5 changes: 4 additions & 1 deletion src/mdx-components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ export function useMDXComponents(
},
pre: ({ children, ...rest }) => {
return (
<pre {...rest} className="my-4 rounded-xl bg-slate-900 p-4">
<pre
{...rest}
className="my-4 overflow-x-auto rounded-xl bg-slate-900 p-4"
>
{children}
</pre>
);
Expand Down

1 comment on commit cf4207b

@vercel
Copy link

@vercel vercel bot commented on cf4207b Jun 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

k8o – ./

k8o-kokisakano.vercel.app
k8o.vercel.app
k8o-git-main-kokisakano.vercel.app

Please sign in to comment.