forked from facebook/docusaurus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.tsx
155 lines (145 loc) · 4.33 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import React from 'react';
import clsx from 'clsx';
import Link from '@docusaurus/Link';
import {FooterLinkItem, useThemeConfig} from '@docusaurus/theme-common';
import useBaseUrl from '@docusaurus/useBaseUrl';
import isInternalUrl from '@docusaurus/isInternalUrl';
import styles from './styles.module.css';
import ThemedImage, {Props as ThemedImageProps} from '@theme/ThemedImage';
import IconExternalLink from '@theme/IconExternalLink';
function FooterLink({
to,
href,
label,
prependBaseUrlToHref,
...props
}: FooterLinkItem) {
const toUrl = useBaseUrl(to);
const normalizedHref = useBaseUrl(href, {forcePrependBaseUrl: true});
return (
<Link
className="footer__link-item"
{...(href
? {
href: prependBaseUrlToHref ? normalizedHref : href,
}
: {
to: toUrl,
})}
{...props}>
{href && !isInternalUrl(href) ? (
<span>
{label}
<IconExternalLink />
</span>
) : (
label
)}
</Link>
);
}
const FooterLogo = ({
sources,
alt,
width,
height,
}: Pick<ThemedImageProps, 'sources' | 'alt' | 'width' | 'height'>) => (
<ThemedImage
className="footer__logo"
alt={alt}
sources={sources}
width={width}
height={height}
/>
);
function Footer(): JSX.Element | null {
const {footer} = useThemeConfig();
const {copyright, links = [], logo = {}} = footer || {};
const sources = {
light: useBaseUrl(logo.src),
dark: useBaseUrl(logo.srcDark || logo.src),
};
if (!footer) {
return null;
}
return (
<footer
className={clsx('footer', {
'footer--dark': footer.style === 'dark',
})}>
<div className="container">
{links && links.length > 0 && (
<div className="row footer__links">
{links.map((linkItem, i) => (
<div key={i} className="col footer__col">
{linkItem.title != null ? (
<div className="footer__title">{linkItem.title}</div>
) : null}
{linkItem.items != null &&
Array.isArray(linkItem.items) &&
linkItem.items.length > 0 ? (
<ul className="footer__items">
{linkItem.items.map((item, key) =>
item.html ? (
<li
key={key}
className="footer__item"
// Developer provided the HTML, so assume it's safe.
// eslint-disable-next-line react/no-danger
dangerouslySetInnerHTML={{
__html: item.html,
}}
/>
) : (
<li key={item.href || item.to} className="footer__item">
<FooterLink {...item} />
</li>
),
)}
</ul>
) : null}
</div>
))}
</div>
)}
{(logo || copyright) && (
<div className="footer__bottom text--center">
{logo && (logo.src || logo.srcDark) && (
<div className="margin-bottom--sm">
{logo.href ? (
<Link href={logo.href} className={styles.footerLogoLink}>
<FooterLogo
alt={logo.alt}
sources={sources}
width={logo.width}
height={logo.height}
/>
</Link>
) : (
<FooterLogo alt={logo.alt} sources={sources} />
)}
</div>
)}
{copyright ? (
<div
className="footer__copyright"
// Developer provided the HTML, so assume it's safe.
// eslint-disable-next-line react/no-danger
dangerouslySetInnerHTML={{
__html: copyright,
}}
/>
) : null}
</div>
)}
</div>
</footer>
);
}
export default Footer;