Skip to content

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

Merged
merged 8 commits into from
May 10, 2024
Merged

Pull in latest JSR posts to homepage #496

merged 8 commits into from
May 10, 2024

Conversation

josh-collinsworth
Copy link
Contributor

@josh-collinsworth josh-collinsworth commented May 9, 2024

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 of deno.com to verify.)

image

Comment on lines 273 to 274
const jsrPosts = await fetch("https://deno.com/blog/json?tag=JSR");
const posts = await jsrPosts.json() as Post[];
Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Member

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)

Copy link
Member

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)

title: string;
description: string;
image: string;
url: string;
Copy link
Member

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 😅

Copy link
Contributor Author

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. 👍

Copy link
Member

@lucacasonato lucacasonato left a comment

Choose a reason for hiding this comment

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

LGTM

@lucacasonato lucacasonato added this pull request to the merge queue May 10, 2024
Merged via the queue into main with commit ec084e4 May 10, 2024
8 checks passed
@lucacasonato lucacasonato deleted the joco/news branch May 10, 2024 18:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants