11'use client' ;
22
33import 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' ;
57import { useRef } from 'react' ;
68
79import 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' ;
916import { useSiteNavigation } from '#site/hooks/generic' ;
1017import { 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
1222import type { NavigationKeys } from '#site/types' ;
1323import type { RichTranslationValues } from 'next-intl' ;
@@ -21,24 +31,29 @@ type WithSidebarProps = {
2131const 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
0 commit comments