| 123456789101112131415161718192021222324252627282930313233 |
- import fs from "fs"
- import path from "path"
- import matter from "gray-matter"
- import { marked } from "marked"
- import handlebars from "handlebars"
- import * as sass from "sass"
- import markedCodePreview from "marked-code-preview"
- const markedRenderer = marked.use({ gfm: true }).use(markedCodePreview)
- export function renderMarkdownWithTemplate(filePath, meta) {
- const content = fs.readFileSync(filePath, "utf8")
- const { data, content: markdown } = matter(content)
- const templateName = data.template || meta.opts.defaultTemplate
- const template = handlebars.compile(
- fs.readFileSync(
- path.join(meta.opts.templatesDir, `${templateName}.hbs`),
- "utf8",
- ),
- )
- const html = template({
- ...data,
- ...meta,
- content: markedRenderer(markdown),
- })
- return { result: html, detail: data }
- }
- export function compileSass(filePath, meta) {
- return {
- result: sass.compile(filePath, { style: "compressed" }).css.toString(),
- }
- }
|