Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/next/pages/index.tsx
6016 views
1
/*
2
* This file is part of CoCalc: Copyright © 2021 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
import { Layout, Tooltip } from "antd";
7
import { GetServerSidePropsContext } from "next";
8
import { join } from "path";
9
import { getRecentHeadlines } from "@cocalc/database/postgres/news";
10
import { COLORS } from "@cocalc/util/theme";
11
import { RecentHeadline } from "@cocalc/util/types/news";
12
import { CoCalcComFeatures } from "components/landing/cocalc-com-features";
13
import Content from "components/landing/content";
14
import Footer from "components/landing/footer";
15
import Head from "components/landing/head";
16
import Header from "components/landing/header";
17
import { NewsBanner } from "components/landing/news-banner";
18
import { Tagline } from "components/landing/tagline";
19
import Logo from "components/logo";
20
import { CSS, Paragraph, Title } from "components/misc";
21
import A from "components/misc/A";
22
import Videos, { Video } from "components/videos";
23
import basePath from "lib/base-path";
24
import { Customize, CustomizeType } from "lib/customize";
25
import { PublicPath as PublicPathType } from "lib/share/types";
26
import withCustomize from "lib/with-customize";
27
import screenshot from "public/cocalc-screenshot-20200128-nq8.png";
28
29
import type { JSX } from "react";
30
31
const TOP_LINK_STYLE: CSS = { marginRight: "20px" } as const;
32
33
interface Props {
34
customize: CustomizeType;
35
publicPaths: PublicPathType[];
36
recentHeadlines: RecentHeadline[] | null;
37
headlineIndex: number;
38
}
39
40
export default function Home(props: Props) {
41
const { customize, recentHeadlines, headlineIndex } = props;
42
const {
43
siteName,
44
siteDescription,
45
organizationName,
46
organizationURL,
47
splashImage,
48
indexInfo,
49
onCoCalcCom,
50
account,
51
isCommercial,
52
indexTagline,
53
} = customize;
54
55
function contentDescription() {
56
return (
57
<Paragraph type="secondary">
58
{onCoCalcCom ? (
59
<>by Sagemath, Inc.</>
60
) : (
61
<>
62
An instance of <A href="https://cocalc.com">CoCalc</A>
63
{organizationName && organizationURL ? (
64
<>
65
{" "}
66
hosted by <A href={organizationURL}>{organizationName}</A>
67
</>
68
) : undefined}
69
.
70
</>
71
)}
72
</Paragraph>
73
);
74
}
75
76
function topAccountLinks() {
77
if (!account) return;
78
return (
79
<div
80
style={{
81
textAlign: "center",
82
margin: "30px 0 15px 0",
83
}}
84
>
85
<Title level={1} style={{ color: COLORS.GRAY }}>
86
Signed in as{" "}
87
<Tooltip title={"View all your account settings"} placement={"right"}>
88
<a href={join(basePath, "settings")}>
89
{`${account.first_name} ${account.last_name} ${
90
account.name ? "(@" + account.name + ")" : ""
91
}`}
92
</a>
93
</Tooltip>
94
</Title>
95
<Paragraph style={{ fontSize: "11pt", margin: "15px 0" }}>
96
{isCommercial && account && !account.is_anonymous && (
97
<>
98
<a href={join(basePath, "store")} style={TOP_LINK_STYLE}>
99
Store
100
</a>{" "}
101
<a
102
href={join(basePath, "settings/purchases")}
103
style={TOP_LINK_STYLE}
104
>
105
Purchases
106
</a>{" "}
107
<A href={"/vouchers"} style={TOP_LINK_STYLE}>
108
Vouchers
109
</A>{" "}
110
</>
111
)}
112
<a href={join(basePath, "projects")} style={TOP_LINK_STYLE}>
113
Projects
114
</a>{" "}
115
{customize.landingPages && (
116
<>
117
<A href="/features/" style={TOP_LINK_STYLE}>
118
Features
119
</A>{" "}
120
<A href="/software" style={TOP_LINK_STYLE}>
121
Software
122
</A>{" "}
123
{isCommercial && (
124
<>
125
<A href="/pricing" style={TOP_LINK_STYLE}>
126
Pricing
127
</A>{" "}
128
</>
129
)}
130
</>
131
)}
132
</Paragraph>
133
</div>
134
);
135
}
136
137
function renderCoCalcComFeatures() {
138
if (!onCoCalcCom) return;
139
return <CoCalcComFeatures />;
140
}
141
142
function logo(): JSX.Element {
143
return <Logo type="full" style={{ width: "50%" }} />;
144
}
145
146
function renderNews() {
147
if (recentHeadlines == null) return;
148
return (
149
<NewsBanner
150
recentHeadlines={recentHeadlines}
151
headlineIndex={headlineIndex}
152
/>
153
);
154
}
155
156
return (
157
<Customize value={customize}>
158
<Head title={siteDescription ?? "Collaborative Calculation"} />
159
<Layout>
160
<Header />
161
<Layout.Content style={{ backgroundColor: "white" }}>
162
{renderNews()}
163
{topAccountLinks()}
164
<Content
165
style={{ minHeight: "30vh" }}
166
body={logo()}
167
title={onCoCalcCom ? "" : siteName}
168
subtitle={siteDescription}
169
description={contentDescription()}
170
image={splashImage ? splashImage : screenshot}
171
alt={"Screenshot showing CoCalc in action!"}
172
imageAlternative={
173
onCoCalcCom ? <Videos videos={YOUTUBE_IDS} /> : indexInfo
174
}
175
/>
176
<Tagline value={indexTagline} style={{ padding: "5px" }} />
177
{renderCoCalcComFeatures()}
178
<Footer />
179
</Layout.Content>
180
</Layout>
181
</Customize>
182
);
183
}
184
185
export async function getServerSideProps(context: GetServerSidePropsContext) {
186
// get most recent headlines
187
const recentHeadlines = await getRecentHeadlines(5);
188
// we want to not always show the same headlines at the start
189
const headlineIndex =
190
recentHeadlines != null
191
? Math.floor(Date.now() % recentHeadlines.length)
192
: 0;
193
194
return await withCustomize(
195
{ context, props: { recentHeadlines, headlineIndex } },
196
{ name: true },
197
);
198
}
199
200
const YOUTUBE_IDS: Readonly<Video[]> = [
201
{ id: "oDdfmkQ0Hvw", title: "CoCalc Overview" },
202
{ id: "UfmjYxalyh0", title: "Using AI in CoCalc" },
203
{ id: "LLtLFtD8qfo", title: "Using JupyterLab in CoCalc" },
204
{ id: "OMN1af0LUcA", title: "Using OpenWebUI and Ollama On CoCalc" },
205
{ id: "Owq90O0vLJo", title: "R Studio on CoCalc" },
206
{ id: "JG6jm6yv_KE", title: "PyTorch with a GPU on CoCalc" },
207
{
208
id: "Uwn3ngzXD0Y",
209
title: "JAX Quickstart on CoCalc using a GPU (or on CPU)",
210
},
211
{ id: "NkNx6tx3nu0", title: "Running On-Prem Compute Servers on CoCalc" },
212
] as const;
213
214