diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Post.ts | 9 | ||||
-rw-r--r-- | lib/interfaces.ts | 10 |
2 files changed, 11 insertions, 8 deletions
diff --git a/lib/Post.ts b/lib/Post.ts index 27a6cb9..f99ef83 100644 --- a/lib/Post.ts +++ b/lib/Post.ts @@ -38,13 +38,16 @@ export default class Post { getMeta(): Meta { const { attributes } = this.post; const author: string = attributes.author; - delete attributes.author; + if (!author) throw 'Error while parsing the author'; const title: string = attributes.title; - delete attributes.title; + if (!title) throw 'Error while parsing the title'; + const additionalMeta = Object.keys(attributes) + .filter((key) => key != 'title' && key != 'author') + .reduce((acc, key) => ({ ...acc, [key]: attributes[key] }), {}); return { author, title, - additionalMeta: attributes, + additionalMeta, }; } diff --git a/lib/interfaces.ts b/lib/interfaces.ts index 974765f..158ac1d 100644 --- a/lib/interfaces.ts +++ b/lib/interfaces.ts @@ -4,19 +4,19 @@ export interface Date { day: string; } -/*export interface Meta { - [key: string]: object; -}*/ +export interface Object { + [key: string]: any; +} export interface Meta { title: string; author: string; - additionalMeta: object; + additionalMeta: object; } export interface FrontMatterObject { body: string; - attributes: Meta; + attributes: Object; } export interface PostApiListEntry { |