Skip to content

Commit

Permalink
Avoid adding multiple copies of Google fonts when self-hosting them
Browse files Browse the repository at this point in the history
  • Loading branch information
papandreou committed Jul 26, 2020
1 parent 231383e commit 071fbf8
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions lib/subsetFonts.js
Original file line number Diff line number Diff line change
Expand Up @@ -591,12 +591,15 @@ async function createSelfHostedGoogleFontsCssAsset(
const srcFragments = [];
for (const format of formats) {
const rawSrc = await convertFontBuffer(cssFontFaceSrc.to.rawSrc, format);
const fontAsset = await assetGraph.addAsset({
url: `/subfont/${cssFontFaceSrc.to.baseName}-${md5HexPrefix(rawSrc)}${
extensionByFormat[format]
}`,
rawSrc,
});
const url = `/subfont/${cssFontFaceSrc.to.baseName}-${md5HexPrefix(
rawSrc
)}${extensionByFormat[format]}`;
const fontAsset =
assetGraph.findAssets({ url })[0] ||
(await assetGraph.addAsset({
url,
rawSrc,
}));
srcFragments.push(
`url(${assetGraph.buildRootRelativeUrl(
fontAsset.url
Expand Down

0 comments on commit 071fbf8

Please sign in to comment.