summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/__tests__/index.spec.ts7
-rw-r--r--src/__tests__/samples/2019/12/12/test.md11
-rw-r--r--src/getPosts.ts36
-rw-r--r--src/index.ts14
-rw-r--r--src/interfaces.ts20
-rw-r--r--src/parsePost.ts45
-rw-r--r--src/utils.ts9
7 files changed, 0 insertions, 142 deletions
diff --git a/src/__tests__/index.spec.ts b/src/__tests__/index.spec.ts
deleted file mode 100644
index 52e28ba..0000000
--- a/src/__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/src/__tests__/samples/2019/12/12/test.md b/src/__tests__/samples/2019/12/12/test.md
deleted file mode 100644
index 5fc0158..0000000
--- a/src/__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/src/getPosts.ts b/src/getPosts.ts
deleted file mode 100644
index 4170292..0000000
--- a/src/getPosts.ts
+++ /dev/null
@@ -1,36 +0,0 @@
-import * as fs from "fs";
-import { Post } from "./interfaces";
-import parsePost from "./parsePost";
-import { readDir } from "./utils";
-
-function getPosts(path: string): Array<Post> {
-  let routesArray: Post[] = [];
-  try {
-    const years = readDir(`${path}`);
-    years.forEach((year: string) => {
-      const months = readDir(`${path}/${year}`);
-      months.forEach((month: string) => {
-        const days = readDir(`${path}/${year}/${month}`);
-        days.forEach((day: string) => {
-          const files = readDir(`${path}/${year}/${month}/${day}`);
-          files.forEach((file: string) => {
-            const fsRoute = `${path}/${year}/${month}/${day}/${file}`;
-
-            const post = parsePost(fsRoute);
-
-            routesArray.push(post);
-          });
-        });
-      });
-    });
-  } finally {
-    return routesArray;
-  }
-}
-
-function createRoutesArray() {
-  // let posts = getPosts();
-  // return posts.map(post => post.route);
-}
-
-export { getPosts, createRoutesArray };
diff --git a/src/index.ts b/src/index.ts
deleted file mode 100644
index 61e38c8..0000000
--- a/src/index.ts
+++ /dev/null
@@ -1,14 +0,0 @@
-import { getPosts as apiGetPosts } from "./getPosts";
-import { Post } from "./interfaces";
-
-export default class Kronikarz {
-  postPath: string;
-
-  constructor(postPath: string) {
-    this.postPath = postPath;
-  }
-
-  getPosts(): Array<Post> {
-    return apiGetPosts(this.postPath);
-  }
-}
diff --git a/src/interfaces.ts b/src/interfaces.ts
deleted file mode 100644
index 8c3493d..0000000
--- a/src/interfaces.ts
+++ /dev/null
@@ -1,20 +0,0 @@
-interface Date {
-  year: string;
-  month: string;
-  day: string;
-}
-
-export interface PostContent {
-  html: string;
-  markdown: string;
-  description: string;
-  meta: Object;
-}
-
-export interface Post {
-  date: Date;
-  title: string;
-  content: PostContent;
-  filePath: string;
-  route: string;
-}
diff --git a/src/parsePost.ts b/src/parsePost.ts
deleted file mode 100644
index 01e8d1c..0000000
--- a/src/parsePost.ts
+++ /dev/null
@@ -1,45 +0,0 @@
-import * as fs from "fs";
-import { JSDOM } from "jsdom";
-import { Post, PostContent } from "./interfaces";
-
-const frontmatter = require("front-matter");
-const md = require("markdown-it")();
-
-function getDescription(html: string): string {
-  const { document } = new JSDOM(`<div>${html}</div>`).window;
-  const elements = document.getElementsByTagName("p");
-
-  const description = elements[1].textContent;
-
-  return description || "";
-}
-
-function getPostContent(fileContent: string): PostContent {
-  const post = frontmatter(fileContent);
-
-  const markdown = post.body;
-  const html = `<div>${md.render(markdown)}</div>`;
-  const description = getDescription(html);
-
-  return {
-    html,
-    markdown,
-    description,
-    meta: post.attributes
-  };
-}
-
-export default 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");
-  const content = getPostContent(fileContent);
-
-  return {
-    date,
-    title: title.substr(0, title.lastIndexOf(".")),
-    content,
-    filePath,
-    route: `/kronika/${year}/${month}/${day}/${title}`
-  };
-}
diff --git a/src/utils.ts b/src/utils.ts
deleted file mode 100644
index 23a3947..0000000
--- a/src/utils.ts
+++ /dev/null
@@ -1,9 +0,0 @@
-import * as fs from "fs";
-
-export function readDir(path: string): Array<string> {
-  if (fs.existsSync(path)) {
-    return fs.readdirSync(path);
-  } else {
-    throw `Path "${path}" doesn't exist`;
-  }
-}