Skip to content

Commit d4f85d9

Browse files
authored
Adds case for both trailing slash and non trailing slash situations since netlify will have both. (#656)
1 parent ca4692a commit d4f85d9

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

components/markdown/image.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@ import { Box } from '@sparkpost/matchbox';
55

66
const getImageSrc = (asPath: string, src?: string) => {
77
const environment = getWindow();
8-
const parts = asPath.split('/');
9-
const dirArr = parts.splice(0, parts.length - 1);
10-
dirArr.pop();
11-
const dir = dirArr.join('/');
8+
const pathArr = asPath.split('/');
9+
10+
// Check for 'trailing slash'
11+
if (!pathArr[pathArr.length - 1]) {
12+
pathArr.pop();
13+
}
14+
pathArr.pop();
15+
const dir = pathArr.join('/');
1216
const path = `${environment?.location.origin || 'https://localhost:3000'}/content${dir}/${src}`;
1317
return path;
1418
};

0 commit comments

Comments
 (0)