Skip to content

Commit

Permalink
Switch to Google Fonts v2 API
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenjoezhang committed Nov 20, 2024
1 parent a77778a commit bec4ea9
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions scripts/helpers/font.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = function() {

if (!config || !config.enable) return '';

const fontStyles = ':300,300italic,400,400italic,700,700italic';
const fontStyles = ':ital,wght@0,300;0,400;0,700;1,300;1,400;1,700';
const fontHost = config.host || 'https://fonts.googleapis.com';

// Get a font list from config
Expand All @@ -18,8 +18,8 @@ module.exports = function() {
});

fontFamilies = fontFamilies.map(name => name.trim().replace(/\s/g, '+') + fontStyles);
fontFamilies = [...new Set(fontFamilies)].join('%7C');
fontFamilies = [...new Set(fontFamilies)].map(name => 'family=' + name).join('&');

// Merge extra parameters to the final processed font string
return fontFamilies ? `<link rel="stylesheet" href="${fontHost}/css?family=${fontFamilies}&display=swap&subset=latin,latin-ext">` : '';
return fontFamilies ? `<link rel="stylesheet" href="${fontHost}/css2?${fontFamilies}&display=swap&subset=latin,latin-ext">` : '';
};

0 comments on commit bec4ea9

Please sign in to comment.