mirror of
https://github.com/JonasunderscoreJones/blog.jonasjones.dev.git
synced 2025-10-22 21:29:18 +02:00
cleaned up loads of code
This commit is contained in:
parent
8b5f7bb7e8
commit
027917aa37
1 changed files with 0 additions and 71 deletions
|
@ -13,15 +13,6 @@
|
||||||
title: ""
|
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 postTitle = "";
|
||||||
let postAuthor = "";
|
let postAuthor = "";
|
||||||
let postDate = "";
|
let postDate = "";
|
||||||
|
@ -42,20 +33,6 @@
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
redirectUrl()
|
redirectUrl()
|
||||||
try {
|
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) {
|
if (params.month?.toString().length === 1) {
|
||||||
params.month = "0" + params.month
|
params.month = "0" + params.month
|
||||||
|
@ -68,11 +45,7 @@
|
||||||
|
|
||||||
if (await content.ok) {
|
if (await content.ok) {
|
||||||
let markdowncontent = await content.text();
|
let markdowncontent = await content.text();
|
||||||
console.log("MarkdownContent: " + markdowncontent);
|
|
||||||
console.log("Posts: ", posts)
|
|
||||||
console.log("Post: ", post)
|
|
||||||
const parsedContent = removeAndParsePostVars(markdowncontent);
|
const parsedContent = removeAndParsePostVars(markdowncontent);
|
||||||
console.log("ParsedContent: ", parsedContent)
|
|
||||||
markdowncontent = await marked.parse(parsedContent[0]);
|
markdowncontent = await marked.parse(parsedContent[0]);
|
||||||
const markdowncontentElement = document.getElementById('markdowncontent');
|
const markdowncontentElement = document.getElementById('markdowncontent');
|
||||||
if (markdowncontentElement) {
|
if (markdowncontentElement) {
|
||||||
|
@ -106,13 +79,6 @@
|
||||||
const date = extractMarkdownValue(content, 'date');
|
const date = extractMarkdownValue(content, 'date');
|
||||||
const description = extractMarkdownValue(content, 'description');
|
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
|
// with regex if the line begins with a markdown variable declaration, remove it
|
||||||
return [content.replace(/^\[.*?\]: .*$(?:\r?\n)?/gm, ''), title, author, date, description];
|
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() {
|
function copyLink() {
|
||||||
navigator.clipboard.writeText(location.href).then(() => {
|
navigator.clipboard.writeText(location.href).then(() => {
|
||||||
clickText = "Copied!";
|
clickText = "Copied!";
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue