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

Compact fix for color generation in theme.json #3222

Merged
merged 3 commits into from
Feb 5, 2025

Conversation

codewithfeeling
Copy link
Contributor

@codewithfeeling codewithfeeling commented Feb 5, 2025

While testing I found that the themeContent CSS sometimes does not contain a closing curly bracket, meaning the index of the last bracket was -1. This cut off the final --color-example: #abcdef definition by one character, leading to the generated theme.json color for that one to be:

{
          "name": "example",
          "slug": "example",
          "color": "#abcde"
 }

By checking for the presence of the final bracket, we can either slice to there, or to the end of the content if it is not present.

const endIndex = themeContent.lastIndexOf('}');
const rootContent = themeContent.slice(themeContent.indexOf('{') + 1, endIndex === -1 ? undefined : endIndex);

Copy link
Member

@retlehs retlehs left a comment

Choose a reason for hiding this comment

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

Thank you!

@retlehs retlehs merged commit 04b2404 into roots:main Feb 5, 2025
3 checks passed
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