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

release-v0.18.0 #2056

Merged
merged 4 commits into from
Sep 25, 2023
Merged
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
13 changes: 12 additions & 1 deletion lib/design-system/src/blocks/LinkBlock/LinkBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ export type LinkType = 'opengraph' | 'url';
type MediaType = 'twitter' | 'media' | 'image';
export type LinkBlockType = LinkType | MediaType;

const parseUrl = (url: string, defaultUrl: string) => {
let result = undefined;
try {
result = new URL(url);
} catch (e) {
result = defaultUrl;
}
return result;
};

export const LinkBlock = ({
id,
link,
Expand Down Expand Up @@ -187,7 +197,8 @@ export const LinkBlock = ({
</Box>
);
}
const ogOrLink = ogHasURL ? openGraph?.ogUrl : link;
// @patrick - only use ogUrl if it can be parsed using URL
const ogOrLink = ogHasURL ? parseUrl(openGraph?.ogUrl, link) : link;
let sitename: string;
try {
sitename = openGraph?.ogSiteName || new URL(ogOrLink).hostname;
Expand Down