Get post data associated with current blog post being read

This commit is contained in:
Sveske_Juice 2024-02-26 20:06:38 +01:00
parent 550b1410e3
commit 110720ea59
9 changed files with 38 additions and 21 deletions

View File

@ -13,7 +13,7 @@
</script> </script>
<div class="news-card"> <div class="news-card">
<a href=/post/{post_url}> <a href={post_url}>
<div class="thumbnail"> <div class="thumbnail">
<img src={thumbnail_url} alt={thumbnail_alt}/> <img src={thumbnail_url} alt={thumbnail_alt}/>
</div> </div>

View File

@ -3,25 +3,16 @@
* for all posts on the website. * for all posts on the website.
*/ */
import { posts } from './post/posts_data'; import { type Post, posts } from './posts/posts_data';
// Basically the same as Post but might contain less infomation - save storage
type Summary = {
url : string,
title : string,
summary : string,
creation_date : number,
modification_date: number,
};
export function load() { export function load() {
let summaries : Summary[] = []; let summaries : Post[] = [];
// Sort by newest news first // Sort by newest news first
posts.sort((a, b) => b.creation_date - a.creation_date); posts.sort((a, b) => b.creation_date - a.creation_date);
posts.map((post) => { posts.map((post) => {
let summary : Summary = { let summary : Post = {
url: post.url, url: post.url,
title : post.title, title : post.title,
summary : post.summary, summary : post.summary,

View File

@ -1,5 +1,5 @@
<script lang="ts"> <script lang="ts">
import { fade, fly } from 'svelte/transition'; import { fly } from 'svelte/transition';
import MediaQuery from 'svelte-media-queries'; import MediaQuery from 'svelte-media-queries';
const footerCollapseThreshold : string = '1000px'; const footerCollapseThreshold : string = '1000px';
@ -30,7 +30,7 @@
<div class="nav-spacer" /> <div class="nav-spacer" />
<a href="/">Home</a> <a href="/">Home</a>
<a href="/games">Games</a> <a href="/games">Games</a>
<a href="/post">Blog</a> <a href="/posts">Blog</a>
<a href="/about">About</a> <a href="/about">About</a>
</div> </div>
{:else} {:else}
@ -48,7 +48,7 @@
<div class="nav-list" transition:fly={{ y: -25, duration: 350 }}> <div class="nav-list" transition:fly={{ y: -25, duration: 350 }}>
<a on:click={resetNavBar} href="/">Home</a> <a on:click={resetNavBar} href="/">Home</a>
<a on:click={resetNavBar} href="/games">Games</a> <a on:click={resetNavBar} href="/games">Games</a>
<a on:click={resetNavBar} href="/post">Blog</a> <a on:click={resetNavBar} href="/posts">Blog</a>
<a on:click={resetNavBar} href="/about">About</a> <a on:click={resetNavBar} href="/about">About</a>
</div> </div>
{/if} {/if}

View File

@ -39,7 +39,7 @@
<footer id="news-footer"> <footer id="news-footer">
<div class="dummy"/> <div class="dummy"/>
<div id="more-posts"> <div id="more-posts">
<Button href="/post" type={ButtonType.Primary}> <Button href="/posts" type={ButtonType.Primary}>
<span slot="content">More News</span> <span slot="content">More News</span>
</Button> </Button>
</div> </div>

View File

@ -1,5 +1,12 @@
<!-- Layout for posts --> <!-- Layout for posts -->
<script lang="ts">
import { type BlogData } from './+layout';
export let data : BlogData
</script>
{#if data}
<h3>{data.post.title}</h3>
{/if}
<slot /> <slot />

View File

@ -0,0 +1,17 @@
import { posts, type Post } from '../posts/posts_data';
export interface BlogData {
summaries: Post[],
post: Post
}
export async function load({ url, parent }) : Promise<BlogData> {
const { summaries } = await parent();
const websiteUrl = url.pathname.split('/');
const windowUrl = websiteUrl.pop() || websiteUrl.pop(); // Handle trailing /
return {
summaries: summaries,
post: posts.filter((post) => post.url == windowUrl)[0],
};
}

View File

@ -0,0 +1,2 @@
Lorem ipsum dolor sit amet, officia excepteur ex fugiat reprehenderit enim labore culpa sint ad nisi Lorem pariatur mollit ex esse exercitation amet. Nisi anim cupidatat excepteur officia. Reprehenderit nostrud nostrud ipsum Lorem est aliquip amet voluptate voluptate dolor minim nulla est proident. Nostrud officia pariatur ut officia. Sit irure elit esse ea nulla sunt ex occaecat reprehenderit commodo officia dolor Lorem duis laboris cupidatat officia voluptate. Culpa proident adipisicing id nulla nisi laboris ex in Lorem sunt duis officia eiusmod. Aliqua reprehenderit commodo ex non excepteur duis sunt velit enim. Voluptate laboris sint cupidatat ullamco ut ea consectetur et est culpa et culpa duis.

View File

@ -24,7 +24,7 @@
{/if} {/if}
{#each matched_posts as summary} {#each matched_posts as summary}
<NewsVerticalCard <NewsVerticalCard
post_url={summary.url} post_url="/post/{summary.url}"
title={summary.title} title={summary.title}
summary={summary.summary} summary={summary.summary}
creation_date={summary.creation_date.toString()} creation_date={summary.creation_date.toString()}