index.js 725 B

123456789101112131415161718192021
  1. import fs from "fs/promises"
  2. import matter from "gray-matter"
  3. import { getHref, slugifyString } from "../../util/index.js"
  4. import { createMarkdownRenderer } from "../_shared/markdown.js"
  5. export async function renderMarkdownToHtml({ config: actionConfig, meta }) {
  6. const filePath = actionConfig.filePath
  7. const fileOutputPath = actionConfig.fileOutputPath
  8. const content = await fs.readFile(filePath, "utf8")
  9. const { data, content: markdown } = matter(content)
  10. const href = getHref(fileOutputPath, meta)
  11. const renderer = createMarkdownRenderer(meta)
  12. const html = renderer(markdown)
  13. const detail = { ...data, href, content: html, fileOutputPath }
  14. return {
  15. detail,
  16. ref: slugifyString(filePath),
  17. }
  18. }