mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-11 08:07: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
|
@ -374,12 +374,16 @@ describe('load utils', () => {
|
|||
output:
|
||||
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ex urna, molestie et sagittis ut, varius ac justo.',
|
||||
},
|
||||
// Content with imports declarations and Markdown markup, as well as Emoji
|
||||
// Content with imports/exports declarations and Markdown markup, as well as Emoji
|
||||
{
|
||||
input: `
|
||||
import Component from '@site/src/components/Component';
|
||||
import Component from '@site/src/components/Component'
|
||||
|
||||
export function ItemCol(props) { return <Item {...props} className={'col col--6 margin-bottom--lg'}/> }
|
||||
|
||||
export function ItemCol(props) { return <Item {...props} className={'col col--6 margin-bottom--lg'}/> };
|
||||
|
||||
Lorem **ipsum** dolor sit \`amet\`[^1], consectetur _adipiscing_ elit. [**Vestibulum**](https://wiktionary.org/wiki/vestibulum) ex urna[^bignote], ~molestie~ et sagittis ut, varius ac justo :wink:.
|
||||
|
||||
Nunc porttitor libero nec vulputate venenatis. Nam nec rhoncus mauris. Morbi tempus est et nibh maximus, tempus venenatis arcu lobortis.
|
||||
|
|
|
@ -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