2018-08-27 02:01:18 +02:00
|
|
|
import * as grayMatter from 'gray-matter';
|
2016-11-13 23:11:49 +01:00
|
|
|
|
2018-08-27 02:01:18 +02:00
|
|
|
export type TFrontMatter = 'yaml' | 'json';
|
2016-11-13 23:11:49 +01:00
|
|
|
|
|
|
|
export interface ISmartfmContructorOptions {
|
2018-08-27 02:01:18 +02:00
|
|
|
fmType: TFrontMatter;
|
2016-11-13 23:11:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* class smartfm handles frontmatter
|
|
|
|
*/
|
|
|
|
export class Smartfm {
|
2018-08-27 02:01:18 +02:00
|
|
|
fmType: TFrontMatter;
|
2017-03-11 22:34:28 +01:00
|
|
|
|
|
|
|
constructor(optionsArg: ISmartfmContructorOptions) {
|
2018-08-27 02:01:18 +02:00
|
|
|
this.fmType = optionsArg.fmType;
|
2017-03-11 22:34:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* add frontmatter to a string
|
|
|
|
*/
|
|
|
|
stringify(bodyString: string, frontmatterData: any) {
|
2018-08-27 02:01:18 +02:00
|
|
|
return grayMatter.stringify(bodyString, frontmatterData);
|
2017-03-11 22:34:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* parse a string that has frontmatter attached, YAML notation
|
|
|
|
*/
|
2018-08-27 02:01:18 +02:00
|
|
|
parse(stringToParse: string) {
|
|
|
|
return grayMatter(stringToParse);
|
2017-03-11 22:34:28 +01:00
|
|
|
}
|
2016-11-13 23:11:49 +01:00
|
|
|
}
|