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 { MarkdownMetadata } from '$content/types';
import type { MdsvexImport } from './types'; import type { MdsvexImport } from './types';
import { parseReadContent } from '$content/utils'; import { parseReadContent } from '$content/utils';
import { error } from '@sveltejs/kit'; import { error } from '@sveltejs/kit';
export function listBlogPosts() { export function listPosts() {
const posts = import.meta.glob<BlogPost>('./blog/*.md', { const posts = import.meta.glob<Post>('./blog/*.md', {
eager: true, eager: true,
import: 'metadata' import: 'metadata'
}); });
@ -13,14 +13,14 @@ export function listBlogPosts() {
return parseReadContent(posts); return parseReadContent(posts);
} }
export async function getBlogPostMetadata(slug: string) { export async function getPostMetadata(slug: string) {
const { post } = await getBlogPost(slug); const { post } = await getPost(slug);
return post; return post;
} }
export async function getBlogPost(slug: string) { export async function getPost(slug: string) {
try { try {
const data: MdsvexImport<BlogPost & MarkdownMetadata> = await import(`./blog/${slug}.md`); const data: MdsvexImport<Post & MarkdownMetadata> = await import(`./blog/${slug}.md`);
return { return {
post: { ...data.metadata, slug }, 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 { parseReadContent } from './utils';
import { error } from '@sveltejs/kit'; import { error } from '@sveltejs/kit';
@ -13,10 +15,16 @@ export function listProjects() {
return parseReadContent(projects); return parseReadContent(projects);
} }
export async function getProjectMetadata(slug: string) {
const { post } = await getProject(slug);
return post;
}
export async function getProject(slug: string) { export async function getProject(slug: string) {
try { try {
const data: MdsvexImport<Project> = await import(`./projects/${slug}.md`); const data: MdsvexImport<Project & MarkdownMetadata> = await import(
`./projects/${slug}.md`
);
return { return {
post: { ...data.metadata, slug }, post: { ...data.metadata, slug },