1
0
Fork 0
mirror of https://github.com/muerwre/vk-tg-bot.git synced 2025-04-25 06:56:40 +07:00

#2 added PostNewHandler.ts

This commit is contained in:
Fedor Katurov 2021-04-29 15:18:24 +07:00
parent 61f0440cb6
commit 8c17836868
10 changed files with 183 additions and 15 deletions

View file

@ -8,6 +8,10 @@ import toVFile from "to-vfile";
import path from "path";
import hb from "handlebars";
const removeFrontmatter = () => (tree) => {
tree.children = tree.children.filter((item) => item.type !== "yaml");
};
export class Template<
F extends Record<string, any>,
V extends Record<string, any>
@ -22,19 +26,17 @@ export class Template<
}
const processor = unified()
.use(parser)
.use(compiler)
.use(frontmatter)
.use(extract, { yaml: parse });
.use(extract, { yaml: parse })
.use(removeFrontmatter)
.use(parser);
const file = toVFile.readSync(path.join(__dirname, "../../", filename));
const result = processor.processSync(file);
this.fields = result.data as F;
this.template = result
.toString()
.replace(/^---\n(.*)---\n?$/gms, "")
.trim();
this.template = result.contents.toString().trim();
} catch (e) {
throw new Error(`Template: ${e.toString()}`);
}