the-dataface / figma2html

Export Figma frames as responsive HTML and CSS
https://www.figma.com/community/plugin/1109185297790825980/figma2html
MIT License
48 stars 8 forks source link

Fix corrupt google font urls #111

Closed sawyerclick closed 6 months ago

sawyerclick commented 6 months ago

Closes #109. The Google font detection was faulty and frequently created output with 'undefined' in the url. We weren't properly detecting variant fonts like "Roboto Condensed" vs. "Roboto".

For the nerds, Figma rolls up "Roboto Condensed" into "Roboto" so the style string would look like "Condensed ExtraBold Italic" and the fontName would be "Roboto". This is not ideal for us. I've added a simple detection in the script to uncover if theres a variant and apply it back to the font name.

// detect if there's a variant such as Condensed.
// Figma rolls Condensed, which is technically its own typeface, into the Roboto family here.
// it always shows up as the first word in the style string
// EX: Condensed ExtraBold Italic
const variant =
    (style.includes('Italic') ? style.split(' ').length === 3 : style.split(' ').length === 2) &&
    style.split(' ')[0];

// if there's a variant, remove it from the style and append to the family name
if (variant) {
    family = `${family} ${variant}`;
    style = style.replace(`${variant} `, '');
}
changeset-bot[bot] commented 6 months ago

🦋 Changeset detected

Latest commit: d910c8d5fd2210e31764fd8ba21b773d98f0d8b4

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package | Name | Type | | ---------- | ----- | | figma2html | Patch |

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR