-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from MTES-MCT/feat/blog
feat: blog index page
- Loading branch information
Showing
12 changed files
with
171 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<script lang="ts"> | ||
import type { Props } from './definition'; | ||
const { title, description, firstPublishedAt, slug }: Props = $props(); | ||
const publishedAt = new Intl.DateTimeFormat('fr-FR', { | ||
dateStyle: 'long', | ||
timeStyle: 'short', | ||
}).format(new Date(firstPublishedAt)); | ||
</script> | ||
|
||
<div class="fr-card fr-enlarge-link"> | ||
<div class="fr-card__body"> | ||
<div class="fr-card__content"> | ||
<h3 class="fr-card__title"> | ||
<a href={`/blog/${slug}`}>{title}</a> | ||
</h3> | ||
<p class="fr-card__desc">{description}</p> | ||
<div class="fr-card__end"> | ||
<p class="fr-card__detail fr-icon-warning-fill"> | ||
Publié le {publishedAt} | ||
</p> | ||
</div> | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import type { BlogPost } from '$lib/utils/definitions'; | ||
|
||
export type Props = BlogPost; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Data> => { | ||
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, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,23 @@ | ||
<h1>Blog</h1> | ||
<script lang="ts"> | ||
import type { Props } from './definitions'; | ||
import Section from '$lib/components/section/section.svelte'; | ||
import BlogPost from '$lib/components/blogPost/blogPost.svelte'; | ||
const { data }: Props = $props(); | ||
</script> | ||
|
||
<Section | ||
title="Blog" | ||
titleElement="h1"> | ||
<div class="fr-grid-row fr-grid-row--gutters"> | ||
{#each data.blogPosts as { title, description, firstPublishedAt, slug }} | ||
<div class="fr-col-12 fr-col-md-6"> | ||
<BlogPost | ||
{title} | ||
{description} | ||
{slug} | ||
{firstPublishedAt} /> | ||
</div> | ||
{/each} | ||
</div> | ||
</Section> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Data> => { | ||
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, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,17 @@ | ||
<script lang="ts"> | ||
import Section from '$components/section/section.svelte'; | ||
import type { Props } from './definitions'; | ||
const { data }: Props = $props(); | ||
const { blogPost } = data; | ||
</script> | ||
|
||
<h1>{data.slug}</h1> | ||
<Section | ||
title={blogPost.title} | ||
titleElement="h1"> | ||
{#if blogPost.body} | ||
{#each blogPost.body as element} | ||
{@html element.value} | ||
{/each} | ||
{/if} | ||
</Section> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import type { BlogPost } from '$lib/utils/definitions'; | ||
|
||
export type Data = { | ||
blogPosts: BlogPost[]; | ||
}; | ||
|
||
export type Props = { | ||
data: Data; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters