Skip to content

Commit

Permalink
Improve link block preview
Browse files Browse the repository at this point in the history
  • Loading branch information
cdedreuille committed Jul 3, 2024
1 parent 65be10d commit d8310ea
Show file tree
Hide file tree
Showing 4 changed files with 232 additions and 7 deletions.
19 changes: 12 additions & 7 deletions apps/frontpage/app/blog/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,18 @@ export default async function Page({ params: { slug } }: PageProps) {
...,
authors[]->,
tags[]->,
body[]{..., post-> {
mainImage,
title,
slug,
subtitle,
authors[]->
}},
body[]{
...,
_type == 'post-block' => {
post-> {
mainImage,
title,
slug,
subtitle,
authors[]->
}
}
},
'prev': *[_type == 'post' && !(_id in path('drafts.**')) && _createdAt < ^._createdAt]{..., authors[]->} | order(_createdAt desc)[0..2],
'next': *[_type == 'post' && !(_id in path('drafts.**')) && _createdAt > ^._createdAt]{..., authors[]->} | order(_createdAt desc)[0..2]
}`,
Expand Down
31 changes: 31 additions & 0 deletions apps/frontpage/components/blog/body.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { YoutubePlayer } from './youtube-player';
import Link from 'next/link';
import Image from 'next/image';
import { ArrowRightIcon } from '@storybook/icons';
import urlMetadata from 'url-metadata';

const builder = imageUrlBuilder(client);

Expand Down Expand Up @@ -179,6 +180,36 @@ ${props.value.code}
</Link>
);
},
'link-block': async ({ value }) => {
const url = value.url;
const metadata = await urlMetadata(url);

return (
<a
href={url}
target="_blank"
rel="noreferrer noopener"
className="flex items-stretch w-full gap-8 p-4 my-8 transition-colors border rounded border-zinc-300 hover:border-blue-500 dark:border-slate-700"
>
<div className="w-full">
<Link href={url} className="block mb-4 font-bold text-md">
{metadata?.title}
</Link>
<div className="flex items-center gap-2 text-blue-500">
Read more <ArrowRightIcon className="text-blue-500" />
</div>
</div>
<div className="relative flex-grow flex-shrink-0 min-h-full w-52 bg-slate-100">
{metadata?.['og:image'] && (
<img
src={metadata['og:image']}
className="object-cover w-full h-full rounded"
/>
)}
</div>
</a>
);
},
},
};

Expand Down
1 change: 1 addition & 0 deletions apps/frontpage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"tailwindcss-animate": "^1.0.7",
"tar": "^6.2.0",
"unified": "^11.0.4",
"url-metadata": "^4.1.1",
"zod": "^3.23.8"
},
"devDependencies": {
Expand Down
188 changes: 188 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d8310ea

Please sign in to comment.