Private
Public Access
1
0

feat: add strapi cms data

- add types
- add layout data loading
- add mapping functions
- add CmsComponent
- remove image
This commit is contained in:
2026-02-09 19:49:55 +01:00
parent 049f3a5f2f
commit 78b47c4823
9 changed files with 349 additions and 18 deletions

View File

@@ -0,0 +1,131 @@
import type {
StrapiComponentUnion,
StrapiContactComponent,
StrapiFooterResponse,
StrapiHomepageResponse,
StrapiProfileComponent,
StrapiProjectComponent,
StrapiSkillComponent
} from '$lib/types/strapi';
import type {
Contact,
Footer,
Header,
HeaderLink,
Profile,
Projects,
Skills
} from '$lib/types/data';
import type { ComponentKeys } from '$lib/types/strapi';
import type { Component } from 'svelte';
import { PUBLIC_STRAPI_URL } from '$env/static/public';
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
export const cmsComponentMapping: Record<ComponentKeys, Promise<{ default: Component<any> }>> = {
'shared.profile': import('$lib/components/Profile.svelte'),
'shared.project': import('$lib/components/Projects.svelte'),
'shared.skill': import('$lib/components/Skills.svelte'),
'shared.contact': import('$lib/components/Contact.svelte')
};
export const mapHeaderData = (data: StrapiHomepageResponse): Header => {
const links: HeaderLink[] = data.data.components.map((component) => {
if (component.__component === 'shared.profile') {
return {
label: "Profile",
href: `#${component.profile.anchor_id}`
};
} else if (component.__component === 'shared.project') {
return {
label: component.project.title,
href: `#${component.project.anchor_id}`
};
} else if (component.__component === 'shared.skill') {
return {
label: component.skill.title,
href: `#${component.skill.anchor_id}`
};
}
return {
label: component.contact.title,
href: `#${component.contact.anchor_id}`
};
});
return { links };
};
export const mapFooterData = (data: StrapiFooterResponse): Footer => {
return {
copyright: data.data.copyright,
links: {
git: data.data.git,
linkedin: data.data.linkedin
}
};
};
const mapProfileData = (data: StrapiProfileComponent): Profile => {
return {
name: data.profile.name,
title: data.profile.title,
anchorId: data.profile.anchor_id,
text: data.profile.description,
imageUrl: PUBLIC_STRAPI_URL + data.profile.image.formats.small.url
};
};
const mapProjectData = (data: StrapiProjectComponent): Projects => {
return {
title: data.project.title,
anchorId: data.project.anchor_id,
entries: data.project.entries.map((entry) => ({
title: entry.front_title,
description: entry.front_description,
taskHeadline: entry.back_title,
tasks: entry.back_description,
toolsHeadline: entry.back_title_second,
tools: entry.back_content_list
}))
};
};
const mapSkillData = (data: StrapiSkillComponent): Skills => {
return {
anchorId: data.skill.anchor_id,
subtitle: data.skill.subtitle,
title: data.skill.title,
entries: data.skill.entries.map((entry) => ({
title: entry.title,
icon: entry.icon,
items: entry.content
}))
};
};
const mapContactData = (data: StrapiContactComponent): Contact => {
return {
anchorId: data.contact.anchor_id,
subtitle: data.contact.subtitle,
title: data.contact.title,
form: {
title: data.contact.form_title,
subjectPlaceholder: data.contact.subject_placeholder,
messagePlaceholder: data.contact.message_placeholder,
submit: data.contact.cta_text
}
};
};
export const mapComponentData = (data: StrapiComponentUnion) => {
if (data.__component === 'shared.profile') {
return mapProfileData(data);
} else if (data.__component === 'shared.project') {
return mapProjectData(data);
} else if (data.__component === 'shared.skill') {
return mapSkillData(data);
}
return mapContactData(data);
};