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

ref: Refactor changelog list page #11019

Merged
merged 10 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/changelog/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"next-auth": "^4.24.5",
"next-mdx-remote": "^4.4.1",
"nextjs-toploader": "^1.6.6",
"nuqs": "^1.17.7",
"prism-sentry": "^1.0.2",
"react": "beta",
"react-dom": "beta",
Expand Down
9 changes: 5 additions & 4 deletions apps/changelog/src/app/changelog/%5Fadmin/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,11 @@ export default async function ChangelogsListPage() {
<span className="text-gray-500">
<Text size="1">
{' '}
{new Date(changelog.publishedAt || '').toLocaleDateString(
undefined,
{month: 'long', day: 'numeric'}
)}
{new Date(changelog.publishedAt || '').toLocaleDateString('en-EN', {
month: 'long',
day: 'numeric',
timeZone: 'UTC',
})}
</Text>
<br />
</span>
Expand Down
50 changes: 32 additions & 18 deletions apps/changelog/src/app/changelog/page.tsx
Original file line number Diff line number Diff line change
@@ -1,38 +1,52 @@
import { Fragment } from "react";
import type { Metadata } from "next";
import { serialize } from "next-mdx-remote/serialize";
import {Fragment} from 'react';
import type {Metadata} from 'next';
import {serialize} from 'next-mdx-remote/serialize';

import Header from "./header";
import { getChangelogs } from "../../server/utils";
import List from "@/client/components/list";
import Header from './header';
import {getChangelogs} from '../../server/utils';
import {ChangelogEntry, ChangelogList} from '@/client/components/list';
import {startSpan} from '@sentry/nextjs';

export const dynamic = "force-dynamic";
export const dynamic = 'force-dynamic';

export default async function ChangelogList() {
export default async function Page() {
const changelogs = await getChangelogs();

const changelogsWithMdxSummaries = await Promise.all(
changelogs.map(async (changelog) => {
const mdxSummary = await serialize(changelog.summary || "");
return {
...changelog,
mdxSummary,
};
})
const changelogsWithPublishedAt = changelogs.filter(changelog => {
return changelog.publishedAt !== null;
});

const changelogsWithMdxSummaries = await startSpan(
{name: 'serialize changelog summaries'},
() =>
Copy link
Member

Choose a reason for hiding this comment

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

good idea!

Promise.all(
changelogsWithPublishedAt.map(async (changelog): Promise<ChangelogEntry> => {
const mdxSummary = await serialize(changelog.summary || '');
return {
id: changelog.id,
title: changelog.title,
slug: changelog.slug,
// Because `getChangelogs` is cached, it sometimes returns its results serialized and sometimes not. Therefore we have to deserialize the string to be able to call toUTCString().
publishedAt: new Date(changelog.publishedAt!).toUTCString(),
categories: changelog.categories,
mdxSummary,
};
})
)
);

return (
<Fragment>
<Header />
<List changelogs={changelogsWithMdxSummaries} />
<ChangelogList changelogs={changelogsWithMdxSummaries} />
</Fragment>
);
}

export function generateMetadata(): Metadata {
return {
description:
"Stay up to date on everything big and small, from product updates to SDK changes with the Sentry Changelog.",
'Stay up to date on everything big and small, from product updates to SDK changes with the Sentry Changelog.',
alternates: {
canonical: `https://sentry.io/changelog/`,
},
Expand Down
6 changes: 3 additions & 3 deletions apps/changelog/src/client/components/article.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {ReactNode} from 'react';
import Tag from './tag';
import { DateComponent } from './date';
import {DateComponent} from './date';
import {CategoryTag} from './tag';

type ArticleProps = {
children?: ReactNode;
Expand Down Expand Up @@ -41,7 +41,7 @@ export default function Article({
<h3 className="text-3xl text-primary font-semibold mb-2">{title}</h3>
<div>
<div className="flex flex-wrap gap-1 py-1">
{Array.isArray(tags) && tags.map(tag => <Tag key={tag} text={tag} />)}
{Array.isArray(tags) && tags.map(tag => <CategoryTag key={tag} text={tag} />)}
</div>

<div className="prose max-w-none text-gray-700 py-2">{children}</div>
Expand Down
5 changes: 2 additions & 3 deletions apps/changelog/src/client/components/date.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
const formatDate = (date: string | Date) => {
const options: Intl.DateTimeFormatOptions = {
const now = new Date(date).toLocaleDateString('en-EN', {
year: 'numeric',
month: 'long',
day: 'numeric',
timeZone: 'UTC'
};
const now = new Date(date).toLocaleDateString('en-EN', options);
});
Comment on lines +2 to +7
Copy link
Member

Choose a reason for hiding this comment

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

l: we could reuse this formatting, or maybe just use day.js?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think this is slimmer for now!


return now;
};
Expand Down
Loading
Loading