|
1 | | -import { BLOG } from '../../../config.mjs' |
2 | | - |
3 | | -import { cleanSlug } from '../../../utils/permalinks' |
4 | | -import { getPosts } from '../../../utils/blog' |
5 | | -import { PostCard } from '../../components/blog/PostCard' |
6 | | -import type { Author, BlogPost } from '@/types' |
7 | | -import Image from 'next/image' |
8 | | -import { FaGithub, FaLink, FaLinkedin, FaOrcid, FaTwitter } from 'react-icons/fa/index' |
9 | | -import { EmailRevealButton } from '../../components/client/EmailRevealButton' |
10 | | -import { createMetadata } from 'apps/next-blog/src/utils/createMetadata' |
11 | | -import { getPerson } from 'apps/next-blog/src/utils/person' |
12 | | -import { Metadata } from 'next' |
| 1 | +import { createMetadata } from "apps/next-blog/src/utils/createMetadata"; |
| 2 | +import { getPerson } from "apps/next-blog/src/utils/person"; |
| 3 | +import type { Metadata } from "next"; |
| 4 | +import Image from "next/image"; |
| 5 | +import { |
| 6 | + FaGithub, |
| 7 | + FaLink, |
| 8 | + FaLinkedin, |
| 9 | + FaOrcid, |
| 10 | + FaTwitter, |
| 11 | +} from "react-icons/fa6"; |
| 12 | +import type { Author, BlogPost } from "@/types"; |
| 13 | +import { BLOG } from "../../../config.mjs"; |
| 14 | +import { getPosts } from "../../../utils/blog"; |
| 15 | +import { cleanSlug } from "../../../utils/permalinks"; |
| 16 | +import { PostCard } from "../../components/blog/PostCard"; |
| 17 | +import { EmailRevealButton } from "../../components/client/EmailRevealButton"; |
13 | 18 |
|
14 | 19 | export async function generateStaticParams() { |
15 | | - if (BLOG?.disabled || BLOG?.author?.disabled) return [] |
| 20 | + if (BLOG?.disabled || BLOG?.author?.disabled) return []; |
16 | 21 |
|
17 | | - const posts = await getPosts() |
| 22 | + const posts = await getPosts(); |
18 | 23 |
|
19 | | - const authors: Record<string, Author> = Object.fromEntries( |
20 | | - posts |
21 | | - .flatMap((post) => [...(post.blog_authors ?? []), ...(post.team_members ?? [])]) |
22 | | - .map((author) => [author.lastName, author]), |
23 | | - ) |
| 24 | + const authors: Record<string, Author> = Object.fromEntries( |
| 25 | + posts |
| 26 | + .flatMap((post) => [ |
| 27 | + ...(post.blog_authors ?? []), |
| 28 | + ...(post.team_members ?? []), |
| 29 | + ]) |
| 30 | + .map((author) => [author.lastName, author]), |
| 31 | + ); |
24 | 32 |
|
25 | | - return Object.entries(authors).map(([lastName, author]) => |
26 | | - posts |
27 | | - .filter((post) => |
28 | | - [...(post.blog_authors ?? []), ...(post.team_members ?? [])].some( |
29 | | - (a: Author) => a.lastName === lastName, |
30 | | - ), |
31 | | - ) |
32 | | - .map((author) => ({ |
33 | | - slug: author.slug ?? cleanSlug(lastName ?? ''), |
34 | | - })), |
35 | | - ) |
| 33 | + return Object.entries(authors).map(([lastName, author]) => |
| 34 | + posts |
| 35 | + .filter((post) => |
| 36 | + [...(post.blog_authors ?? []), ...(post.team_members ?? [])].some( |
| 37 | + (a: Author) => a.lastName === lastName, |
| 38 | + ), |
| 39 | + ) |
| 40 | + .map((author) => ({ |
| 41 | + slug: author.slug ?? cleanSlug(lastName ?? ""), |
| 42 | + })), |
| 43 | + ); |
36 | 44 | } |
37 | 45 |
|
38 | 46 | export async function generateMetadata({ |
39 | | - params, |
| 47 | + params, |
40 | 48 | }: { |
41 | | - params: { slug: string } |
| 49 | + params: { slug: string }; |
42 | 50 | }): Promise<Metadata> { |
43 | | - const author = await getPerson(params.slug) |
44 | | - if (!author) { |
45 | | - return createMetadata() |
46 | | - } |
| 51 | + const author = await getPerson(params.slug); |
| 52 | + if (!author) { |
| 53 | + return createMetadata(); |
| 54 | + } |
47 | 55 |
|
48 | | - return createMetadata({ |
49 | | - title: `${author.firstName} ${author.lastName}`, |
50 | | - description: author.summary?.replace(/<[^>]*?>/gm, '') ?? '', |
51 | | - canonical: `/author/${params.slug}`, |
52 | | - image: `${process.env.OG_URL}/api/og/person?author=${author.slug}${ |
53 | | - 'azureId' in author ? '' : `&guest=true` |
54 | | - }`, |
55 | | - }) |
| 56 | + return createMetadata({ |
| 57 | + title: `${author.firstName} ${author.lastName}`, |
| 58 | + description: author.summary?.replace(/<[^>]*?>/gm, "") ?? "", |
| 59 | + canonical: `/author/${params.slug}`, |
| 60 | + image: `${process.env.OG_URL}/api/og/person?author=${author.slug}${ |
| 61 | + "azureId" in author ? "" : `&guest=true` |
| 62 | + }`, |
| 63 | + }); |
56 | 64 | } |
57 | 65 |
|
58 | | -export default async function AuthorPage({ params }: { params: { slug: string } }) { |
59 | | - const author = await getPerson(params.slug) |
60 | | - if (!author) { |
61 | | - return <div>Author not found</div> |
62 | | - } |
| 66 | +export default async function AuthorPage({ |
| 67 | + params, |
| 68 | +}: { |
| 69 | + params: { slug: string }; |
| 70 | +}) { |
| 71 | + const author = await getPerson(params.slug); |
| 72 | + |
| 73 | + console.log(author); |
| 74 | + if (!author) { |
| 75 | + return <div>Author not found</div>; |
| 76 | + } |
63 | 77 |
|
64 | | - return ( |
65 | | - <article className="mx-auto scroll-m-14 px-6 py-12 sm:px-6 sm:py-16 lg:py-20"> |
66 | | - <header> |
67 | | - <h1 className="leading-tighter font-heading mb-8 text-center text-4xl font-bold tracking-tighter md:mb-16 md:text-5xl"> |
68 | | - <span> |
69 | | - {author.firstName} {author.lastName} |
70 | | - </span> |
71 | | - </h1> |
72 | | - </header> |
73 | | - {'show_pronouns' in author && author.show_pronouns && ( |
74 | | - <p className="text-center text-3xl text-orange-500 dark:text-gray-400 md:text-4xl"> |
75 | | - {author.pronouns} |
76 | | - </p> |
77 | | - )} |
78 | | - <div className="mx-auto mb-20 flex max-w-4xl flex-col items-center"> |
79 | | - {author.image?.url && ( |
80 | | - <Image |
81 | | - src={author.image?.url} |
82 | | - alt={author.image?.alt} |
83 | | - width={author.image?.width} |
84 | | - height={author.image?.height} |
85 | | - className="mx-auto h-40 w-40 rounded-full border-2 border-black object-cover md:h-60 md:w-60" |
86 | | - /> |
87 | | - )} |
| 78 | + return ( |
| 79 | + <article className="mx-auto scroll-m-14 px-6 py-12 sm:px-6 sm:py-16 lg:py-20"> |
| 80 | + <header> |
| 81 | + <h1 className="leading-tighter font-heading mb-8 text-center text-4xl font-bold tracking-tighter md:mb-16 md:text-5xl"> |
| 82 | + <span> |
| 83 | + {author.firstName} {author.lastName} |
| 84 | + </span> |
| 85 | + </h1> |
| 86 | + </header> |
| 87 | + {"show_pronouns" in author && author.show_pronouns && ( |
| 88 | + <p className="text-center text-3xl text-orange-500 dark:text-gray-400 md:text-4xl"> |
| 89 | + {author.pronouns} |
| 90 | + </p> |
| 91 | + )} |
| 92 | + <div className="mx-auto mb-20 flex max-w-4xl flex-col items-center"> |
| 93 | + {author.image?.url && ( |
| 94 | + <Image |
| 95 | + src={author.image?.url} |
| 96 | + alt={author.image?.alt} |
| 97 | + width={author.image?.width} |
| 98 | + height={author.image?.height} |
| 99 | + className="mx-auto h-40 w-40 rounded-full border-2 border-black object-cover md:h-60 md:w-60" |
| 100 | + /> |
| 101 | + )} |
88 | 102 |
|
89 | | - <div className="my-6 flex flex-col items-center justify-center"> |
90 | | - {'position' in author && author.position && ( |
91 | | - <p className="md:text-2x text-center text-xl text-black dark:text-gray-400"> |
92 | | - {author.position} |
93 | | - </p> |
94 | | - )} |
| 103 | + <div className="my-6 flex flex-col items-center justify-center"> |
| 104 | + {"position" in author && author.position && ( |
| 105 | + <p className="md:text-2x text-center text-xl text-black dark:text-gray-400"> |
| 106 | + {author.position} |
| 107 | + </p> |
| 108 | + )} |
95 | 109 |
|
96 | | - <div className="col-span-4 row-span-1 flex flex-wrap items-center justify-center gap-1 leading-none"> |
97 | | - {author.orcid && ( |
98 | | - <a href={author.orcid} className="button-sleek flex items-center text-black"> |
99 | | - <FaOrcid className="h-5 w-5" /> |
100 | | - <span className="sr-only">ORCID</span> |
101 | | - </a> |
102 | | - )} |
103 | | - {author.twitter && ( |
104 | | - <a href={author.twitter} className="button-sleek z-10 flex items-center"> |
105 | | - <FaTwitter className="h-5 w-5" /> |
106 | | - <span className=" sr-only absolute">Twitter</span> |
107 | | - </a> |
108 | | - )} |
109 | | - {author.github && ( |
110 | | - <a href={author.github} className="button-sleek z-10 flex items-center gap-1"> |
111 | | - <FaGithub className="h-5 w-5" /> |
112 | | - <span className="sr-only">Github</span> |
113 | | - </a> |
114 | | - )} |
115 | | - {'linkedIn' in author && author.linkedIn && ( |
116 | | - <a href={author.linkedIn} className="button-sleek z-10 flex items-center gap-1"> |
117 | | - <FaLinkedin className="h-5 w-5" /> |
118 | | - <span className="sr-only">LinkedIn</span> |
119 | | - </a> |
120 | | - )} |
121 | | - {author.personalWebsite && ( |
122 | | - <a |
123 | | - href={author.personalWebsite} |
124 | | - className="button-sleek z-10 flex items-center gap-1" |
125 | | - > |
126 | | - <FaLink className="h-5 w-5" /> |
127 | | - <span className="sr-only">Website</span> |
128 | | - </a> |
129 | | - )} |
130 | | - {author.email && ( |
131 | | - <div className="button-sleek z-10 flex items-center gap-1"> |
132 | | - <EmailRevealButton |
133 | | - classNameIcon="h-5 w-5" |
134 | | - classNameRevealed="underline font-semibold" |
135 | | - email={author.email} |
136 | | - /> |
137 | | - </div> |
138 | | - )} |
139 | | - </div> |
140 | | - </div> |
141 | | - <div |
142 | | - className="prose" |
143 | | - dangerouslySetInnerHTML={{ __html: author.summary || author.bio || '' }} |
144 | | - /> |
145 | | - </div> |
146 | | - <div className="mx-auto flex max-w-4xl flex-col gap-6"> |
147 | | - <h2 className="md:text-4x text-2xl font-bold"> |
148 | | - Posts by {author.firstName} {author.lastName} |
149 | | - </h2> |
150 | | - {author?.blog_posts?.map((post) => ( |
151 | | - <PostCard wide post={post as BlogPost} key={(post as BlogPost).id} /> |
152 | | - ))} |
153 | | - </div> |
154 | | - </article> |
155 | | - ) |
| 110 | + <div className="col-span-4 row-span-1 flex flex-wrap items-center justify-center gap-1 leading-none"> |
| 111 | + {author.orcid && ( |
| 112 | + <a |
| 113 | + href={author.orcid} |
| 114 | + className="button-sleek flex items-center text-black" |
| 115 | + > |
| 116 | + <FaOrcid className="h-5 w-5" /> |
| 117 | + <span className="sr-only">ORCID</span> |
| 118 | + </a> |
| 119 | + )} |
| 120 | + {author.bluesky && ( |
| 121 | + <a |
| 122 | + href={author.bluesky} |
| 123 | + className="button-sleek z-10 flex items-center" |
| 124 | + > |
| 125 | + <FaTwitter className="h-5 w-5" /> |
| 126 | + <span className=" sr-only absolute">Twitter</span> |
| 127 | + </a> |
| 128 | + )} |
| 129 | + {author.github && ( |
| 130 | + <a |
| 131 | + href={author.github} |
| 132 | + className="button-sleek z-10 flex items-center gap-1" |
| 133 | + > |
| 134 | + <FaGithub className="h-5 w-5" /> |
| 135 | + <span className="sr-only">Github</span> |
| 136 | + </a> |
| 137 | + )} |
| 138 | + {"linkedIn" in author && author.linkedIn && ( |
| 139 | + <a |
| 140 | + href={author.linkedIn} |
| 141 | + className="button-sleek z-10 flex items-center gap-1" |
| 142 | + > |
| 143 | + <FaLinkedin className="h-5 w-5" /> |
| 144 | + <span className="sr-only">LinkedIn</span> |
| 145 | + </a> |
| 146 | + )} |
| 147 | + {author.personalWebsite && ( |
| 148 | + <a |
| 149 | + href={author.personalWebsite} |
| 150 | + className="button-sleek z-10 flex items-center gap-1" |
| 151 | + > |
| 152 | + <FaLink className="h-5 w-5" /> |
| 153 | + <span className="sr-only">Website</span> |
| 154 | + </a> |
| 155 | + )} |
| 156 | + {author.email && ( |
| 157 | + <div className="button-sleek z-10 flex items-center gap-1"> |
| 158 | + <EmailRevealButton |
| 159 | + classNameIcon="h-5 w-5" |
| 160 | + classNameRevealed="underline font-semibold" |
| 161 | + email={author.email} |
| 162 | + /> |
| 163 | + </div> |
| 164 | + )} |
| 165 | + </div> |
| 166 | + </div> |
| 167 | + <div |
| 168 | + className="prose" |
| 169 | + dangerouslySetInnerHTML={{ |
| 170 | + __html: author.summary || author.bio || "", |
| 171 | + }} |
| 172 | + /> |
| 173 | + </div> |
| 174 | + <div className="mx-auto flex max-w-4xl flex-col gap-6"> |
| 175 | + <h2 className="md:text-4x text-2xl font-bold"> |
| 176 | + Posts by {author.firstName} {author.lastName} |
| 177 | + </h2> |
| 178 | + {author?.blog_posts?.map((post) => ( |
| 179 | + <PostCard wide post={post as BlogPost} key={(post as BlogPost).id} /> |
| 180 | + ))} |
| 181 | + </div> |
| 182 | + </article> |
| 183 | + ); |
156 | 184 | } |
0 commit comments