npm install front-matter --save
import frontMatter from "front-matter";
 
const content = `
---
title: Hello, world!
author: John Doe
date: 2021-05-31
---
 
This is the main content.
`;
 
const result = frontMatter(content);
console.log(result);
 
// 输出:
// {
//   attributes: { title: 'Hello, world!', author: 'John Doe', date: '2021-05-31' },
//   body: 'This is the main content.\n'
// }

扩展阅读