Skip to content
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

Port /blog to App router; add blog preview cards [#134] #1059

Merged
merged 7 commits into from
Nov 15, 2024

Conversation

genehack
Copy link
Contributor

@genehack genehack commented Oct 31, 2024

Description of proposed changes

This ports the /blog and /blog/[id] pages to App Router. It also adds metadata to blog posts, including OpenGraph tags, to support preview cards. Finally, it updates the marked Markdown parser to the current release, in order to get type support, and adds the @types/sanitize-html dev dependency to provide type support for sanitize-html.

Note that this code is on top of, and includes, the changes from #1032; when that is merged, I will rebase this on top of it. This is rebased and ready to review.

Related issue(s)

Checklist

@nextstrain-bot nextstrain-bot temporarily deployed to nextstrain-s-add-blog-p-ky3afp October 31, 2024 19:04 Inactive
@genehack genehack force-pushed the add-blog-preview-cards-134 branch from 131c645 to e3d671d Compare October 31, 2024 19:11
@nextstrain-bot nextstrain-bot temporarily deployed to nextstrain-s-add-blog-p-bstxdd October 31, 2024 19:12 Inactive
@genehack genehack force-pushed the add-blog-preview-cards-134 branch from e3d671d to 94cae8d Compare November 1, 2024 18:27
@genehack genehack temporarily deployed to nextstrain-s-add-blog-p-bstxdd November 1, 2024 18:27 Inactive
@genehack genehack marked this pull request as ready for review November 1, 2024 18:33
Copy link
Member

@jameshadfield jameshadfield left a comment

Choose a reason for hiding this comment

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

A couple of comments while trying out the PR. I didn't do a thorough comparison of pages as I think others have done so.

static-site/app/not-found.tsx Outdated Show resolved Hide resolved
static-site/app/whoami/page.tsx Outdated Show resolved Hide resolved
@genehack genehack force-pushed the add-blog-preview-cards-134 branch from 94cae8d to a960935 Compare November 8, 2024 21:43
@genehack genehack temporarily deployed to nextstrain-s-add-blog-p-bstxdd November 8, 2024 21:43 Inactive
@genehack genehack force-pushed the add-blog-preview-cards-134 branch from a960935 to 9e5c3bb Compare November 8, 2024 23:07
@genehack genehack temporarily deployed to nextstrain-s-add-blog-p-bstxdd November 8, 2024 23:07 Inactive
Copy link
Contributor

@joverlee521 joverlee521 left a comment

Choose a reason for hiding this comment

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

I only did a quick review in the test app, I didn't dig into specifics. Really love the new layout of the blog page!

I only flagged a weird behavior in loading images when redirecting from the main /blog page to the most recent blog post.

Comment on lines +12 to +16
const redirectTo = mostRecentPost
? `/blog/${mostRecentPost.blogUrlName}`
: `/404`;

redirect(redirectTo);
Copy link
Contributor

Choose a reason for hiding this comment

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

The images of the most recent blog fail to load when going to /blog, but load fine at /blog/2024-10-22-oropouche-analysis-and-resources

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, i see that.

seems to be because the image URLs are relative to /blog (i.e., img/foo.png, not /blog/img/foo.png), maybe? The images are showing as 404 and the HTTP request was GET /img/oropouche_host_view.png.

oddly, it works fine on localhost... I will dig into the redirect() API and see if I need to do something different, but an initial fix might be tweaking the image URLs in the Oropouche post.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So, yeah, this is because of how the redirect() API works, apparently.

I think I'm going to take this as the push from the universe to move ahead with converting the front page to be the five most recent blog posts, which will require some additional refactoring in this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the end, because of how Next.JS generates URLs without trailing slashes, I had to update the blog image URLs; there was no other way to resolve this (not without other knock-on damage that would have been worse).

So the "multiple pages on the front page" thing will get kicked down the road a bit, and this PR is once again ready to be reviewed.

Note that I also added a section to the static-site README with some minimal info about blog post creation.

static-site/app/blog/[id]/page.tsx Show resolved Hide resolved
package.json Show resolved Hide resolved
static-site/app/blog/utils.ts Show resolved Hide resolved
The need for this update was mainly to get type information for
`marked`; version 14.1.3 was current on the day when I made this
change. (The library releases and updates versions _frequently_.)

I did not carefully review the five years worth of changelogs between
0.7 and 14.1.3, but empirically the API doesn't seem to have changed
and the code still works.
Deletes old Pages Router blog files, as well as displayMarkdown
component.
…URLs [#134]

* Prepend `/blog/` to all blog post image URLs
* Remove `https://nextstrain.org` from link URLs
@genehack genehack force-pushed the add-blog-preview-cards-134 branch from 9e5c3bb to c2cf130 Compare November 15, 2024 00:21
@genehack genehack temporarily deployed to nextstrain-s-add-blog-p-bstxdd November 15, 2024 00:21 Inactive
@genehack genehack temporarily deployed to nextstrain-s-add-blog-p-bstxdd November 15, 2024 17:52 Inactive
@genehack genehack merged commit 5503367 into master Nov 15, 2024
7 checks passed
@genehack genehack deleted the add-blog-preview-cards-134 branch November 15, 2024 18:26
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.

Add Open Graph and Twitter Card meta tags for rich embeds/previews
5 participants