BlogEngine: Remove all references to old posts.json and Python scripts
This commit is contained in:
parent
6931e2a414
commit
6c8083593f
7 changed files with 0 additions and 116 deletions
|
|
@ -1,49 +0,0 @@
|
|||
import glob
|
||||
import frontmatter
|
||||
import json
|
||||
from datetime import datetime
|
||||
from datetime import date
|
||||
from dateutil.parser import *
|
||||
from markdown import markdown
|
||||
|
||||
"""
|
||||
Build a hashamp of all blog posts and book reviews used in the blog.
|
||||
This is used on both the blog/index page, and the blog/[svelte] pages to
|
||||
render out a list of posts (and fetch more detail) to prevent the need
|
||||
to re-fetch on every request
|
||||
"""
|
||||
|
||||
blog_posts = glob.glob('./src/content/**/*.md')
|
||||
hash_map = {}
|
||||
|
||||
for file in blog_posts:
|
||||
try:
|
||||
post = frontmatter.load(file)
|
||||
slug = post['slug']
|
||||
frontmatter_keys = post.keys()
|
||||
|
||||
published_date = post['date']
|
||||
|
||||
# We want a datetime, note a date
|
||||
if isinstance(published_date, date):
|
||||
published_date = datetime.combine(published_date, datetime.min.time())
|
||||
|
||||
details = {
|
||||
'title': post['title'],
|
||||
'author': post['author'],
|
||||
'date': published_date.isoformat(),
|
||||
'book_review': 'book_review' in frontmatter_keys,
|
||||
'preview': post.content[0:180],
|
||||
'content': markdown(post.content),
|
||||
'slug': slug
|
||||
}
|
||||
hash_map[slug] = details
|
||||
except Exception as e:
|
||||
print("!!!")
|
||||
print("Caught Error in following file, ignoring")
|
||||
print(file)
|
||||
print(e)
|
||||
print("---")
|
||||
|
||||
with open('./src/content/posts.json', "w") as file:
|
||||
json.dump(hash_map, file)
|
||||
File diff suppressed because one or more lines are too long
|
|
@ -1,18 +0,0 @@
|
|||
export type PostMetadata = {
|
||||
title: string;
|
||||
author: string;
|
||||
slug: string;
|
||||
draft: boolean;
|
||||
date: Date;
|
||||
html: string;
|
||||
content: string
|
||||
|
||||
image?: string;
|
||||
book_review?: boolean;
|
||||
finished?: string;
|
||||
score?: number; // out of 5
|
||||
tags?: string[];
|
||||
links?: { country: string; store_name: string; link: string }[];
|
||||
};
|
||||
|
||||
export type Post = PostMetadata & { filename: string };
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
import type { Post } from './Post';
|
||||
import { getPostsFromGlobResult } from './getPostsFromGlobResult';
|
||||
import allPosts from '../content/posts.json'
|
||||
|
||||
export const fetchBlogPostBySlug = async (slug: string): Promise<Post | null> => {
|
||||
|
||||
const post = allPosts[slug]
|
||||
|
||||
if (!post) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return post;
|
||||
};
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
import { getPostsFromGlobResult } from './getPostsFromGlobResult';
|
||||
import type { Post } from './Post';
|
||||
export const fetchBlogPosts = async (): Promise<Post[]> => {
|
||||
const files = await import.meta.glob('../content/**/*.md');
|
||||
|
||||
return await getPostsFromGlobResult(files);
|
||||
};
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
import type { Post } from './Post';
|
||||
|
||||
export async function getPostsFromGlobResult(result: Record<string, any>): Promise<Post[]> {
|
||||
const allPosts: Array<Post | null> = await Promise.all(
|
||||
Object.entries(result).map(async ([filename, resolver]) => {
|
||||
try {
|
||||
const {
|
||||
metadata,
|
||||
default: { render, $$render, ...rest }
|
||||
} = await resolver();
|
||||
const { html } = render();
|
||||
const { date, ...data } = metadata;
|
||||
return {
|
||||
...data,
|
||||
html,
|
||||
date: new Date(date),
|
||||
filename
|
||||
};
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
return allPosts.filter((post) => post !== null) as Post[];
|
||||
}
|
||||
|
|
@ -1,6 +1,5 @@
|
|||
<script lang="ts">
|
||||
import type { PageData } from "./$types.js";
|
||||
import type { Post } from "$lib/Post.js";
|
||||
import { intlFormat } from "date-fns";
|
||||
import Navbar from "$lib/components/Navbar.svelte";
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue