image 404 issue
This commit is contained in:
+1
-1
@@ -728,7 +728,7 @@ export default function App({ previewMode = false }) {
|
||||
pointerEvents: 'none'
|
||||
}}
|
||||
>
|
||||
<source src={`${assetUrl(hero.video)}?v=2`} type="video/mp4" />
|
||||
<source src={assetUrl(hero.video)} type="video/mp4" />
|
||||
Your browser does not support the video tag.
|
||||
</video>
|
||||
|
||||
|
||||
+20
-8
@@ -1,9 +1,21 @@
|
||||
/**
|
||||
* Vite base, e.g. "/citpl_website/" in production and "/" in local dev.
|
||||
* Runtime fallback: if an old/dev build baked base "/" but the page is
|
||||
* actually served under /citpl_website/, prefer the live path prefix.
|
||||
*/
|
||||
export const ASSET_BASE = (import.meta.env.BASE_URL || '/').endsWith('/')
|
||||
? (import.meta.env.BASE_URL || '/')
|
||||
: `${import.meta.env.BASE_URL || ''}/`;
|
||||
function resolveAssetBase() {
|
||||
const fromEnv = import.meta.env.BASE_URL || '/';
|
||||
let base = fromEnv.endsWith('/') ? fromEnv : `${fromEnv}/`;
|
||||
|
||||
if (typeof window !== 'undefined' && base === '/') {
|
||||
const match = window.location.pathname.match(/^(\/citpl_website)(?=\/|$)/);
|
||||
if (match) base = `${match[1]}/`;
|
||||
}
|
||||
|
||||
return base;
|
||||
}
|
||||
|
||||
export const ASSET_BASE = resolveAssetBase();
|
||||
|
||||
/**
|
||||
* Resolve content/seed asset paths for subdirectory deploys.
|
||||
@@ -14,13 +26,15 @@ export function assetUrl(path) {
|
||||
|
||||
if (/^(data:|blob:)/i.test(path)) return path;
|
||||
|
||||
const assetBase = resolveAssetBase();
|
||||
const prefix = assetBase.replace(/\/$/, '');
|
||||
|
||||
// Absolute URL wrongly pointing at domain-root /assets or /uploads
|
||||
if (/^https?:\/\//i.test(path)) {
|
||||
try {
|
||||
const u = new URL(path);
|
||||
if (u.pathname.startsWith('/assets/') || u.pathname.startsWith('/uploads/')) {
|
||||
const prefix = ASSET_BASE.replace(/\/$/, '');
|
||||
if (!u.pathname.startsWith(`${prefix}/`)) {
|
||||
if (prefix && !u.pathname.startsWith(`${prefix}/`)) {
|
||||
u.pathname = `${prefix}${u.pathname}`;
|
||||
return u.href;
|
||||
}
|
||||
@@ -31,8 +45,6 @@ export function assetUrl(path) {
|
||||
}
|
||||
}
|
||||
|
||||
const prefix = ASSET_BASE.replace(/\/$/, '');
|
||||
|
||||
// Already under the site base
|
||||
if (prefix && (path === prefix || path.startsWith(`${prefix}/`))) {
|
||||
return path;
|
||||
@@ -43,7 +55,7 @@ export function assetUrl(path) {
|
||||
}
|
||||
|
||||
if (path.startsWith('assets/') || path.startsWith('uploads/')) {
|
||||
return `${ASSET_BASE}${path}`;
|
||||
return `${assetBase}${path}`;
|
||||
}
|
||||
|
||||
return path;
|
||||
|
||||
Reference in New Issue
Block a user