summary refs log tree commit diff
path: root/lib/parsePost.ts
diff options
context:
space:
mode:
authorPatryk Niedźwiedziński <pniedzwiedzinski19@gmail.com>2020-01-28 11:55:03 +0100
committerPatryk Niedźwiedziński <pniedzwiedzinski19@gmail.com>2020-01-28 11:55:03 +0100
commit9f75ff1d2d5ebf34c040474e836e125f80253365 (patch)
tree523c52b9dd158e21d9247b58d81c655102323a26 /lib/parsePost.ts
parentc11d7a84aa59e9b1179a9834129b2d776bab8bca (diff)
downloadkronikarz-9f75ff1d2d5ebf34c040474e836e125f80253365.tar.gz
kronikarz-9f75ff1d2d5ebf34c040474e836e125f80253365.zip
Add Post class
Diffstat (limited to 'lib/parsePost.ts')
-rw-r--r--lib/parsePost.ts46
1 files changed, 0 insertions, 46 deletions
diff --git a/lib/parsePost.ts b/lib/parsePost.ts
deleted file mode 100644
index 2f5f2b9..0000000
--- a/lib/parsePost.ts
+++ /dev/null
@@ -1,46 +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 function parsePost(filePath: string): Post {
-  let [year, month, day, title] = filePath.split("/").splice(-4, 4);
-  title = title.substr(0, title.lastIndexOf("."));
-  const date = { year, month, day };
-  const fileContent = fs.readFileSync(filePath, "utf-8");
-  const content = getPostContent(fileContent);
-
-  return {
-    date,
-    title,
-    content,
-    filePath,
-    route: `/kronika/${year}/${month}/${day}/${title}`
-  };
-}