MCPcopy Index your code
hub / github.com/nodejs/nodejs.org / WithMetaBar

Function WithMetaBar

apps/site/components/withMetaBar.tsx:18–79  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

16import type { FC } from 'react';
17
18const WithMetaBar: FC = () => {
19 const { headings, readingTime, frontmatter, filename } = useClientContext();
20 const formatter = useFormatter();
21 const lastUpdated = frontmatter.date
22 ? // "frontmatter.date" is deterministic
23
24 formatter.dateTime(new Date(frontmatter.date), DEFAULT_DATE_FORMAT)
25 : undefined;
26 const readingTimeText = formatter.number(readingTime.minutes, {
27 style: 'unit',
28 unit: 'minute',
29 maximumFractionDigits: 0,
30 });
31
32 const usernames =
33 frontmatter.authors?.split(',').map(author => author.trim()) ?? [];
34
35 const t = useTranslations();
36 const locale = useLocale();
37
38 // Since we cannot show the same number of avatars in Mobile / Tablet
39 // resolution as we do on desktop and there is overflow, we are adjusting
40 // the number of avatars manually for the resolutions below
41 const isSmallerThanDesktop = useMediaQuery('(max-width: 1280px)');
42
43 return (
44 <MetaBar
45 heading={t('components.metabar.tableOfContents')}
46 as={Link}
47 aria-label={t('components.metabar.metadata')}
48 items={{
49 [t('components.metabar.lastUpdated')]: lastUpdated,
50 [t('components.metabar.readingTime')]: readingTimeText,
51 ...(usernames.length && {
52 [t(
53 `components.metabar.${usernames.length > 1 ? 'authors' : 'author'}`
54 )]: (
55 <WithAvatarGroup
56 usernames={usernames}
57 limit={isSmallerThanDesktop ? 5 : 8}
58 />
59 ),
60 }),
61 [t('components.metabar.contribute')]: (
62 <>
63 <GitHubIcon className="fill-neutral-700 dark:fill-neutral-100" />
64 <Link
65 href={
66 locale === defaultLocale.code
67 ? getGitHubBlobUrl(filename)
68 : TRANSLATION_URL
69 }
70 >
71 {t('components.metabar.contributeText')}
72 </Link>
73 </>
74 ),
75 }}

Callers

nothing calls this directly

Calls 2

getGitHubBlobUrlFunction · 0.90
useMediaQueryFunction · 0.85

Tested by

no test coverage detected