diff options
author | Patryk Niedźwiedziński <pniedzwiedzinski19@gmail.com> | 2019-10-13 23:48:12 +0200 |
---|---|---|
committer | Patryk Niedźwiedziński <pniedzwiedzinski19@gmail.com> | 2019-10-13 23:48:12 +0200 |
commit | 4274595b251632ef004d5f1429d7fbdde1cd4a5a (patch) | |
tree | c8a5ac120ddd03e161ecac522b1180f3a815cf70 /src | |
parent | 0ccea881106946b66d167eee0ec8116ae4e3019e (diff) | |
download | kronikarz-4274595b251632ef004d5f1429d7fbdde1cd4a5a.tar.gz kronikarz-4274595b251632ef004d5f1429d7fbdde1cd4a5a.zip |
Add publish options
Diffstat (limited to 'src')
-rw-r--r-- | src/__tests__/index.spec.ts | 7 | ||||
-rw-r--r-- | src/__tests__/samples/2019/12/12/test.md | 11 | ||||
-rw-r--r-- | src/getPosts.ts | 36 | ||||
-rw-r--r-- | src/index.ts | 14 | ||||
-rw-r--r-- | src/interfaces.ts | 20 | ||||
-rw-r--r-- | src/parsePost.ts | 45 | ||||
-rw-r--r-- | src/utils.ts | 9 |
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`; - } -} |