Skip to content

Commit

Permalink
feat: fix social media image url
Browse files Browse the repository at this point in the history
  • Loading branch information
madcampos committed Sep 26, 2024
1 parent 0d934da commit 55208d3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/components/HtmlHead.astro
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@ const {
hasFeed = false
} = Astro.props;
const fullUrl = new URL(url, new URL(GLOBALS.url, Astro.site)).toString();
const baseUrl = new URL(GLOBALS.url, Astro.site).toString();
const fullUrl = new URL(url, baseUrl).toString();
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const socialImageAlt = imageAlt ?? GLOBALS.logoAltText!.micro;
const socialImage = join([GLOBALS.url, image ?? defaultSocialImage.src], { trailingSlash: false });
const socialImage = join([baseUrl, image ?? defaultSocialImage.src], { trailingSlash: false });
---
<head>
<meta charset="utf-8" />
Expand Down
6 changes: 3 additions & 3 deletions src/utils/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ export function join(paths: string[], options?: Partial<JoinOptions>) {
...options
};

const joinedPath = paths.join(opts.separator).replaceAll(`${opts.separator}${opts.separator}`, opts.separator);
const joinedPath = paths.join(opts.separator).replaceAll(new RegExp(`(?<!:)${opts.separator}{2,}`, 'giu'), opts.separator);

let normalizedPath = joinedPath;

switch (opts.trailingSlash) {
case true:
normalizedPath = `${joinedPath}${opts.separator}`.replaceAll(`${opts.separator}${opts.separator}`, opts.separator);
normalizedPath = `${joinedPath}${opts.separator}`.replaceAll(new RegExp(`(?<!:)${opts.separator}{2,}`, 'giu'), opts.separator);
break;
case false:
normalizedPath = joinedPath.replace(new RegExp(`${opts.separator}$`, 'u'), '');
normalizedPath = joinedPath.replace(new RegExp(`${opts.separator}$`, 'iu'), '');
break;
default:
}
Expand Down

0 comments on commit 55208d3

Please sign in to comment.