mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-28 05:37:34 +03:00
Fixed recommending site without available metadata (#17989)
fixes https://github.com/TryGhost/Product/issues/3813
This commit is contained in:
parent
8f272e730b
commit
83399222ea
@ -23,10 +23,16 @@ export const useGetOembed = () => {
|
||||
return {
|
||||
async query(searchParams: OembedRequest) {
|
||||
const url = apiUrl(path, searchParams);
|
||||
const result = await fetchApi(url, {
|
||||
method: 'GET'
|
||||
});
|
||||
return result as OembedResponse;
|
||||
try {
|
||||
const result = await fetchApi(url, {
|
||||
method: 'GET'
|
||||
});
|
||||
return result as OembedResponse;
|
||||
} catch (e) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
@ -38,12 +38,14 @@ const AddRecommendationModal: React.FC<AddRecommendationModalProps> = ({recommen
|
||||
type: 'mention'
|
||||
});
|
||||
|
||||
if (!oembed) {
|
||||
showToast({
|
||||
type: 'pageError',
|
||||
message: 'Could not fetch metadata for this URL, please try again later'
|
||||
});
|
||||
return;
|
||||
let defaultTitle = formState.title;
|
||||
if (!defaultTitle) {
|
||||
try {
|
||||
defaultTitle = new URL(formState.url).hostname.replace('www.', '');
|
||||
} catch (e) {
|
||||
// Ignore
|
||||
defaultTitle = formState.url;
|
||||
}
|
||||
}
|
||||
|
||||
// Switch modal without changing the route (the second modal is not reachable by URL)
|
||||
@ -52,10 +54,10 @@ const AddRecommendationModal: React.FC<AddRecommendationModalProps> = ({recommen
|
||||
animate: false,
|
||||
recommendation: {
|
||||
...formState,
|
||||
title: oembed.metadata.title ?? formState.title,
|
||||
excerpt: oembed.metadata.description ?? formState.excerpt,
|
||||
featured_image: oembed.metadata.thumbnail ?? formState.featured_image,
|
||||
favicon: oembed.metadata.icon ?? formState.favicon
|
||||
title: oembed?.metadata?.title ?? defaultTitle,
|
||||
excerpt: oembed?.metadata?.description ?? formState.excerpt ?? null,
|
||||
featured_image: oembed?.metadata?.thumbnail ?? formState.featured_image ?? null,
|
||||
favicon: oembed?.metadata?.icon ?? formState.favicon ?? null
|
||||
}
|
||||
});
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user