Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add open graph metadata #75

Merged
merged 3 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/chat/app/+html.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ export default function Root({ children }: PropsWithChildren) {
<ScrollViewStyleReset />

{/* Add any additional <head> elements that you want globally available on web... */}
<meta property="og:image" content="https://orbiting.com/imgs/og.png" />
<meta property="og:url" content={typeof window !== 'undefined' ? window.location.href : ''} />
<meta property="og:type" content="website" />
<meta property="og:description" content="A simple messaging app for your eyeballs. You can use it to type and display messages to those around you. Display a message loud and clear." />
</head>
<body>{children}</body>
</html>
Expand Down
27 changes: 26 additions & 1 deletion packages/chat/app/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,49 @@ function AppContent() {

useEffect(() => {
let title = 'Orbiting';

let ogTitle = 'Orbiting';
let ogDescription = 'A simple messaging app for your eyeballs. You can use it to type and display messages to those around you. Display a message loud and clear.';
let ogImage = 'https://orbiting.com/imgs/og.png';

switch (pathname) {
case '/history':
title = `${t('history')} | Orbiting`;
ogTitle = `${t('history')} | Orbiting`;
break;
case '/settings':
title = `${t('settings')} | Orbiting`;
ogTitle = `${t('settings')} | Orbiting`;
break;
case '/help':
title = `${t('help')} | Orbiting`;
ogTitle = `${t('help')} | Orbiting`;
break;
case '/about':
title = `${t('about')} | Orbiting`;
ogTitle = `${t('about')} | Orbiting`;
break;
}

if (typeof document !== 'undefined') {
document.title = title;

const metaTags = [
{ property: 'og:title', content: ogTitle },
{ property: 'og:description', content: ogDescription },
{ property: 'og:image', content: ogImage },
{ property: 'og:url', content: window.location.href },
{ property: 'og:type', content: 'website' }
];

metaTags.forEach(({ property, content }) => {
let metaTag = document.querySelector(`meta[property="${property}"]`);
if (!metaTag) {
metaTag = document.createElement('meta');
metaTag.setAttribute('property', property);
document.head.appendChild(metaTag);
}
metaTag.setAttribute('content', content);
});
}
}, [pathname, t]);

Expand Down
22 changes: 22 additions & 0 deletions packages/chat/app/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffect } from 'react';
import { useTranslation } from 'react-i18next';

Check warning on line 2 in packages/chat/app/index.tsx

View workflow job for this annotation

GitHub Actions / lint

'useTranslation' is defined but never used
import { Platform } from 'react-native';
import HomeScreen from "./components/HomeScreen";

Expand All @@ -17,5 +17,27 @@
}
}, []);

useEffect(() => {
if (Platform.OS === 'web' && typeof document !== 'undefined') {
const metaTags = [
{ property: 'og:title', content: 'Orbiting' },
{ property: 'og:description', content: 'A simple messaging app for your eyeballs. You can use it to type and display messages to those around you. Display a message loud and clear.' },
{ property: 'og:image', content: 'https://orbiting.com/imgs/og.png' },
{ property: 'og:url', content: window.location.href },
{ property: 'og:type', content: 'website' }
];

metaTags.forEach(({ property, content }) => {
let metaTag = document.querySelector(`meta[property="${property}"]`);
if (!metaTag) {
metaTag = document.createElement('meta');
metaTag.setAttribute('property', property);
document.head.appendChild(metaTag);
}
metaTag.setAttribute('content', content);
});
}
}, []);

return <HomeScreen />;
}
Loading