-
Notifications
You must be signed in to change notification settings - Fork 138
Pull in latest JSR posts to homepage #496
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
d98f543
efb1fa8
09b5ca5
a2f1c49
76dcca1
e093f79
20800d3
da1ed33
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright 2024 the JSR authors. All rights reserved. MIT license. | ||
export function NewsCard({ | ||
title, | ||
description, | ||
image, | ||
url, | ||
}: { | ||
title: string; | ||
description: string; | ||
image: string; | ||
url: string; | ||
}) { | ||
return ( | ||
<li class="group border-1.5 border-jsr-cyan-950 rounded list-none overflow-hidden hover:border-jsr-cyan-400 focus-within:border-jsr-cyan-400 transition-colors duration-150"> | ||
<a | ||
href={url} | ||
class="h-full flex flex-col justify-stretch cursor-pointer" | ||
tabIndex={0} | ||
> | ||
<img | ||
src={image} | ||
crossOrigin={"anonymous"} | ||
alt="" | ||
class="w-full h-48 object-cover border-b-1.5 border-jsr-cyan-950 group-hover:border-jsr-cyan-400 group-focus-within:border-jsr-cyan-400 transition-colors duration-150" | ||
/> | ||
<div class="p-4 flex flex-grow flex-col gap-4"> | ||
<h3 class="text-xl lg:text-2xl font-semibold !leading-tight text-balance"> | ||
{title} | ||
</h3> | ||
<p class="text-sm"> | ||
{description} | ||
</p> | ||
</div> | ||
</a> | ||
</li> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,9 +9,18 @@ import { Head } from "$fresh/runtime.ts"; | |
import { ComponentChildren } from "preact"; | ||
import { HomepageHero } from "../components/HomepageHero.tsx"; | ||
import { Logo } from "../components/Logo.tsx"; | ||
import { NewsCard } from "../components/NewsCard.tsx"; | ||
|
||
interface Post { | ||
title: string; | ||
description: string; | ||
image: string; | ||
url: string; | ||
} | ||
|
||
interface Data { | ||
stats: Stats; | ||
posts: Post[]; | ||
} | ||
|
||
export default function Home({ data }: PageProps<Data>) { | ||
|
@@ -32,17 +41,47 @@ export default function Home({ data }: PageProps<Data>) { | |
apiKey={Deno.env.get("ORAMA_PACKAGE_PUBLIC_API_KEY")} | ||
indexId={Deno.env.get("ORAMA_PACKAGE_PUBLIC_INDEX_ID")} | ||
/> | ||
<div class="grid grid-cols-1 gap-8 lg:grid-cols-3"> | ||
<ListPanel title="Featured Packages"> | ||
{data.stats.featured.map(PackageToPanelEntry)} | ||
</ListPanel> | ||
<ListPanel title="Recent updates"> | ||
{data.stats.updated.map(PackageVersionToPanelEntry)} | ||
</ListPanel> | ||
<ListPanel title="New Packages"> | ||
{data.stats.newest.map(PackageToPanelEntry)} | ||
</ListPanel> | ||
</div> | ||
|
||
{data.posts?.length && ( | ||
<section class="flex flex-col gap-4 mb-16 md:mb-32"> | ||
<h2 class="text-3xl md:text-4xl mb-4 md:mb-8 font-semibold text-center"> | ||
Latest updates | ||
</h2> | ||
<ul class="grid grid-cols-1 md:grid-cols-3 gap-4 md:gap-8"> | ||
{data?.posts?.slice(0, 3).map((post) => ( | ||
<NewsCard | ||
image={post.image} | ||
title={post.title} | ||
description={post.description} | ||
url={post.url} | ||
/> | ||
))} | ||
</ul> | ||
<a | ||
href="https://deno.com/blog?tag=jsr" | ||
class="underline block mt-4 w-full text-center" | ||
> | ||
More JSR updates <span aria-hidden="true">›</span> | ||
</a> | ||
</section> | ||
)} | ||
|
||
<section class="flex flex-col gap-4"> | ||
<h2 class="text-3xl md:text-4xl mb-4 md:mb-8 font-semibold text-center"> | ||
Packages | ||
</h2> | ||
<div class="grid grid-cols-1 gap-8 lg:grid-cols-3"> | ||
<ListPanel title="Featured"> | ||
{data.stats.featured.map(PackageToPanelEntry)} | ||
</ListPanel> | ||
<ListPanel title="Recently updated"> | ||
{data.stats.updated.map(PackageVersionToPanelEntry)} | ||
</ListPanel> | ||
<ListPanel title="New to JSR"> | ||
{data.stats.newest.map(PackageToPanelEntry)} | ||
</ListPanel> | ||
</div> | ||
</section> | ||
|
||
<h2 | ||
class="font-semibold text-5xl md:text-7xl lg:text-center mt-16 md:mt-24 lg:mt-48 lg:mb-16" | ||
|
@@ -231,8 +270,11 @@ export const handler: Handlers<Data, State> = { | |
const statsResp = await ctx.state.api.get<Stats>(path`/stats`, undefined, { | ||
anonymous: true, | ||
}); | ||
const jsrPosts = await fetch("https://deno.com/blog/json?tag=JSR"); | ||
const posts = await jsrPosts.json() as Post[]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a Also can you add a Also I'll add some caching to this call in a follow up. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @lucacasonato I agree with the try/catch safety, but I don't think we want to do anything different if the request fails; just render the rest of the page without the posts. So I don't think we need to check for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mean if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So just wrap the |
||
|
||
if (!statsResp.ok) throw statsResp; // gracefully handle this | ||
return ctx.render({ stats: statsResp.data }, { | ||
return ctx.render({ stats: statsResp.data, posts: posts || [] }, { | ||
headers: ctx.state.api.hasToken() | ||
? undefined | ||
: { "Cache-Control": "public, s-maxage=60" }, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be undefined. I can't actually click on the cards 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops, we call it
link
on dotcom, noturl
. Fixed now. 👍