-
-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathpage-settings.tsx
229 lines (207 loc) · 10.2 KB
/
page-settings.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
/********************************************************************************
* Copyright (c) 2020 TypeFox and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
import React, { FunctionComponent, ReactNode, Suspense, lazy } from 'react';
import { Link, Typography, Theme, Box, SxProps } from '@mui/material';
import { Helmet, HelmetTags } from 'react-helmet-async';
import { Link as RouteLink, Route, useParams } from 'react-router-dom';
import { PageSettings, Extension, NamespaceDetails } from 'openvsx-webui';
import { ExtensionListRoutes } from 'openvsx-webui/lib/pages/extension-list/extension-list-container';
import { DefaultMenuContent, MobileMenuContent } from './menu-content';
import InfoIcon from '@mui/icons-material/Info';
import OpenVSXLogo from './openvsx-registry-logo';
import footerContent from './footer-content';
import { Document } from './document';
import About from './about';
import Adopters from './adopters';
import Members from './members';
//---------- HEAD TAGS
const HeadTags: FunctionComponent<{title?: string, description?: string, keywords?: string, url?: string, imageUrl?: string, type?: string}> = (props) => {
const handleChangeClientState = (newState: any, addedTags: HelmetTags, removedTags: HelmetTags): void => {
if (addedTags.metaTags) {
addedTags.metaTags.forEach((value: HTMLMetaElement) => {
if (!value.content) {
value.remove();
}
});
}
};
const twitterCard = props.imageUrl ? 'summary_large_image' : 'summary';
const type = props.type || 'website';
return <Helmet onChangeClientState={handleChangeClientState}>
<title>{props.title}</title>
{/* SEO Meta Tags */}
<meta name='description' content={props.description}/>
<meta name='keywords' content={props.keywords}/>
<meta property='og:url' content={props.url}/>
<meta property='og:type' content={type}/>
<meta property='og:title' content={props.title}/>
<meta property='og:description' content={props.description}/>
<meta property='og:image' content={props.imageUrl}/>
{/* Google Meta Tags */}
<meta itemProp='name' content={props.title}/>
<meta itemProp='description' content={props.description}/>
<meta itemProp='image' content={props.imageUrl}/>
{/* Twitter Meta Tags */}
<meta name='twitter:card' content={twitterCard}/>
<meta name='twitter:title' content={props.title}/>
<meta name='twitter:description' content={props.description}/>
<meta name='twitter:image' content={props.imageUrl}/>
</Helmet>;
};
const MainHeadTags: FunctionComponent<{pageSettings: PageSettings}> = (props) => {
const title = props.pageSettings.pageTitle;
const description = 'Open VSX is an Eclipse open-source project and alternative to the Visual Studio Marketplace. It is deployed by the Eclipse Foundation at open-vsx.org.';
const keywords = 'eclipse,ide,open source,development environment,development,vs code,visual studio code,extension,plugin,plug-in,registry,theia';
const url = `${location.protocol}//${location.host}`;
const imageUrl = url + '/openvsx-preview.png';
return (<HeadTags title={title} description={description} keywords={keywords} url={url} imageUrl={imageUrl}/>);
};
const ExtensionHeadTags: FunctionComponent<{extension?: Extension, pageSettings: PageSettings}> = (props) => {
const { name, namespace } = useParams();
let title = ` – ${props.pageSettings.pageTitle}`;
let url = `${location.protocol}//${location.host}/extension/`;
let description: string | undefined;
let keywords: string | undefined;
if (props.extension) {
title = (props.extension.displayName || props.extension.name) + title;
url += `${props.extension.namespace}/${props.extension.name}`;
description = props.extension.description;
// extension description can be up to 2048 characters, truncate it.
if (description && description.length > 255) {
let lastWordIndex = description.indexOf(' ', 255);
lastWordIndex = lastWordIndex !== -1 ? lastWordIndex - 1 : 255;
description = description.substring(0, lastWordIndex);
}
if (props.extension.tags) {
keywords = props.extension.tags.filter(t => !t.startsWith('__')).join();
}
} else {
title = name + title;
url += `${namespace}/${name}`;
}
return(<HeadTags title={title} url={url} description={description} keywords={keywords}/>)
};
const NamespaceHeadTags: FunctionComponent<{namespaceDetails?: NamespaceDetails, pageSettings: PageSettings}> = (props) => {
const { name } = useParams();
const namespaceName = props.namespaceDetails?.displayName ?? props.namespaceDetails?.name ?? name
const title = `${namespaceName} – ${props.pageSettings.pageTitle}`;
const url = `${location.protocol}//${location.host}/namespace/${namespaceName}`;
const description = props.namespaceDetails?.description
return(<HeadTags title={title} url={url} description={description}/>)
};
export default function createPageSettings(theme: Theme, prefersDarkMode: boolean, serverVersionPromise: Promise<string>): PageSettings {
//---------- SERVER VERSION
const ServerVersion = lazy(async () => {
const version = await serverVersionPromise;
return { default: () => <Typography variant='body2' sx={{ alignSelf: 'flex-start', fontSize: '0.8rem' }}>{version}</Typography> };
});
//---------- MAIN LOGO / TOOLBAR
const toolbarContent: FunctionComponent = () =>
<>
<RouteLink to={ExtensionListRoutes.MAIN} aria-label={`Home - Open VSX Registry`}>
<OpenVSXLogo width='auto' height='40px' marginTop='8px' prefersDarkMode={prefersDarkMode} />
</RouteLink>
<Suspense>
<ServerVersion/>
</Suspense>
</>;
//---------- ANNOUNCEMENT BANNER
const bannerContent: FunctionComponent = () =>
<Box display='flex' alignItems='center' pt={1} pb={1}>
<Box mr={2}>
<InfoIcon fontSize='large' />
</Box>
<Typography variant='body1'>
Open VSX now supports deprecating extensions - see our <Link color='secondary' underline='hover' href="https://blogs.eclipse.org/post/john-kellerman/new-feature-open-vsx-deprecating-extensions">announcement</Link>.
</Typography>
</Box>;
//---------- SEARCH HEADER
const searchHeader: FunctionComponent = () =>
<Typography variant='h4' sx={{ mb: 2, fontWeight: 'fontWeightLight', letterSpacing: 4, textAlign: 'center' }}>
Extensions for VS Code Compatible Editors
</Typography>;
//---------- DOWNLOAD TERMS
const downloadTerms: FunctionComponent = () =>
<Box mt={1}>
<Typography variant='body2'>
By clicking download, you accept this website's
<Link color='secondary' underline='hover' href='https://open-vsx.org/terms-of-use'>
Terms of Use
</Link>.
</Typography>
</Box>;
//---------- ADDITIONAL PAGES
const additionalRoutes: ReactNode = <>
<Route path='/about' element={<About />} />
<Route path='/terms-of-use' element={<Document url='/documents/terms-of-use.md' />} />
<Route path='/publisher-agreement-v1.0' element={<Document url='/documents/publisher-agreement-v1.0.md' />} />
<Route path='/members' element={<Members />} />
<Route path='/adopters' element={<Adopters />} />
</>;
//---------- REPORT ABUSE LINK
const reportAbuse: FunctionComponent<{ extension: Extension, sx: SxProps<Theme> }> = ({ extension, sx }) => {
const reportAbuseText = encodeURIComponent('<Please describe the issue>');
const extensionURL = encodeURIComponent(`${location.protocol}//${location.hostname}/extension/${extension.namespace}/${extension.name}`);
return <Link
href={`mailto:license@eclipse.org?subject=Report%20Abuse%20-%20${extension.namespace}.${extension.name}&Body=${reportAbuseText}%0A%0A${extensionURL}`}
variant='body2' color='secondary' underline='hover' sx={sx} >
Report Abuse
</Link>;
};
//---------- CLAIM NAMESPACE LINK
const claimNamespace: FunctionComponent<{ extension: Extension, sx: SxProps<Theme> }> = ({ sx }) => <Link
href='https://github.com/EclipseFdn/open-vsx.org/issues/new/choose'
target='_blank' variant='body2' color='secondary' underline='hover' sx={sx} >
Claim Ownership
</Link>;
return {
pageTitle: 'Open VSX Registry',
themeType: prefersDarkMode ? 'dark' : 'light',
elements: {
defaultMenuContent: DefaultMenuContent,
mobileMenuContent: MobileMenuContent,
toolbarContent,
banner: {
content: bannerContent,
props: {
dismissButton: {
show: true,
label: 'Got It'
},
color: 'info'
},
cookie: {
key: 'Extension-Deprecation',
value: 'closed',
path: '/'
}
},
footer: {
content: footerContent,
props: {
footerHeight: 45
}
},
searchHeader,
downloadTerms,
additionalRoutes,
reportAbuse,
claimNamespace,
mainHeadTags: MainHeadTags,
extensionHeadTags: ExtensionHeadTags,
namespaceHeadTags: NamespaceHeadTags
},
urls: {
extensionDefaultIcon: '/default-icon.png',
namespaceAccessInfo: 'https://github.com/eclipse/openvsx/wiki/Namespace-Access',
publisherAgreement: '/documents/publisher-agreement-v1.0.md'
}
};
}