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

metrics: Prefer public family name to internal familyName metrics #191

Merged
merged 1 commit into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
53 changes: 53 additions & 0 deletions .changeset/funny-trees-listen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
'@capsizecss/metrics': major
---

metrics: Prefer public family name to internal `familyName` metrics

Ensure metrics are available using the public family name as seen on Google Fonts as opposed to the internal family name metric.
This makes sense as consumers are looking to import the metrics relevant to a specific system font or from Google Fonts (also aligns with the names Google use in their font declarations generated in the hosted stylesheets).

### BREAKING CHANGES:

#### Google Fonts

Previously, the metrics were imported with a path that used the internal family name, now they align with the font as seen on Google Fonts.

```diff
-import metrics from '@capsizecss/metrics/roundedMplus1c';
+import metrics from '@capsizecss/metrics/mPLUSRounded1c';
```

With only a small number of Google Fonts affected, this is only a break for the following fonts:
- Ballet
- Bodoni Moda
- Buda
- Bungee Spice
- Fjord One
- Geologica
- Imbue
- M PLUS Rounded 1c
- Material Symbols Outlined
- Material Symbols Rounded
- Material Symbols Sharp
- Montagu Slab
- Nanum Pen Script
- Newsreader
- Nunito Sans
- Pathway Extreme
- Sono
- Sunflower
- Supermercado One
- Texturina


#### System fonts

The system fonts only had one example where the names diverged:

```diff
-import metrics from '@capsizecss/metrics/brushScriptMT';
+import metrics from '@capsizecss/metrics/brushScript';
```

This now aligns with the name consumers use to reference the font on their system.
27 changes: 16 additions & 11 deletions packages/metrics/scripts/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const extractor: Record<SourceType, typeof fromFile | typeof fromUrl> = {
};

export type FontSourceList = Array<{
family: string;
variants?: string[];
files: Record<string, string>;
category: FontCategory;
Expand Down Expand Up @@ -58,17 +59,21 @@ const metricsForFamily = async ({
});

const result = await queue.addAll(
fonts.map(({ files, variants = [], overrides, category }) => async () => {
const variant = files.regular ? 'regular' : variants[0];
const url = files[variant];
const metrics = await extractor[sourceType](url);

return {
...metrics,
...overrides,
category,
};
}),
fonts.map(
({ family, files, variants = [], overrides, category }) =>
async () => {
const variant = files.regular ? 'regular' : variants[0];
const url = files[variant];
const metrics = await extractor[sourceType](url);

return {
...metrics,
...overrides,
familyName: family,
category,
};
},
),
);

progress.stop();
Expand Down
Loading
Loading