Post, projects content functions

This commit is contained in:
matthieu42morin 2024-04-04 20:07:18 +02:00
parent 80757d37b1
commit ff649cc9e9
2 changed files with 17 additions and 9 deletions

View File

@ -1,11 +1,11 @@
import type { BlogPost } from '$lib/types/blog';
import type { Post } from '$lib/types/post';
import type { MarkdownMetadata } from '$content/types';
import type { MdsvexImport } from './types';
import { parseReadContent } from '$content/utils';
import { error } from '@sveltejs/kit';
export function listBlogPosts() {
const posts = import.meta.glob<BlogPost>('./blog/*.md', {
export function listPosts() {
const posts = import.meta.glob<Post>('./blog/*.md', {
eager: true,
import: 'metadata'
});
@ -13,14 +13,14 @@ export function listBlogPosts() {
return parseReadContent(posts);
}
export async function getBlogPostMetadata(slug: string) {
const { post } = await getBlogPost(slug);
export async function getPostMetadata(slug: string) {
const { post } = await getPost(slug);
return post;
}
export async function getBlogPost(slug: string) {
export async function getPost(slug: string) {
try {
const data: MdsvexImport<BlogPost & MarkdownMetadata> = await import(`./blog/${slug}.md`);
const data: MdsvexImport<Post & MarkdownMetadata> = await import(`./blog/${slug}.md`);
return {
post: { ...data.metadata, slug },

View File

@ -1,4 +1,6 @@
import type { MarkdownMetadata, MdsvexImport } from './types';
import type { MdsvexImport } from '$content/types';
import type { MarkdownMetadata } from '$content/types';
import type { Project } from '$lib/types/projects';
import { parseReadContent } from './utils';
import { error } from '@sveltejs/kit';
@ -13,10 +15,16 @@ export function listProjects() {
return parseReadContent(projects);
}
export async function getProjectMetadata(slug: string) {
const { post } = await getProject(slug);
return post;
}
export async function getProject(slug: string) {
try {
const data: MdsvexImport<Project> = await import(`./projects/${slug}.md`);
const data: MdsvexImport<Project & MarkdownMetadata> = await import(
`./projects/${slug}.md`
);
return {
post: { ...data.metadata, slug },