|
| 1 | +'use client'; |
1 | 2 | import { useFormatter } from 'next-intl'; |
2 | 3 | import type { FC } from 'react'; |
3 | 4 |
|
| 5 | +import AvatarGroup from '@/components/Common/AvatarGroup'; |
4 | 6 | import MetaBar from '@/components/Containers/MetaBar'; |
5 | 7 | import GitHub from '@/components/Icons/Social/GitHub'; |
6 | 8 | import Link from '@/components/Link'; |
7 | | -import { useClientContext } from '@/hooks/server'; |
| 9 | +import { useClientContext } from '@/hooks/react-client'; |
| 10 | +import useMediaQuery from '@/hooks/react-client/useMediaQuery'; |
8 | 11 | import { DEFAULT_DATE_FORMAT } from '@/next.calendar.constants.mjs'; |
9 | | -import { getGitHubBlobUrl } from '@/util/gitHubUtils'; |
| 12 | +import { getGitHubBlobUrl, getGitHubAvatarUrl } from '@/util/gitHubUtils'; |
| 13 | +import { getAcronymFromString } from '@/util/stringUtils'; |
10 | 14 |
|
11 | 15 | const WithMetaBar: FC = () => { |
12 | 16 | const { headings, readingTime, frontmatter, filename } = useClientContext(); |
13 | 17 | const formatter = useFormatter(); |
14 | | - |
15 | 18 | const lastUpdated = frontmatter.date |
16 | 19 | ? formatter.dateTime(new Date(frontmatter.date), DEFAULT_DATE_FORMAT) |
17 | 20 | : undefined; |
18 | 21 |
|
| 22 | + const usernames = |
| 23 | + frontmatter.authors?.split(',').map(author => author.trim()) ?? []; |
| 24 | + const avatars = usernames.map(username => ({ |
| 25 | + src: getGitHubAvatarUrl(username), |
| 26 | + alt: getAcronymFromString(username), |
| 27 | + })); |
| 28 | + |
| 29 | + // Doing that because on mobile list on top of page and on desktop list on the right side |
| 30 | + const shortAvatarList = useMediaQuery( |
| 31 | + '(min-width: 670px) and (max-width: 1280px)' |
| 32 | + ); |
| 33 | + |
19 | 34 | return ( |
20 | 35 | <MetaBar |
21 | 36 | items={{ |
22 | 37 | 'components.metabar.lastUpdated': lastUpdated, |
23 | 38 | 'components.metabar.readingTime': readingTime.text, |
| 39 | + ...(avatars.length && { |
| 40 | + [`components.metabar.${avatars.length > 1 ? 'authors' : 'author'}`]: ( |
| 41 | + <AvatarGroup avatars={avatars} limit={shortAvatarList ? 4 : 8} /> |
| 42 | + ), |
| 43 | + }), |
24 | 44 | 'components.metabar.contribute': ( |
25 | 45 | <> |
26 | 46 | <GitHub className="fill-neutral-700 dark:fill-neutral-100" /> |
|
0 commit comments