Skip to content

Commit 7efc167

Browse files
committed
Prepend Astro BASE_PATH to absolute image paths
1 parent f793704 commit 7efc167

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

src/components/projects/ProjectBrowser.astro

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,17 @@ async function getFigureFromPath(path: string) {
157157
return await getContentFromPath('figure', figureRecord, path);
158158
}
159159
160+
const BASE_URL = import.meta.env.BASE_URL;
161+
162+
function rebasePath(path: string | undefined): string | undefined {
163+
while(path && path[0] === '/')
164+
path = path.slice(1);
165+
if(!path) return undefined;
166+
return BASE_URL + path;
167+
}
168+
160169
function expandImagePath(fn: string) {
161-
const result = getImagePath(imagePaths, prepath, fn);
170+
const result = rebasePath(getImagePath(imagePaths, prepath, fn));
162171
if(!result) {
163172
console.warn('Could not expand path:', fn);
164173
return null;

0 commit comments

Comments
 (0)