diff --git a/posts/contract-development.md b/posts/contract-development.md index 68965b3..5f4eb44 100644 --- a/posts/contract-development.md +++ b/posts/contract-development.md @@ -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. diff --git a/src/services/post-file.ts b/src/services/post-file.ts index 6e376b4..1a10f77 100644 --- a/src/services/post-file.ts +++ b/src/services/post-file.ts @@ -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 { - const file = Bun.file(POST_PATH + '/' + fileName); +export async function readPostFile(path: string): Promise { + 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 { date: new Date(parsedData.date), draft: parsedData?.draft || false, tags: parsedData.tags, - slug: POST_ROUTE_PREFIX + '/' + fileName, + slug: slug }, content: parsedData.__content, html: postHtml diff --git a/src/services/post-repository.ts b/src/services/post-repository.ts new file mode 100644 index 0000000..8099153 --- /dev/null +++ b/src/services/post-repository.ts @@ -0,0 +1,4 @@ + +export class PostRepository { + +}