CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

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