-
Notifications
You must be signed in to change notification settings - Fork 219
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
Closes #7063: Google font - Frontend part #7091
Closes #7063: Google font - Frontend part #7091
Conversation
27da3fa
to
b33302c
Compare
Coverage summary from CodacySee diff coverage on Codacy
Coverage variation details
Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: Diff coverage details
Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: See your quality gate settings Change summary preferencesCodacy stopped sending the deprecated coverage status on June 5th, 2024. Learn more Footnotes
|
Hello hello, There is a known bug with this branch, which is non-blocking. The main feature is here and that's what is important. However, to give more context, the known bug is reported here: To make it short, we are adding 2 times the same tag on the page instead of a single one. |
@team Thanks for the PR. Kindly note my exploratory test notes below (WIP)
Agreed as fine:
|
Description
Fixes #7063
This PR introduces a feature that allows users to use locally stored Google Fonts on the front end instead of the online ones. The code rewrites the Google Fonts paths to the local ones, maintaining the original structure as a
data-wpr-hosted-gf-parameters
argument. It handles Google Fonts V1 and V2 separately, saving and generating two separate CSS files if both versions are present in the source simultaneously. The feature adds its markup just after the OCI feature preloads and prints data correctly when used on multisite.Type of change
Detailed scenario
Prerequisites
Media
tab.As this PR is about the front-end we are not saving locally the fonts yet. So we will have to create the local file manually located in:
/wp-content/cache/fonts/1/e/b/c/173c0fc97eef86a6e51ada56c5a9a.css
&/wp-content/cache/fonts/1/5/9/5/cb6ccb56826a802ed411cef875f0e.css
of your wordpress.Load the page while clearing cache (if you opened it before), and you should see the following output in your HTML:
However this test only includes v1 fonts,
We can modify the fonts to be v2 or even combined them, as long as we have the local file saved it's fine.
For information, the hash (name) of the local file is made by :
md5("https://fonts.googleapis.com/css?family=Roboto");
(and change the font URL you are checking).Note that actually, Unit testing implemented in this PR are covering these manual tests.
Technical description
Documentation
The code introduces a new namespace
Media\Fonts
with four classes:Subscriber
,Controller
,Context
, andServiceProvider
. TheSubscriber
class uses therocket_buffer
filter to add the markup to the page. TheController
class rewrites the CSS to the page and checks if the feature is available. TheContext
class implementsContextInterface
to determine if the feature is allowed. TheServiceProvider
class registers the created classes.This new implementation also includes:
Unit Tests Coverage
For the @wp-media/qa-team info,
The unit tests cover the following aspects:
Controller
class => Makes sure that when the font exists, we will get the rewrite on the front-end to load the local fonts rather than the external one.Subscriber
class correctly uses therocket_buffer
filter to add the necessary markupNew dependencies
No new dependencies are required for this change.
Risks
N/A
Mandatory Checklist
Code validation
Code style