mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-07 13:22:26 +02:00
fix(v2): ignore export declarations in excerpt (#3703)
This commit is contained in:
parent
86be6cec1e
commit
f2d1330207
2 changed files with 17 additions and 13 deletions
|
@ -188,21 +188,21 @@ export function getSubFolder(file: string, refDir: string): string | null {
|
|||
return match && match[1];
|
||||
}
|
||||
|
||||
// Regex for an import statement.
|
||||
const importRegexString = '^(.*import){1}(.+){0,1}\\s[\'"](.+)[\'"];?';
|
||||
|
||||
export function createExcerpt(fileString: string): string | undefined {
|
||||
let fileContent = fileString.trimLeft();
|
||||
|
||||
if (RegExp(importRegexString).test(fileContent)) {
|
||||
fileContent = fileContent
|
||||
.replace(RegExp(importRegexString, 'gm'), '')
|
||||
.trimLeft();
|
||||
}
|
||||
|
||||
const fileLines = fileContent.split('\n');
|
||||
const fileLines = fileString.trimLeft().split('\n');
|
||||
|
||||
/* eslint-disable no-continue */
|
||||
for (const fileLine of fileLines) {
|
||||
// Skip empty line.
|
||||
if (!fileLine.trim()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Skip import/export declaration.
|
||||
if (/^.*import\s.*from.*;?|export\s.*{.*};?/.test(fileLine)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const cleanedLine = fileLine
|
||||
// Remove HTML tags.
|
||||
.replace(/<[^>]*>/g, '')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue