summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/__tests__/index.spec.ts7
-rw-r--r--lib/__tests__/samples/2019/12/12/test.md11
-rw-r--r--lib/getPost.ts19
-rw-r--r--lib/getPosts.ts2
-rw-r--r--lib/index.ts4
-rw-r--r--lib/interfaces.ts6
-rw-r--r--lib/parsePost.ts2
7 files changed, 30 insertions, 21 deletions
diff --git a/lib/__tests__/index.spec.ts b/lib/__tests__/index.spec.ts
deleted file mode 100644
index 52e28ba..0000000
--- a/lib/__tests__/index.spec.ts
+++ /dev/null
@@ -1,7 +0,0 @@
-import Kronikarz from "..";
-
-test("basic", () => {
-  const k = new Kronikarz(__dirname + "/samples");
-  console.log(k.getPosts());
-  expect(k.getPosts().length).toBe(1);
-});
diff --git a/lib/__tests__/samples/2019/12/12/test.md b/lib/__tests__/samples/2019/12/12/test.md
deleted file mode 100644
index 5fc0158..0000000
--- a/lib/__tests__/samples/2019/12/12/test.md
+++ /dev/null
@@ -1,11 +0,0 @@
----
-title: Test
-description: test test
-author: Tester
----
-
-# Test
-
-12-12-2019 | Tester
-
-test test test
diff --git a/lib/getPost.ts b/lib/getPost.ts
new file mode 100644
index 0000000..2555215
--- /dev/null
+++ b/lib/getPost.ts
@@ -0,0 +1,19 @@
+import { parsePost } from "./parsePost";
+import { Post } from "./interfaces";
+
+interface getPostArgument {
+  year: string;
+  month: string;
+  day: string;
+  title: string;
+}
+
+export function getPost(
+  { year, month, day, title }: getPostArgument,
+  path: string
+): Post {
+  const filePath = `${path}/${year}/${month}/${day}/${title}.md`;
+
+  const post = parsePost(filePath);
+  return post;
+}
diff --git a/lib/getPosts.ts b/lib/getPosts.ts
index 69a353f..1821f12 100644
--- a/lib/getPosts.ts
+++ b/lib/getPosts.ts
@@ -1,5 +1,5 @@
 import { Post } from "./interfaces";
-import parsePost from "./parsePost";
+import { parsePost } from "./parsePost";
 import { readDir } from "./utils";
 
 function getPosts(path: string): Array<Post> {
diff --git a/lib/index.ts b/lib/index.ts
index 61e38c8..ade7180 100644
--- a/lib/index.ts
+++ b/lib/index.ts
@@ -1,3 +1,4 @@
+import { getPost as apiGetPost } from "./getPost";
 import { getPosts as apiGetPosts } from "./getPosts";
 import { Post } from "./interfaces";
 
@@ -11,4 +12,7 @@ export default class Kronikarz {
   getPosts(): Array<Post> {
     return apiGetPosts(this.postPath);
   }
+  getPost(year: string, month: string, day: string, title: string): Post {
+    return apiGetPost({ year, month, day, title }, this.postPath);
+  }
 }
diff --git a/lib/interfaces.ts b/lib/interfaces.ts
index 8c3493d..1d598c6 100644
--- a/lib/interfaces.ts
+++ b/lib/interfaces.ts
@@ -4,11 +4,15 @@ interface Date {
   day: string;
 }
 
+interface Meta {
+  [key: string]: string;
+}
+
 export interface PostContent {
   html: string;
   markdown: string;
   description: string;
-  meta: Object;
+  meta: Meta;
 }
 
 export interface Post {
diff --git a/lib/parsePost.ts b/lib/parsePost.ts
index 01e8d1c..416dd16 100644
--- a/lib/parsePost.ts
+++ b/lib/parsePost.ts
@@ -29,7 +29,7 @@ function getPostContent(fileContent: string): PostContent {
   };
 }
 
-export default function parsePost(filePath: string): Post {
+export function parsePost(filePath: string): Post {
   const [year, month, day, title] = filePath.split("/").splice(-4, 4);
   const date = { year, month, day };
   const fileContent = fs.readFileSync(filePath, "utf-8");