1
1
import React from 'react'
2
- import { Box , Octicon } from '@primer/react'
2
+ import { Box , Octicon , Avatar , Text , Tooltip } from '@primer/react'
3
3
import { PencilIcon } from '@primer/octicons-react'
4
4
import Link from './link'
5
- import Contributors from './contributors'
6
5
import usePage from '../hooks/use-page'
7
6
8
- function PageFooter ( ) {
7
+ const months = [
8
+ 'January' ,
9
+ 'February' ,
10
+ 'March' ,
11
+ 'April' ,
12
+ 'May' ,
13
+ 'June' ,
14
+ 'July' ,
15
+ 'August' ,
16
+ 'September' ,
17
+ 'October' ,
18
+ 'November' ,
19
+ 'December' ,
20
+ ]
21
+
22
+ const format = d => `${ months [ d . getMonth ( ) ] } ${ d . getDate ( ) } , ${ d . getFullYear ( ) } `
23
+
24
+ const pluralize = ( word , count ) => `${ word } ${ count === 1 ? '' : 's' } `
25
+
26
+ const Contributors = ( { contributors = [ ] , latestCommit} ) => {
27
+ if ( ! contributors . length ) {
28
+ return null
29
+ }
30
+
31
+ return (
32
+ < div >
33
+ < Box sx = { { display : 'flex' , alignItems : 'center' } } >
34
+ < Text sx = { { mr : 2 } } >
35
+ { contributors . length } { pluralize ( 'contributor' , contributors . length ) }
36
+ </ Text >
37
+ { contributors . map ( login => (
38
+ < Tooltip key = { login } aria-label = { login } >
39
+ < Link href = { `https://github.com/${ login } ` } sx = { { lineHeight : 'condensedUltra' , mr : 2 } } >
40
+ < Avatar src = { `https://github.com/${ login } .png?size=40` } alt = { login } />
41
+ </ Link >
42
+ </ Tooltip >
43
+ ) ) }
44
+ </ Box >
45
+ { latestCommit ? (
46
+ < Text sx = { { fontSize : 1 , color : 'fg.muted' , mt : 1 } } >
47
+ Last edited by < Link href = { `https://github.com/${ latestCommit . login } ` } > { latestCommit . login } </ Link > on{ ' ' }
48
+ < Link href = { latestCommit . url } > { format ( new Date ( latestCommit . date ) ) } </ Link >
49
+ </ Text >
50
+ ) : null }
51
+ </ div >
52
+ )
53
+ }
54
+
55
+ const PageFooter = ( ) => {
9
56
const { editUrl, latestCommit, contributors = [ ] } = usePage ( ) . pageContext
10
- return editUrl || contributors . length ? (
57
+
58
+ if ( ! editUrl && ! contributors . length ) {
59
+ return null
60
+ }
61
+
62
+ return (
11
63
< Box
12
64
sx = { {
13
65
borderWidth : 0 ,
@@ -26,10 +78,10 @@ function PageFooter() {
26
78
Edit this page on GitHub
27
79
</ Link >
28
80
) : null }
29
- { contributors . length ? < Contributors contributors = { contributors } latestCommit = { latestCommit } /> : null }
81
+ < Contributors contributors = { contributors } latestCommit = { latestCommit } />
30
82
</ Box >
31
83
</ Box >
32
- ) : null
84
+ )
33
85
}
34
86
35
87
export default PageFooter
0 commit comments