Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ exports[`Blog/BlogCard Default smoke-test 1`] = `
</div>
<div class="BlogCard_content__jnh1D">
<h4>
April 21, 2023
21 April 2023
</h4>
<p>
by
Expand Down
14 changes: 14 additions & 0 deletions components/Common/Time/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import type { FC } from 'react';
import { FormattedDate } from 'react-intl';

type TimeProps = { date: string | Date; format: Intl.DateTimeFormatOptions };

export const Time: FC<TimeProps> = ({ date, format }) => {
const dateObject = new Date(date);

return (
<time dateTime={dateObject.toISOString()}>
<FormattedDate value={dateObject} {...format} timeZone="UTC" />
</time>
);
};
2 changes: 1 addition & 1 deletion i18n/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"name": "English",
"langDir": "ltr",
"dateFormat": "MM.DD.YYYY",
"hrefLang": "en-US",
"hrefLang": "en-GB",
"enabled": true,
"default": true
},
Expand Down
12 changes: 5 additions & 7 deletions layouts/BlogIndexLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useMemo } from 'react';
import { FormattedMessage } from 'react-intl';
import BaseLayout from './BaseLayout';
import { Time } from '../components/Common/Time';
import Pagination from '../components/Pagination';
import LocalizedLink from '../components/LocalizedLink';
import { useBlogData } from '../hooks/useBlogData';
Expand Down Expand Up @@ -39,13 +40,10 @@ const BlogIndexLayout: FC<PropsWithChildren> = ({ children }) => {
<ul className="blog-index">
{posts.map((post: BlogPost) => (
<li key={post.slug}>
<time dateTime={post.date}>
{new Date(post.date).toLocaleString('en-GB', {
timeZone: 'UTC',
month: 'short',
day: '2-digit',
})}
</time>
<Time
date={post.date}
format={{ month: 'short', day: '2-digit' }}
/>

<LocalizedLink href={post.slug}>{post.title}</LocalizedLink>
</li>
Expand Down
13 changes: 5 additions & 8 deletions layouts/BlogPostLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { FormattedMessage } from 'react-intl';
import BaseLayout from './BaseLayout';
import { Time } from '../components/Common/Time';
import { useLayoutContext } from '../hooks/useLayoutContext';
import type { FC, PropsWithChildren } from 'react';
import type { LegacyBlogFrontMatter } from '../types';
Expand All @@ -21,14 +22,10 @@ const BlogPostLayout: FC<PropsWithChildren> = ({ children }) => {
values={{ author: author || null }}
/>

<time dateTime={date}>
{new Date(date).toLocaleString('en-GB', {
timeZone: 'UTC',
month: 'short',
day: '2-digit',
year: 'numeric',
})}
</time>
<Time
date={date}
format={{ month: 'short', day: '2-digit', year: 'numeric' }}
/>
</span>
</div>

Expand Down
12 changes: 5 additions & 7 deletions layouts/CategoryIndexLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useMemo } from 'react';
import BaseLayout from './BaseLayout';
import { Time } from '../components/Common/Time';
import LocalizedLink from '../components/LocalizedLink';
import { useLayoutContext } from '../hooks/useLayoutContext';
import { useBlogData } from '../hooks/useBlogData';
Expand All @@ -23,13 +24,10 @@ const CategoryIndexLayout: FC<PropsWithChildren> = ({ children }) => {
<ul className="blog-index">
{posts.map((post: BlogPost) => (
<li key={post.slug}>
<time dateTime={post.date}>
{new Date(post.date).toLocaleString('en-GB', {
timeZone: 'UTC',
month: 'short',
day: '2-digit',
})}
</time>
<Time
date={post.date}
format={{ month: 'short', day: '2-digit' }}
/>

<LocalizedLink href={post.slug}>{post.title}</LocalizedLink>
</li>
Expand Down
191 changes: 156 additions & 35 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion providers/localeProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const LocaleProvider: FC<PropsWithChildren> = ({ children }) => {
return (
<LocaleContext.Provider value={localeData}>
<IntlProvider
locale={localeData.currentLocale.code}
locale={localeData.currentLocale.hrefLang}
messages={localeData.localeMessages}
onError={() => null}
>
Expand Down