66 lines
1.7 KiB
TypeScript
66 lines
1.7 KiB
TypeScript
import type { Experience, Education, Skill, Profile } from './types';
|
|
|
|
async function loadJsonFilesFromGlob<T>(
|
|
modules: Record<string, () => Promise<{ default: T }>>
|
|
): Promise<T[]> {
|
|
return Promise.all(
|
|
Object.entries(modules).map(async ([_, module]) => await module().then((m) => m.default))
|
|
);
|
|
}
|
|
|
|
function decodeBase64Email(email: string): string {
|
|
try {
|
|
return Buffer.from(email, 'base64').toString('utf-8');
|
|
} catch {
|
|
return email;
|
|
}
|
|
}
|
|
|
|
export async function loadProfile() {
|
|
const profile: Profile = await import('$lib/content/profile.json');
|
|
const media = import.meta.glob<{ default: string }>('$lib/media/*');
|
|
const profilePictureModule = await (profile.profilePicture
|
|
? media[`/${profile.profilePicture}`]?.()
|
|
: undefined);
|
|
const avatarModule = await (profile.avatar ? media[`/${profile.avatar}`]?.() : undefined);
|
|
|
|
return {
|
|
...profile,
|
|
email: decodeBase64Email(profile.email),
|
|
profilePicture: profilePictureModule?.default,
|
|
avatar: avatarModule?.default,
|
|
};
|
|
}
|
|
|
|
export async function loadExperience() {
|
|
return loadJsonFilesFromGlob(
|
|
import.meta.glob<{ default: Experience }>('$lib/content/experience/*.json')
|
|
);
|
|
}
|
|
|
|
export function loadEducation() {
|
|
return loadJsonFilesFromGlob(
|
|
import.meta.glob<{ default: Education }>('$lib/content/education/*.json')
|
|
);
|
|
}
|
|
|
|
export function loadSkills() {
|
|
return loadJsonFilesFromGlob(import.meta.glob<{ default: Skill }>('$lib/content/skills/*.json'));
|
|
}
|
|
|
|
export async function loadAllContent() {
|
|
const [profile, experience, education, skills] = await Promise.all([
|
|
loadProfile(),
|
|
loadExperience(),
|
|
loadEducation(),
|
|
loadSkills(),
|
|
]);
|
|
|
|
return {
|
|
profile,
|
|
experience,
|
|
education,
|
|
skills,
|
|
};
|
|
}
|