Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(v2): ignore import declarations in excerpt #2380

Merged
merged 3 commits into from
Apr 22, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions packages/docusaurus-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ export function getSubFolder(file: string, refDir: string): string | null {
return match && match[1];
}

const importRegexString = '^(.*import){1}(.+){0,1}\\s[\'"](.+)[\'"];';

export function parse(
fileString: string,
): {
Expand All @@ -191,10 +193,15 @@ export function parse(
} {
const options: {} = {
excerpt: (file: matter.GrayMatterFile<string>): void => {
file.excerpt = file.content
.trim()
.split('\n', 1)
.shift();
let fileContent = file.content.trimLeft();

if (RegExp(importRegexString).test(fileContent)) {
lex111 marked this conversation as resolved.
Show resolved Hide resolved
fileContent = fileContent
.replace(RegExp(importRegexString, 'gm'), '')
.trimLeft();
}

file.excerpt = fileContent.split('\n', 1).shift();
},
};

Expand Down