OpenPanel is an open-source web and product analytics platform, an open-source alternative to Mixpanel with optional self-hosting.
import { existsSync } from 'node:fs';
import { join } from 'node:path';
const PUBLIC_DIR = join(process.cwd(), 'public');
// Some articles have no cover, or point at a file that was never added;
// the card then draws its own placeholder instead of a broken image.
export function resolveArticleCover(cover?: string): string | undefined {
if (!cover) {
return undefined;
}
if (cover.startsWith('http://') || cover.startsWith('https://')) {
return URL.canParse(cover) ? cover : undefined;
}
return existsSync(join(PUBLIC_DIR, cover)) ? cover : undefined;
}