diff --git a/client/eslint.config.js b/client/eslint.config.js index f9b64cb..da0a406 100644 --- a/client/eslint.config.js +++ b/client/eslint.config.js @@ -12,7 +12,8 @@ export default tseslint.config( ...svelte.configs['flat/prettier'], { rules: { - 'svelte/valid-compile': ['error', { ignoreWarnings: true }], + 'svelte/valid-compile': 'warn', + 'svelte/no-at-html-tags': 'warn', }, languageOptions: { globals: { diff --git a/client/src/lib/components/blogPost/blogPost.svelte b/client/src/lib/components/blogPost/blogPost.svelte new file mode 100644 index 0000000..bfca295 --- /dev/null +++ b/client/src/lib/components/blogPost/blogPost.svelte @@ -0,0 +1,26 @@ + + + diff --git a/client/src/lib/components/blogPost/definition.ts b/client/src/lib/components/blogPost/definition.ts new file mode 100644 index 0000000..fad5dcd --- /dev/null +++ b/client/src/lib/components/blogPost/definition.ts @@ -0,0 +1,3 @@ +import type { BlogPost } from '$lib/utils/definitions'; + +export type Props = BlogPost; diff --git a/client/src/lib/utils/definitions.ts b/client/src/lib/utils/definitions.ts index 48991cb..1a751ba 100644 --- a/client/src/lib/utils/definitions.ts +++ b/client/src/lib/utils/definitions.ts @@ -113,3 +113,40 @@ export type BackgroundClasss = | 'fr-background-action-low--brown-caramel' | 'fr-background-action-low--brown-opera' | 'fr-background-action-low--beige-gris-galet'; + +export type WagtailApiItemsResponse = { + meta: { + total_count: number; + }; + items: WagtailApiItemResponse[]; +}; + +export type WagtailApiItemResponse = { + id: number; + meta: { + type: string; + slug: string; + first_published_at: string; + search_description: string; + }; + title: string; + body?: [ + { + type: string; + value: string; + }, + ]; +}; + +export type BlogPost = { + title: string; + description: string; + firstPublishedAt: string; + slug: string; + body?: [ + { + type: string; + value: string; + }, + ]; +}; diff --git a/client/src/routes/blog/+page.server.ts b/client/src/routes/blog/+page.server.ts new file mode 100644 index 0000000..419ab86 --- /dev/null +++ b/client/src/routes/blog/+page.server.ts @@ -0,0 +1,22 @@ +import type { PageServerLoad } from './$types'; +import { BORIS_CMS_URL } from '$env/static/private'; +import type { BlogPost, WagtailApiItemsResponse } from '$lib/utils/definitions'; +import type { Data } from './definitions'; + +export const load: PageServerLoad = async ({ fetch }): Promise => { + const response = await fetch( + `${BORIS_CMS_URL}/api/v2/pages?type=blog.BlogEntryPage&fields=*,-body&order=-first_published_at`, + ); + const data: WagtailApiItemsResponse = await response.json(); + + const blogPosts: BlogPost[] = data.items.map((item) => ({ + title: item.title, + description: item.meta.search_description, + firstPublishedAt: item.meta.first_published_at, + slug: item.meta.slug, + })); + + return { + blogPosts, + }; +}; diff --git a/client/src/routes/blog/+page.svelte b/client/src/routes/blog/+page.svelte index fcc0bb9..389dced 100644 --- a/client/src/routes/blog/+page.svelte +++ b/client/src/routes/blog/+page.svelte @@ -1 +1,23 @@ -

Blog

+ + +
+
+ {#each data.blogPosts as { title, description, firstPublishedAt, slug }} +
+ +
+ {/each} +
+
diff --git a/client/src/routes/blog/[slug]/+page.server.ts b/client/src/routes/blog/[slug]/+page.server.ts new file mode 100644 index 0000000..88558a4 --- /dev/null +++ b/client/src/routes/blog/[slug]/+page.server.ts @@ -0,0 +1,33 @@ +import type { PageServerLoad } from './$types'; +import { BORIS_CMS_URL } from '$env/static/private'; +import type { Data } from './definitions'; +import type { + BlogPost, + WagtailApiItemResponse, + WagtailApiItemsResponse, +} from '$lib/utils/definitions'; + +export const load: PageServerLoad = async ({ + params, + fetch, +}): Promise => { + const { slug } = params; + const response = await fetch(`${BORIS_CMS_URL}/api/v2/pages?slug=${slug}`); + const data: WagtailApiItemsResponse = await response.json(); + const { id } = data.items[0]; + + const blogPostResponse = await fetch(`${BORIS_CMS_URL}/api/v2/pages/${id}`); + const blogPostData: WagtailApiItemResponse = await blogPostResponse.json(); + + const blogPost: BlogPost = { + title: blogPostData.title, + description: blogPostData.meta.search_description, + firstPublishedAt: blogPostData.meta.first_published_at, + slug, + body: blogPostData.body, + }; + + return { + blogPost, + }; +}; diff --git a/client/src/routes/blog/[slug]/+page.svelte b/client/src/routes/blog/[slug]/+page.svelte index 1dfd925..9274496 100644 --- a/client/src/routes/blog/[slug]/+page.svelte +++ b/client/src/routes/blog/[slug]/+page.svelte @@ -1,7 +1,17 @@ -

{data.slug}

+
+ {#if blogPost.body} + {#each blogPost.body as element} + {@html element.value} + {/each} + {/if} +
diff --git a/client/src/routes/blog/[slug]/+page.ts b/client/src/routes/blog/[slug]/+page.ts deleted file mode 100644 index 7f185ff..0000000 --- a/client/src/routes/blog/[slug]/+page.ts +++ /dev/null @@ -1,14 +0,0 @@ -import type { PageLoad } from './$types'; -import type { Data } from './definitions'; - -export const load: PageLoad = ({ params }) => { - const data: Data = { - slug: params.slug, - }; - - return data; -}; - -export async function entries() { - return [{ slug: "Le BRS, kesako ? (exemple d'article)" }]; -} diff --git a/client/src/routes/blog/[slug]/definitions.ts b/client/src/routes/blog/[slug]/definitions.ts index e52bddb..b86833c 100644 --- a/client/src/routes/blog/[slug]/definitions.ts +++ b/client/src/routes/blog/[slug]/definitions.ts @@ -1,5 +1,7 @@ +import type { BlogPost } from '$lib/utils/definitions'; + export type Data = { - slug: string; + blogPost: BlogPost; }; export type Props = { diff --git a/client/src/routes/blog/definitions.ts b/client/src/routes/blog/definitions.ts new file mode 100644 index 0000000..ba274e3 --- /dev/null +++ b/client/src/routes/blog/definitions.ts @@ -0,0 +1,9 @@ +import type { BlogPost } from '$lib/utils/definitions'; + +export type Data = { + blogPosts: BlogPost[]; +}; + +export type Props = { + data: Data; +}; diff --git a/client/src/routes/simuler-mon-eligibilite/+page.server.ts b/client/src/routes/simuler-mon-eligibilite/+page.server.ts index b922109..292bca7 100644 --- a/client/src/routes/simuler-mon-eligibilite/+page.server.ts +++ b/client/src/routes/simuler-mon-eligibilite/+page.server.ts @@ -2,10 +2,8 @@ import type { PageServerLoad } from './$types'; import type { Data } from './definitions'; import { LANDBOT_CONFIG_URL } from '$env/static/private'; -export const load: PageServerLoad = () => { - const data: Data = { +export const load: PageServerLoad = (): Data => { + return { landbotConfigUrl: LANDBOT_CONFIG_URL, }; - - return data; };