Add some development, services repository.

This commit is contained in:
Dave Smith-Hayes 2024-07-11 20:27:55 -04:00
parent db484c0bb1
commit 27e7c8f17b
3 changed files with 14 additions and 3 deletions

View File

@ -5,6 +5,7 @@ date: 2023-04-09
tags:
- development
- php
slug: contract-development
---
I have been mulling in my head for a while now about how I wanted to talk about this very common design pattern at work. [Designing by contract](https://en.wikipedia.org/wiki/Design_by_contract) is a very old idea in software and I have found myself having to explain it and teach it other developers at work. So hopefully in this post, I can elaborate on why using a contract is beneficial in the design and development of large applications.

View File

@ -4,12 +4,18 @@ import type { Post } from '@blog/models/Post';
import * as yamlFront from 'yaml-front-matter';
import { marked } from 'marked';
export async function readPostFile(fileName: string): Promise<Post> {
const file = Bun.file(POST_PATH + '/' + fileName);
export async function readPostFile(path: string): Promise<Post> {
const file = Bun.file(path);
const fileContent = await file.text();
const parsedData = yamlFront.loadFront(fileContent);
const postHtml = await marked.parse(parsedData.__content);
let slug = parsedData.slug;
if (!slug) {
slug = path.split('/').pop().slice(0, -3);
}
return {
meta: {
title: parsedData.title,
@ -17,7 +23,7 @@ export async function readPostFile(fileName: string): Promise<Post> {
date: new Date(parsedData.date),
draft: parsedData?.draft || false,
tags: parsedData.tags,
slug: POST_ROUTE_PREFIX + '/' + fileName,
slug: slug
},
content: parsedData.__content,
html: postHtml

View File

@ -0,0 +1,4 @@
export class PostRepository {
}