Add some development, services repository.
This commit is contained in:
parent
db484c0bb1
commit
27e7c8f17b
@ -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.
|
||||
|
@ -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
|
||||
|
4
src/services/post-repository.ts
Normal file
4
src/services/post-repository.ts
Normal file
@ -0,0 +1,4 @@
|
||||
|
||||
export class PostRepository {
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user