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: **BREAKING** refactor frontmatter API #589

Merged
merged 1 commit into from
Dec 18, 2024
Merged

fix: **BREAKING** refactor frontmatter API #589

merged 1 commit into from
Dec 18, 2024

Conversation

3y3
Copy link
Member

@3y3 3y3 commented Dec 17, 2024

Description

Убрал излишнюю декомпозицию из frontmatter.
Заменил основные методы на extractFrontMatter и composeFrontMatter.
composeFrontMatter совместим с extractFrontMatter по аргументам

composeFrontMatter(...extractFrontMatter(content))

Поменял логику обновления сурсмапов:

  • Считаем линии ТОЛЬКО если сурсмапы включены
  • Считаем линии не через сплит контента на части - экономим память
  • Теперь это логика liquid а не frontmatter, что позволило убрать излишнюю декомпозицию

Большая пачка кода и тестов ушла из-за использования deepMergeWith

@3y3 3y3 requested a review from brotheroftux December 17, 2024 13:07
Copy link
Contributor

@brotheroftux brotheroftux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this.
As far as I understand, this is marked as a breaking change since we'd have to modify CLI's code to use the new API, right?

Comment on lines 59 to 61
.replace(/^\s+/gm, '')
.replace(/\n/g, ' ')
.trim();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say we could use ts-dedent here as well, granted that we started using it again in our codebases

Comment on lines +32 to +46
const matchMetadata = (fileContent: string) => {
if (!fileContent.startsWith(SEP)) {
return null;
}

const closeStart = fileContent.indexOf('\n' + SEP, SEP.length);
const closeEnd = fileContent.indexOf('\n', closeStart + 1);

if (closeStart === -1) {
return null;
}

return [fileContent.slice(SEP.length, closeStart).trim(), fileContent.slice(closeEnd + 1)];
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for refactoring the regexp monstrosity, I was lazy to do the same :)

const [metadata, strippedContent] = matches;

return [
cloneDeepWith(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, this is a fair change

@3y3 3y3 merged commit 3cdecd9 into master Dec 18, 2024
1 check passed
@3y3 3y3 deleted the frontmatter branch December 18, 2024 17:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants