Get the post file service fleshed out

This commit is contained in:
Dave Smith-Hayes 2024-07-09 21:44:52 -04:00
parent 87fd7b129b
commit db484c0bb1

View File

@ -44,23 +44,27 @@ export class PostFileService {
return new PostFileService(posts);
}
public getPostHtml(slug: string): string {
const html = this.posts.get(slug)?.html;
public getPost(slug: string): Post {
const post = this.posts.get(slug);
if (!html?.length) {
throw new Error("Post does not exist.");
if (!post) {
throw Error("Post does not exist.");
}
return post;
}
public getPostHtml(slug: string): string {
const html = this.getPost(slug).html;
if (!html) {
throw Error("No HTML for this post yet.");
}
return html;
}
public getPostRawContent(slug: string): string {
const content = this.posts.get(slug)?.content;
if (!content?.length) {
throw new Error("Post does not exist.");
}
return content;
return this.getPost(slug).content;
}
}