diff --git a/src/routes/(marketing)/blog/(posts)/+layout.svelte b/src/routes/(marketing)/blog/(posts)/+layout.svelte index 1280fd09..b3dfc77a 100644 --- a/src/routes/(marketing)/blog/(posts)/+layout.svelte +++ b/src/routes/(marketing)/blog/(posts)/+layout.svelte @@ -4,45 +4,44 @@ import { sortedBlogPosts, type BlogPost } from "./../posts" import { WebsiteName } from "../../../../config" - let currentPost: BlogPost | null = null - for (const post of sortedBlogPosts) { - if ( - $page.url.pathname == post.link || - $page.url.pathname == post.link + "/" - ) { - currentPost = post - continue + function getCurrentPost(url: string): BlogPost { + let searchPost: BlogPost | null = null + for (const post of sortedBlogPosts) { + if (url == post.link || url == post.link + "/") { + searchPost = post + continue + } } + if (!searchPost) { + throw error(404, "Blog post not found") + } + return searchPost } - if (!currentPost) { - throw error(404, "Blog post not found") - } - - const pageTitle = currentPost?.title ? currentPost.title : "Not Found" - const pageDescription = currentPost?.description - ? currentPost.description - : "Blog post" - const pageUrl = $page.url.origin + $page.url.pathname + $: currentPost = getCurrentPost($page.url.pathname) - const ldJson = { - "@context": "https://schema.org", - "@type": "BlogPosting", - headline: pageTitle, - datePublished: currentPost.parsedDate?.toISOString(), - dateModified: currentPost.parsedDate?.toISOString(), + function buildLdJson(post: BlogPost) { + return { + "@context": "https://schema.org", + "@type": "BlogPosting", + headline: post.title, + datePublished: post.parsedDate?.toISOString(), + dateModified: post.parsedDate?.toISOString(), + } } - const jsonldScript = ` - {pageTitle} - + {currentPost.title} + - - + + @@ -50,8 +49,8 @@ - - + + @@ -60,17 +59,13 @@
- {#if currentPost == null} -

Blog post not found

- {:else} -
- {currentPost.parsedDate?.toLocaleDateString("en-US", { - month: "short", - day: "numeric", - year: "numeric", - })} -
-

{currentPost.title}

- - {/if} +
+ {currentPost.parsedDate?.toLocaleDateString("en-US", { + month: "short", + day: "numeric", + year: "numeric", + })} +
+

{currentPost.title}

+