feat: define closed portfolio input contract
This commit is contained in:
12
src/content/asset-url.ts
Normal file
12
src/content/asset-url.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import type { PublicAssetManifest } from './types.ts';
|
||||
|
||||
export const assetUrl = (manifest: PublicAssetManifest, assetId: string, base = '/assets/'): string => {
|
||||
if (!base.startsWith('/') || base.startsWith('//') || /[?#]/u.test(base)) {
|
||||
throw new Error('Asset URL base must be an absolute path without a query or fragment.');
|
||||
}
|
||||
const asset = manifest.assets.find((candidate) => candidate.id === assetId);
|
||||
if (asset === undefined) {
|
||||
throw new Error(`Unknown asset ID: ${assetId}`);
|
||||
}
|
||||
return `${base.endsWith('/') ? base : `${base}/`}${encodeURIComponent(asset.fileName)}`;
|
||||
};
|
||||
Reference in New Issue
Block a user