Skip to content

Commit 591724e

Browse files
committed
Overlap product updates and blog frontmatter types
1 parent 912be44 commit 591724e

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

packages/web/docs/src/app/blog/blog-types.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
import type { StaticImageData } from 'next/image';
2-
import { AuthorId } from '../../authors';
3-
import { MdxFile, PageMapItem } from '../../mdx-types';
2+
import type { Author, AuthorId } from '../../authors';
3+
import type { MdxFile, PageMapItem } from '../../mdx-types';
4+
5+
type OneOrMany<T> = T | T[];
46

57
export interface BlogFrontmatter {
6-
authors: AuthorId | AuthorId[];
8+
authors: OneOrMany<AuthorId | Author>;
79
title: string;
810
date: string;
911
tags: string | string[];
1012
featured?: boolean;
1113
image?: VideoPath | StaticImageData;
1214
thumbnail?: StaticImageData;
15+
description?: string;
1316
}
1417

1518
type VideoPath = `${string}.${'webm' | 'mp4'}`;

packages/web/docs/src/app/product-updates/(posts)/product-update-header.tsx

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,9 @@ import { format } from 'date-fns';
44
import { Anchor, cn, useConfig } from '@theguild/components';
55
import { AuthorId, authors } from '../../../authors';
66
import { SocialAvatar } from '../../../components/social-avatar';
7+
import { BlogFrontmatter } from '../../blog/blog-types';
78

8-
type Meta = {
9-
authors: AuthorId[];
10-
date: string;
11-
title: string;
12-
description: string;
13-
};
9+
type Meta = Pick<BlogFrontmatter, 'authors' | 'date' | 'title' | 'description'>;
1410

1511
export const ProductUpdateAuthors = ({
1612
meta,
@@ -21,10 +17,15 @@ export const ProductUpdateAuthors = ({
2117
}) => {
2218
const date = meta.date ? new Date(meta.date) : new Date();
2319

24-
if (meta.authors.length === 1) {
25-
const author = authors[meta.authors[0] as AuthorId];
20+
const metaAuthors = (Array.isArray(meta.authors) ? meta.authors : [meta.authors]).map(author => {
21+
return typeof author === 'string' ? authors[author as AuthorId] : author;
22+
});
23+
24+
if (metaAuthors.length === 1) {
25+
const author = metaAuthors[0];
26+
2627
if (!author) {
27-
throw new Error(`Author ${meta.authors[0]} not found`);
28+
throw new Error(`Author ${metaAuthors[0]} not found`);
2829
}
2930

3031
return (
@@ -66,14 +67,9 @@ export const ProductUpdateAuthors = ({
6667
{format(date, 'EEEE, LLL do y')}
6768
</time>
6869
<div className="my-5 flex flex-wrap justify-center gap-5">
69-
{meta.authors.map(authorId => {
70-
const author = authors[authorId as AuthorId];
71-
if (!author) {
72-
throw new Error(`Author ${authorId} not found`);
73-
}
74-
70+
{metaAuthors.map(author => {
7571
return (
76-
<div key={authorId}>
72+
<div key={author.name}>
7773
<Anchor
7874
href={author.link}
7975
title={author.name}

0 commit comments

Comments
 (0)