forked from raycast/ray-so
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpage.tsx
87 lines (76 loc) · 2.26 KB
/
page.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
import { Desktop } from "@themes/components/desktop";
import { PageWithThemeMode } from "@themes/components/page-with-theme-mode";
import { Raycast } from "@themes/components/raycast";
import { RedirectToRaycast } from "@themes/components/redirect-to-raycast";
import { Theme, getAllThemes, makeThemeObjectFromParams } from "@themes/lib/theme";
import { BASE_URL } from "@/utils/common";
import defaultOgImage from "@themes/assets/default-og-image.png";
export async function generateMetadata({ searchParams }: { searchParams: { [key: string]: string } }) {
const themeInUrl = makeThemeObjectFromParams(searchParams);
if (!themeInUrl) {
return {
openGraph: {
images: [
{
url: defaultOgImage.src,
},
],
},
twitter: {
card: "summary_large_image",
images: [
{
url: defaultOgImage.src,
},
],
},
};
}
const { colors, ...theme } = themeInUrl;
const queryParams = new URLSearchParams();
Object.entries(theme).forEach(([key, value]) => queryParams.set(key, value));
Object.entries(colors).forEach(([key, value]) => queryParams.set(key, value));
const title = theme.author ? `${theme.name} by ${theme.author}` : theme.name;
const image = `${BASE_URL}/themes/og?${queryParams}`;
return {
title,
openGraph: {
title,
images: [
{
url: image,
},
],
},
twitter: {
card: "summary_large_image",
images: [
{
url: image,
},
],
},
};
}
export default async function Home({
searchParams,
}: {
searchParams: { [key: string]: string | string[] | undefined };
}) {
const themes = await getAllThemes();
const defaultTheme = themes.filter((theme) => theme.appearance === "dark")[0];
let themeInUrl: Theme | undefined = undefined;
let shouldOpenInRaycast: boolean = false;
if (searchParams) {
themeInUrl = makeThemeObjectFromParams(searchParams);
shouldOpenInRaycast = "addToRaycast" in searchParams;
}
return (
<PageWithThemeMode theme={themeInUrl || defaultTheme}>
<Desktop>
<Raycast />
</Desktop>
{shouldOpenInRaycast && themeInUrl && <RedirectToRaycast theme={themeInUrl} />}
</PageWithThemeMode>
);
}