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:
parent
61f0440cb6
commit
8c17836868
10 changed files with 183 additions and 15 deletions
|
@ -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()}`);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue