Skip to content

Commit 461602d

Browse files
authored
feat(material/schematics): use newer Google Fonts version (#21479)
Switches the schematics, guides and internal dev apps to use the second version of the Google Fonts loading snippet. Fixes #21478.
1 parent e35cee0 commit 461602d

File tree

6 files changed

+19
-10
lines changed

6 files changed

+19
-10
lines changed

guides/typography.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ To get started, you first include the `Roboto` font with the 300, 400 and 500 we
3131
You can host it yourself or include it from [Google Fonts][2]:
3232

3333
```html
34-
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500&display=swap" rel="stylesheet">
34+
<link rel="preconnect" href="https://fonts.gstatic.com">
35+
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500&display=swap" rel="stylesheet">
3536
```
3637

3738
Now you can add the appropriate CSS classes to the elements that you want to style:

src/dev-app/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
<base href="/">
88

99
<link rel="icon" type="image/x-icon" href="favicon.ico">
10+
<link rel="preconnect" href="https://fonts.gstatic.com">
1011
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
12+
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500&display=swap" rel="stylesheet">
1113
<link href="theme.css" rel="stylesheet">
12-
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500" rel="stylesheet">
1314

1415
<script>
1516
if (window.customElements) {

src/e2e-app/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
<base href="/">
88

99
<link rel="icon" type="image/x-icon" href="favicon.ico">
10+
<link rel="preconnect" href="https://fonts.gstatic.com">
1011
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
11-
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500" rel="stylesheet">
12+
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500&display=swap" rel="stylesheet">
1213
<link href="theme.css" rel="stylesheet">
1314

1415
<!-- FontAwesome for mat-icon demo. -->

src/material/schematics/ng-add/fonts/material-fonts.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,17 @@ export function addFontsToIndex(options: Schema): Rule {
2626
throw new SchematicsException('No project index HTML file could be found.');
2727
}
2828

29+
const preconnect = `<link rel="preconnect" href="https://fonts.gstatic.com">`;
2930
const fonts = [
30-
'https://fonts.googleapis.com/css?family=Roboto:300,400,500&display=swap',
31+
'https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500&display=swap',
3132
'https://fonts.googleapis.com/icon?family=Material+Icons',
3233
];
3334

34-
fonts.forEach(f => {
35-
projectIndexFiles.forEach(indexFilePath => {
36-
appendHtmlElementToHead(host, indexFilePath, `<link href="${f}" rel="stylesheet">`);
35+
projectIndexFiles.forEach(indexFilePath => {
36+
appendHtmlElementToHead(host, indexFilePath, preconnect);
37+
38+
fonts.forEach(font => {
39+
appendHtmlElementToHead(host, indexFilePath, `<link href="${font}" rel="stylesheet">`);
3740
});
3841
});
3942
};

src/material/schematics/ng-add/index.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,13 @@ describe('ng-add schematic', () => {
151151
// Ensure that the indentation has been determined properly. We want to make sure that
152152
// the created links properly align with the existing HTML. Default CLI projects use an
153153
// indentation of two columns.
154+
expect(htmlContent)
155+
.toContain(' <link rel="preconnect" href="https://fonts.gstatic.com">');
154156
expect(htmlContent)
155157
.toContain(' <link href="https://fonts.googleapis.com/icon?family=Material+Icons"');
156158
expect(htmlContent)
157-
.toContain(
158-
' <link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500&display=swap"');
159+
.toContain(' <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@' +
160+
'300;400;500&display=swap"');
159161
});
160162
});
161163

src/universal-app/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
<meta name="viewport" content="width=device-width, initial-scale=1">
66
<title>Angular Material Universal Kitchen Sink Test</title>
77
<link href="theme.css" rel="stylesheet">
8+
<link rel="preconnect" href="https://fonts.gstatic.com">
89
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
9-
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500" rel="stylesheet">
10+
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500&display=swap" rel="stylesheet">
1011
<base href="/">
1112

1213
<style>

0 commit comments

Comments
 (0)