diff --git a/src/services/post-file.ts b/src/services/post-file.ts index 24f6212..6e376b4 100644 --- a/src/services/post-file.ts +++ b/src/services/post-file.ts @@ -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; } }