Skip to content

Commit 3c58f92

Browse files
committed
feat(ui): remove meta bar
1 parent 7228f53 commit 3c58f92

File tree

22 files changed

+259
-652
lines changed

22 files changed

+259
-652
lines changed

apps/site/components/withLayout.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
import AboutLayout from '#site/layouts/About';
2-
import ArticlePageLayout from '#site/layouts/ArticlePage';
31
import BlogLayout from '#site/layouts/Blog';
4-
import DefaultLayout from '#site/layouts/Default';
2+
import DefaultLayout, {
3+
AboutPageLayout,
4+
LearnPageLayout,
5+
} from '#site/layouts/Default';
56
import DownloadLayout from '#site/layouts/Download';
67
import DownloadArchiveLayout from '#site/layouts/DownloadArchive';
78
import GlowingBackdropLayout from '#site/layouts/GlowingBackdrop';
8-
import LearnLayout from '#site/layouts/Learn';
99
import PostLayout from '#site/layouts/Post';
1010

1111
import type { Layouts } from '#site/types';
1212
import type { FC, PropsWithChildren } from 'react';
1313

1414
const layouts = {
15-
about: AboutLayout,
15+
about: AboutPageLayout,
1616
home: GlowingBackdropLayout,
17-
learn: LearnLayout,
17+
learn: LearnPageLayout,
1818
page: DefaultLayout,
1919
'blog-post': PostLayout,
2020
'blog-category': BlogLayout,
2121
download: DownloadLayout,
2222
'download-archive': DownloadArchiveLayout,
23-
article: ArticlePageLayout,
23+
article: DefaultLayout,
2424
} satisfies Record<Layouts, FC>;
2525

2626
type WithLayoutProps<L = Layouts> = PropsWithChildren<{ layout: L }>;

apps/site/components/withMetaBar.tsx

Lines changed: 0 additions & 81 deletions
This file was deleted.

apps/site/components/withSidebar.tsx

Lines changed: 83 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
'use client';
22

33
import Sidebar from '@node-core/ui-components/Containers/Sidebar';
4-
import { useTranslations } from 'next-intl';
4+
import GitHubIcon from '@node-core/ui-components/Icons/Social/GitHub';
5+
import { defaultLocale } from '@node-core/website-i18n';
6+
import { useFormatter, useLocale, useTranslations } from 'next-intl';
57
import { useRef } from 'react';
68

79
import Link from '#site/components/Link';
8-
import { useClientContext, useScrollToElement } from '#site/hooks/client';
10+
import WithAvatarGroup from '#site/components/withAvatarGroup';
11+
import {
12+
useClientContext,
13+
useScrollToElement,
14+
useMediaQuery,
15+
} from '#site/hooks/client';
916
import { useSiteNavigation } from '#site/hooks/generic';
1017
import { useRouter, usePathname } from '#site/navigation.mjs';
18+
import { DEFAULT_DATE_FORMAT } from '#site/next.calendar.constants.mjs';
19+
import { TRANSLATION_URL } from '#site/next.constants.mjs';
20+
import { getGitHubBlobUrl } from '#site/util/github';
1121

1222
import type { NavigationKeys } from '#site/types';
1323
import type { RichTranslationValues } from 'next-intl';
@@ -21,24 +31,29 @@ type WithSidebarProps = {
2131
const WithSidebar: FC<WithSidebarProps> = ({ navKeys, context, ...props }) => {
2232
const { getSideNavigation } = useSiteNavigation();
2333
const pathname = usePathname()!;
34+
const locale = useLocale();
2435
const t = useTranslations();
36+
const formatter = useFormatter();
2537
const { push } = useRouter();
26-
const { frontmatter } = useClientContext();
38+
const { frontmatter, readingTime, filename } = useClientContext();
2739
const sidebarRef = useRef<HTMLElement>(null);
28-
const sideNavigation = getSideNavigation(navKeys, context);
2940

30-
// Preserve sidebar scroll position across navigations
3141
useScrollToElement('sidebar', sidebarRef);
3242

33-
const mappedSidebarItems =
34-
// If there's only a single navigation key, use its sub-items
35-
// as our navigation.
36-
(navKeys.length === 1 ? sideNavigation[0][1].items : sideNavigation).map(
37-
([, { label, items }]) => ({
38-
groupName: label,
39-
items: items.map(([, item]) => item),
40-
})
41-
);
43+
const sideNavigation = getSideNavigation(navKeys, context);
44+
const mappedSidebarItems = (
45+
navKeys.length === 1 ? sideNavigation[0][1].items : sideNavigation
46+
).map(([, { label, items }]) => ({
47+
groupName: label,
48+
items: items.map(([, item]) => item),
49+
}));
50+
51+
const usernames =
52+
frontmatter.authors?.split(',').map(author => author.trim()) ?? [];
53+
const isMobileResolution = useMediaQuery('(max-width: 670px)');
54+
const isTabletResolution = useMediaQuery(
55+
'(min-width: 670px) and (max-width: 1280px)'
56+
);
4257

4358
return (
4459
<Sidebar
@@ -50,7 +65,60 @@ const WithSidebar: FC<WithSidebarProps> = ({ navKeys, context, ...props }) => {
5065
onSelect={push}
5166
as={Link}
5267
{...props}
53-
/>
68+
>
69+
<dl>
70+
{frontmatter.date && (
71+
<>
72+
<dt>{t('components.common.sidebar.lastUpdated')}</dt>
73+
<dd>
74+
{formatter.dateTime(
75+
new Date(frontmatter.date),
76+
DEFAULT_DATE_FORMAT
77+
)}
78+
</dd>
79+
</>
80+
)}
81+
82+
<dt>{t('components.common.sidebar.readingTime')}</dt>
83+
<dd>
84+
{formatter.number(readingTime.minutes, {
85+
style: 'unit',
86+
unit: 'minute',
87+
maximumFractionDigits: 0,
88+
})}
89+
</dd>
90+
91+
{usernames.length > 0 && (
92+
<>
93+
<dt>
94+
{t(
95+
`components.common.sidebar.${usernames.length > 1 ? 'authors' : 'author'}`
96+
)}
97+
</dt>
98+
<dd>
99+
<WithAvatarGroup
100+
usernames={usernames}
101+
limit={isMobileResolution ? 7 : isTabletResolution ? 5 : 9}
102+
/>
103+
</dd>
104+
</>
105+
)}
106+
107+
<dt>{t('components.common.sidebar.contribute')}</dt>
108+
<dd>
109+
<GitHubIcon className="fill-neutral-700 dark:fill-neutral-100" />
110+
<Link
111+
href={
112+
locale === defaultLocale.code
113+
? getGitHubBlobUrl(filename)
114+
: TRANSLATION_URL
115+
}
116+
>
117+
{t('components.common.sidebar.contributeText')}
118+
</Link>
119+
</dd>
120+
</dl>
121+
</Sidebar>
54122
);
55123
};
56124

apps/site/components/withTOC.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import TableOfContents from '@node-core/ui-components/Common/TableOfContents';
2+
import { useTranslations } from 'next-intl';
3+
4+
import type { FC } from 'react';
5+
6+
import { useClientContext } from '../hooks/server';
7+
8+
const WithTOC: FC = () => {
9+
const { headings } = useClientContext();
10+
const t = useTranslations();
11+
12+
return (
13+
<TableOfContents
14+
headings={headings}
15+
summaryTitle={t('components.common.onThisPage')}
16+
/>
17+
);
18+
};
19+
20+
export default WithTOC;

apps/site/layouts/About.tsx

Lines changed: 0 additions & 33 deletions
This file was deleted.

apps/site/layouts/ArticlePage.tsx

Lines changed: 0 additions & 30 deletions
This file was deleted.

apps/site/layouts/Default.tsx

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,59 @@
11
import Article from '@node-core/ui-components/Containers/Article';
22

3+
import WithBreadcrumbs from '#site/components/withBreadcrumbs';
34
import WithFooter from '#site/components/withFooter';
45
import WithNavBar from '#site/components/withNavBar';
56
import WithSidebar from '#site/components/withSidebar';
7+
import WithSidebarCrossLinks from '#site/components/withSidebarCrossLinks';
8+
import WithTOC from '#site/components/withTOC';
69

10+
import type { NavigationKeys } from '../types';
711
import type { FC, PropsWithChildren } from 'react';
812

9-
const DefaultLayout: FC<PropsWithChildren> = ({ children }) => (
13+
type DefaultLayoutProps = {
14+
navKeys?: Array<NavigationKeys>;
15+
showBreadcrumbs?: boolean;
16+
};
17+
18+
const DefaultLayout: FC<PropsWithChildren<DefaultLayoutProps>> = ({
19+
children,
20+
navKeys = [],
21+
showBreadcrumbs = false,
22+
}) => (
1023
<>
1124
<WithNavBar />
1225

1326
<Article>
14-
<WithSidebar navKeys={[]} />
27+
<WithSidebar navKeys={navKeys} />
1528

1629
<div>
30+
<WithTOC />
31+
1732
<main id="main" tabIndex={-1}>
1833
{children}
1934
</main>
2035
</div>
36+
37+
{showBreadcrumbs && <WithBreadcrumbs navKeys={navKeys} />}
2138
</Article>
2239

2340
<WithFooter />
2441
</>
2542
);
2643

2744
export default DefaultLayout;
45+
46+
export const AboutPageLayout: FC<PropsWithChildren> = props => (
47+
<DefaultLayout
48+
navKeys={['about', 'getInvolved']}
49+
showBreadcrumbs={true}
50+
{...props}
51+
/>
52+
);
53+
54+
export const LearnPageLayout: FC<PropsWithChildren> = ({ children }) => (
55+
<DefaultLayout navKeys={['learn']} showBreadcrumbs={true}>
56+
{children}
57+
<WithSidebarCrossLinks navKey="learn" />
58+
</DefaultLayout>
59+
);

0 commit comments

Comments
 (0)