mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-12 08:37:25 +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:
|
output:
|
||||||
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ex urna, molestie et sagittis ut, varius ac justo.',
|
'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: `
|
input: `
|
||||||
import Component from '@site/src/components/Component';
|
import Component from '@site/src/components/Component';
|
||||||
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:.
|
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.
|
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];
|
return match && match[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Regex for an import statement.
|
|
||||||
const importRegexString = '^(.*import){1}(.+){0,1}\\s[\'"](.+)[\'"];?';
|
|
||||||
|
|
||||||
export function createExcerpt(fileString: string): string | undefined {
|
export function createExcerpt(fileString: string): string | undefined {
|
||||||
let fileContent = fileString.trimLeft();
|
const fileLines = fileString.trimLeft().split('\n');
|
||||||
|
|
||||||
if (RegExp(importRegexString).test(fileContent)) {
|
/* eslint-disable no-continue */
|
||||||
fileContent = fileContent
|
for (const fileLine of fileLines) {
|
||||||
.replace(RegExp(importRegexString, 'gm'), '')
|
// Skip empty line.
|
||||||
.trimLeft();
|
if (!fileLine.trim()) {
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const fileLines = fileContent.split('\n');
|
// Skip import/export declaration.
|
||||||
|
if (/^.*import\s.*from.*;?|export\s.*{.*};?/.test(fileLine)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
for (const fileLine of fileLines) {
|
|
||||||
const cleanedLine = fileLine
|
const cleanedLine = fileLine
|
||||||
// Remove HTML tags.
|
// Remove HTML tags.
|
||||||
.replace(/<[^>]*>/g, '')
|
.replace(/<[^>]*>/g, '')
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue