0

我正在开发一个 MDX 博客,并使用灰质来提取前端、内容和摘录。正如文档中提到的,我正在使用一个函数将内容的前 4 行提取为excerpt. 但这会提取文件的所有 4 行,包括标签/md 符号。

是否可以获得不包括符号的文件内容?

例如,我想要以下内容:

// returns the first 4 lines of the contents
function firstFourLines(file, options) {
  file.excerpt = file.content.split('\n').slice(0, 4).join(' ');
}

const file =  matter([
  '---',
  'foo: bar',
  '---',
  '# Only this',
  'will be',
  '<p>in the</p>',
  'excerpt',
  'but not this...'
].join('\n'), {excerpt: firstFourLines});

期望的输出:

{ 
  content: '# Only this\nwill be\n<p>in the</p>\nexcerpt\nbut not this...',
  data: { foo: 'bar' },
  excerpt: 'Only this will be in the excerpt'
}
}
4

0 回答 0