Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Add Space profile link preview metadata

Anand Baburajan9deeaab9e937
diff --git a/web/apps/space/next.config.js b/web/apps/space/next.config.js
index fc60f17a60..9611e61220 100644
--- a/web/apps/space/next.config.js
+++ b/web/apps/space/next.config.js
@@ -5,13 +5,14 @@ module.exports = {
transpilePackages: Array.from(
new Set([...(baseConfig.transpilePackages || []), "ente-media"]),
),
- // Static deployments serve arbitrary profile links through index.html.
- // In development, mirror that behavior with a fallback rewrite.
+ // Static deployments serve arbitrary profile links through profile-link.html.
+ // In development, mirror that behavior with fallback rewrites.
...(process.env.NODE_ENV === "development" && {
output: undefined,
async rewrites() {
return {
fallback: [
+ { source: "/:spaceUsername", destination: "/profile-link" },
{
source: "/:path((?!_next|images|favicon.ico).*)",
destination: "/",
diff --git a/web/apps/space/public/_redirects b/web/apps/space/public/_redirects
index 239395825d..8e883dbdef 100644
--- a/web/apps/space/public/_redirects
+++ b/web/apps/space/public/_redirects
@@ -1,3 +1,4 @@
/app/friends/* /app/friends/[spaceId] 200
/app/messages/* /app/messages/[spaceId] 200
+/:spaceUsername /profile-link.html 200
/* /index.html 200
diff --git a/web/apps/space/src/components/SpacePageMeta.tsx b/web/apps/space/src/components/SpacePageMeta.tsx
index 15a2933868..1886fdc4d4 100644
--- a/web/apps/space/src/components/SpacePageMeta.tsx
+++ b/web/apps/space/src/components/SpacePageMeta.tsx
@@ -2,14 +2,34 @@ import Head from "next/head";
import React from "react";
import { onboardingDescription } from "screens/OnboardingScreen";
+const spacePreviewTitle = "Add me on Ente Space";
+
interface SpacePageMetaProps {
themeColor: string;
+ invitePreview?: boolean;
}
-export const SpacePageMeta: React.FC<SpacePageMetaProps> = ({ themeColor }) => (
+export const SpacePageMeta: React.FC<SpacePageMetaProps> = ({
+ invitePreview,
+ themeColor,
+}) => (
<Head>
<meta name="theme-color" content={themeColor} />
<meta name="robots" content="noindex,nofollow" />
<meta name="description" content={onboardingDescription} />
+ {invitePreview && (
+ <>
+ <meta property="og:title" content={spacePreviewTitle} />
+ <meta
+ property="og:description"
+ content={onboardingDescription}
+ />
+ <meta name="twitter:title" content={spacePreviewTitle} />
+ <meta
+ name="twitter:description"
+ content={onboardingDescription}
+ />
+ </>
+ )}
</Head>
);
diff --git a/web/apps/space/src/components/SpaceRouteFallback.tsx b/web/apps/space/src/components/SpaceRouteFallback.tsx
index f3718afcf9..5697f2ca8b 100644
--- a/web/apps/space/src/components/SpaceRouteFallback.tsx
+++ b/web/apps/space/src/components/SpaceRouteFallback.tsx
@@ -4,6 +4,7 @@ import React from "react";
interface SpaceRouteFallbackProps {
background: string;
+ invitePreview?: boolean;
message?: string;
}
@@ -40,10 +41,11 @@ export const SpaceLoadingSpinner: React.FC<SpaceLoadingSpinnerProps> = ({
export const SpaceRouteFallback: React.FC<SpaceRouteFallbackProps> = ({
background,
+ invitePreview,
message,
}) => (
<>
- <SpacePageMeta themeColor={background} />
+ <SpacePageMeta themeColor={background} invitePreview={invitePreview} />
<Box
sx={{
alignItems: "center",
diff --git a/web/apps/space/src/pages/index.tsx b/web/apps/space/src/pages/index.tsx
index f941c840dd..7616a4ee96 100644
--- a/web/apps/space/src/pages/index.tsx
+++ b/web/apps/space/src/pages/index.tsx
@@ -37,6 +37,10 @@ type RouteMode =
| { kind: "app" }
| ({ kind: "public-profile" } & PendingSpaceInvite);
+interface PageProps {
+ invitePreview?: boolean;
+}
+
const PublicProfileUnavailable: React.FC = () => (
<Box
className="green-bg"
@@ -246,7 +250,7 @@ const PublicFriendRequestScreen: React.FC<PublicFriendRequestScreenProps> = ({
</Box>
);
-const Page: React.FC = () => {
+export const Page: React.FC<PageProps> = ({ invitePreview }) => {
const router = useSpaceRouter();
const {
onboardingEntrySource,
@@ -318,7 +322,12 @@ const Page: React.FC = () => {
(routeMode.kind == "app" &&
(profileLoadStatus == "loading" || Boolean(profile)))
) {
- return <SpaceRouteFallback background={profileBackground} />;
+ return (
+ <SpaceRouteFallback
+ background={profileBackground}
+ invitePreview={invitePreview}
+ />
+ );
}
if (routeMode.kind == "public-profile") {
@@ -364,7 +373,7 @@ const Page: React.FC = () => {
return (
<>
- <SpacePageMeta themeColor={onboardingGreen} />
+ <SpacePageMeta themeColor={onboardingGreen} invitePreview />
<PublicFriendRequestScreen
identity={publicIdentity}
onAddFriend={addFriend}
diff --git a/web/apps/space/src/pages/profile-link.tsx b/web/apps/space/src/pages/profile-link.tsx
new file mode 100644
index 0000000000..874b7800c0
--- /dev/null
+++ b/web/apps/space/src/pages/profile-link.tsx
@@ -0,0 +1,5 @@
+import { Page } from "./index";
+
+const ProfileLinkPage = () => <Page invitePreview />;
+
+export default ProfileLinkPage;