Skip to content

Commit 45d2992

Browse files
authored
fix: Slack OG preview when missing og:site_name (#126)
1 parent 7d525c7 commit 45d2992

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

apps/dashboard/src/components/Splash/Tools/OpenGraphImageChecker.tsx

+10-7
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,28 @@ import {
2323
export function OpenGraphImageChecker() {
2424
const [loading, setLoading] = useState(false);
2525
const [data, setData] = useState<Record<MetaTags, string> | undefined>();
26+
const [url, setUrl] = useState<URL | undefined>();
2627
const { preview, PreviewControls } = usePreviewControls();
2728

28-
const debounced = useDebouncedCallback((url: string) => {
29+
const debounced = useDebouncedCallback((maybeUrl: string) => {
2930
try {
30-
let finalUrl = url;
31+
let finalUrl = maybeUrl;
3132

32-
if (!url.startsWith("http")) {
33-
finalUrl = `https://${url}`;
33+
if (!maybeUrl.startsWith("http")) {
34+
finalUrl = `https://${maybeUrl}`;
3435
}
3536

3637
if (!finalUrl.includes("://") || !finalUrl.includes(".")) {
3738
throw new Error("Invalid URL");
3839
}
3940

40-
const maybeUrl = new URL(finalUrl);
41+
// eslint-disable-next-line @typescript-eslint/no-shadow -- disable no shadow
42+
const url = new URL(finalUrl);
4143

44+
setUrl(url);
4245
setLoading(true);
4346

44-
fetch(`/api/og/check?url=${encodeURIComponent(maybeUrl.toString())}`)
47+
fetch(`/api/og/check?url=${encodeURIComponent(url.toString())}`)
4548
.then(async (response) => {
4649
const tempData = (await response.json()) as Record<MetaTags, string>;
4750

@@ -124,7 +127,7 @@ export function OpenGraphImageChecker() {
124127
previewTitle={data["og:title"]}
125128
previewDescription={data["og:description"]}
126129
previewUrl={data["og:url"]}
127-
previewSite={data["og:site_name"]}
130+
previewSite={data["og:site_name"] || url?.hostname}
128131
size="medium"
129132
/>
130133
</Flex>

0 commit comments

Comments
 (0)