fix(fonts): Fixed page title fonts not downloadable to local #1898
+11
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR addresses the issue where page title fonts introduced in #1848 are not downloadable and still reaches Google Fonts API when
cdnCaching
is set to false. Caught this bug because I have CSP set on my website.Details
The issue is the PR introduced a new Google Fonts API to extract only a subset of fonts needed for the page title text, but didn't update the parser regex to recognize the new font URLs returned by the new API, which causes a fallback to the cloud.
Example of a standard API call that downloads the full font: https://fonts.googleapis.com/css2?family=Roboto+Slab&display=swap, which returns the following CSS:
Example of a subset API call that downloads only what's needed to render given texts: https://fonts.googleapis.com/css2?family=Roboto+Slab&text=hello&display=swap, which returns the following CSS:
I updated the regex to cover these two cases, we're also now getting the API URL, file name and the extension entirely through capture groups. Manually tested working on a number of fonts.