From 027917aa3759e69855d97c96702185bced06b975 Mon Sep 17 00:00:00 2001 From: J-onasJones Date: Fri, 28 Jun 2024 02:45:18 +0200 Subject: [PATCH] cleaned up loads of code --- src/routes/Post.svelte | 71 ------------------------------------------ 1 file changed, 71 deletions(-) diff --git a/src/routes/Post.svelte b/src/routes/Post.svelte index d70ca7a..57ffc20 100644 --- a/src/routes/Post.svelte +++ b/src/routes/Post.svelte @@ -13,15 +13,6 @@ title: "" }; - let posts: { id: any; }[] = []; - let post: {id: string, date: string, title: string, author: string, description: string} = { - id: '', - date: '', - title: '', - author: '', - description: '' - }; - let postTitle = ""; let postAuthor = ""; let postDate = ""; @@ -42,20 +33,6 @@ onMount(async () => { redirectUrl() try { - const response = await fetch('https://cdn.jonasjones.dev/blog/index.json'); - - posts = await response.json(); - - post = await findPostByDate(posts, params); - - if (await !post) { - loading = false; - error404 = true; - const markdowncontentElement = document.getElementById('markdowncontent'); - if (markdowncontentElement) { - markdowncontentElement.style.display = "none"; - } - } if (params.month?.toString().length === 1) { params.month = "0" + params.month @@ -68,11 +45,7 @@ if (await content.ok) { let markdowncontent = await content.text(); - console.log("MarkdownContent: " + markdowncontent); - console.log("Posts: ", posts) - console.log("Post: ", post) const parsedContent = removeAndParsePostVars(markdowncontent); - console.log("ParsedContent: ", parsedContent) markdowncontent = await marked.parse(parsedContent[0]); const markdowncontentElement = document.getElementById('markdowncontent'); if (markdowncontentElement) { @@ -106,13 +79,6 @@ const date = extractMarkdownValue(content, 'date'); const description = extractMarkdownValue(content, 'description'); - - console.log("The parsed stuff:") - console.log("Title: " + title) - console.log("Author: " + author) - console.log("Date: " + date) - console.log("Description: " + description) - // with regex if the line begins with a markdown variable declaration, remove it return [content.replace(/^\[.*?\]: .*$(?:\r?\n)?/gm, ''), title, author, date, description]; } @@ -128,43 +94,6 @@ } } - function findPostByDate(posts: any[], params: { year: any; month: any; day: any; title: any; }) { - return posts.find(post => { - - // Extract the year, month, and day from the Date object - const postYear = post.date.split('-')[0]; - const postMonth = post.date.split('-')[1]; - const postDay = post.date.split('-')[2]; - - if (params.month?.toString().length === 1) { - params.month = "0" + params.month - } - - if (params.day?.toString().length === 1) { - params.day = "0" + params.day - } - - console.log("PostYear: " + postYear) - console.log("PostMonth: " + postMonth) - console.log("PostDay: " + postDay) - - console.log("ParamsYear: " + params.year) - console.log("ParamsMonth: " + params.month) - console.log("ParamsDay: " + params.day) - - console.log("PostID: " + post.id) - console.log("ParamsTitle: " + params.title) - - // Compare the extracted year, month, and day with params, and the title - return ( - postYear === params.year && - postMonth === params.month && - postDay === params.day && - post.id === params.title - ); - }); -} - function copyLink() { navigator.clipboard.writeText(location.href).then(() => { clickText = "Copied!";