-
Notifications
You must be signed in to change notification settings - Fork 140
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
Conversation
frontend/routes/index.tsx
Outdated
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a try
catch
around this and set posts
to []
if this fails? That way if deno.com
goes down, this landing page does not :)
Also can you add a if (jsrPosts.ok)
check in there to check we didn't get a 404 / 500 or something.
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 comment
The 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 .ok
, do we?
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.
I mean if !jsrPosts.ok
then also set posts = []
(ie not call jsrPosts.json()
, as it's almost certainly going to fail anyway)
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.
So just wrap the posts = await jsrPosts.json() as Post[];
in an if (jsrPosts.ok)
frontend/routes/index.tsx
Outdated
title: string; | ||
description: string; | ||
image: string; | ||
url: string; |
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, not url
. Fixed now. 👍
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.
LGTM
Now that there's a JSON API for Deno blog posts that allows us to filter by tags, we can pull in the three latest JSR blog posts and display them on the JSR homepage.
NOTE: because of CORS, this won't work locally. The images will load properly once live, however. (You can run your own
dotcom
locally, update its_middleware.ts
file to allow your local JSR domain, and replace all image URLs to point to your local dotcom localhost domain instead ofdeno.com
to verify.)