Skip to content
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

Add Google Fonts provider and register a selection of fonts #23045

Merged
merged 14 commits into from
Mar 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"automattic/jetpack-constants",
"automattic/jetpack-device-detection",
"automattic/jetpack-error",
"automattic/jetpack-google-fonts-provider",
"automattic/jetpack-heartbeat",
"automattic/jetpack-identity-crisis",
"automattic/jetpack-jitm",
Expand Down
16 changes: 16 additions & 0 deletions projects/packages/google-fonts-provider/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Files not needed to be distributed in the package.
.gitattributes export-ignore
.github/ export-ignore
package.json export-ignore

# Files to include in the mirror repo, but excluded via gitignore
# Remember to end all directories with `/**` to properly tag every file.
# /src/js/example.min.js production-include

# Files to exclude from the mirror repo, but included in the monorepo.
# Remember to end all directories with `/**` to properly tag every file.
.gitignore production-exclude
changelog/** production-exclude
phpunit.xml.dist production-exclude
.phpcs.dir.xml production-exclude
tests/** production-exclude
2 changes: 2 additions & 0 deletions projects/packages/google-fonts-provider/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
vendor/
node_modules/
24 changes: 24 additions & 0 deletions projects/packages/google-fonts-provider/.phpcs.dir.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0"?>
<ruleset>

<rule ref="WordPress.WP.I18n">
<properties>
<property name="text_domain" type="array">
<element value="jetpack-google-fonts-provider" />
</property>
</properties>
</rule>
<rule ref="Jetpack.Functions.I18n">
<properties>
<property name="text_domain" value="jetpack-google-fonts-provider" />
</properties>
</rule>

<rule ref="WordPress.Utils.I18nTextDomainFixer">
<properties>
<property name="old_text_domain" type="array" />
<property name="new_text_domain" value="jetpack-google-fonts-provider" />
</properties>
</rule>

</ruleset>
7 changes: 7 additions & 0 deletions projects/packages/google-fonts-provider/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

62 changes: 62 additions & 0 deletions projects/packages/google-fonts-provider/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Jetpack Google Fonts Provider Package

WordPress Webfonts provider for Google Fonts
creativecoder marked this conversation as resolved.
Show resolved Hide resolved

## How to install google-fonts-provider

Package is published in [Packagist](https://packagist.org/packages/automattic/jetpack-google-fonts-provider). We recommend using the latest version there. You can install it in a composer managed project with `composer require automattic/jetpack-google-fonts-provider`.

You can also test with the latest development versions like below:

```json
"require": {
"automattic/jetpack-google-fonts-provider": "dev-master"
}
```

## Usage

The WordPress Webfonts API is available by activating the Gutenberg plugin and is planned to be included in WordPress 6.0.

### Register the provider

This package contains the provider class, but the provider needs to be registered before it can be used.

```php
wp_register_webfont_provider( 'google-fonts', '\Automattic\Jetpack\Fonts\Google_Fonts_Provider' );
```

### Register fonts

After registering the provider, you can register any of the fonts available in the [Google Fonts catalog](https://fonts.google.com) to make them available for use in the block editor typography settings, Global styles, and your site's CSS.

```php
wp_register_webfont(
array(
'font-family' => 'Lato',
'provider' => 'google-fonts',
),
);
```

### Add preconnect link

Adding a preconnect link to the `<head>` of the page will help make sure the font files load as soon as possible, and reduce the layout shift when they are displayed. See [this list of webfont best practices](https://web.dev/font-best-practices/#preconnect-to-critical-third-party-origins) for more details.

```php
// Run on an early priority to print out the preconnect link tag near the start of the page source.
add_action( 'wp_head', '\Automattic\Jetpack\Fonts\Google_Fonts_Provider::preconnect_font_source', 0 );
```

### Additional info

For a discussion about the Webfonts API in WordPress, see https://make.wordpress.org/core/2021/09/28/implementing-a-webfonts-api-in-wordpress-core/.

## Security

Need to report a security vulnerability? Go to [https://automattic.com/security/](https://automattic.com/security/) or directly to our security bug bounty site [https://hackerone.com/automattic](https://hackerone.com/automattic).

## License

Jetpack Google Fonts Provider is licensed under [GNU General Public License v2 (or later)](./LICENSE.txt)

Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: major
Type: added

Adds a provider for Google Fonts using the new Webfonts API in Gutenberg
50 changes: 50 additions & 0 deletions projects/packages/google-fonts-provider/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"name": "automattic/jetpack-google-fonts-provider",
"description": "WordPress Webfonts provider for Google Fonts",
"type": "library",
"license": "GPL-2.0-or-later",
"require": {},
"require-dev": {
"yoast/phpunit-polyfills": "1.0.3",
"automattic/jetpack-changelogger": "^3.0",
"brain/monkey": "^2.6"
},
"autoload": {
"classmap": [
"src/"
]
},
"scripts": {
"phpunit": [
"./vendor/phpunit/phpunit/phpunit --colors=always"
],
"test-coverage": [
"php -dpcov.directory=. ./vendor/bin/phpunit --coverage-clover \"$COVERAGE_DIR/clover.xml\""
],
"test-php": [
"@composer phpunit"
]
},
"repositories": [
{
"type": "path",
"url": "../../packages/*",
"options": {
"monorepo": true
}
}
],
"minimum-stability": "dev",
"prefer-stable": true,
"extra": {
creativecoder marked this conversation as resolved.
Show resolved Hide resolved
"autotagger": true,
"mirror-repo": "Automattic/jetpack-google-fonts-provider",
"changelogger": {
"link-template": "https://github.com/Automattic/jetpack-google-fonts-provider/compare/v${old}...v${new}"
},
"branch-alias": {
"dev-master": "0.1.x-dev"
},
"textdomain": "jetpack-google-fonts-provider"
}
}
29 changes: 29 additions & 0 deletions projects/packages/google-fonts-provider/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"private": true,
"name": "@automattic/jetpack-google-fonts-provider",
"version": "0.1.0-alpha",
"description": "WordPress Webfonts provider for Google Fonts",
"homepage": "https://jetpack.com",
"bugs": {
"url": "https://github.com/Automattic/jetpack/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/Automattic/jetpack.git"
},
"license": "GPL-2.0-or-later",
"author": "Automattic",
"scripts": {
"build": "echo 'Not implemented.",
"build-js": "echo 'Not implemented.",
"build-production": "echo 'Not implemented.",
"build-production-js": "echo 'Not implemented.",
"clean": "true"
},
"devDependencies": {},
"engines": {
"node": "^14.18.3 || ^16.13.2",
"pnpm": "^6.23.6",
"yarn": "use pnpm instead - see docs/yarn-upgrade.md"
}
}
15 changes: 15 additions & 0 deletions projects/packages/google-fonts-provider/phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="tests/php/bootstrap.php" backupGlobals="false" colors="true" convertDeprecationsToExceptions="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage processUncoveredFiles="false">
<!-- Better to only include "src" than to add "." and then exclude "tests", "vendor", and so on, as PHPUnit still scans the excluded directories. -->
<!-- Add additional lines for any files or directories outside of src/ that need coverage. -->
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
<testsuites>
<testsuite name="main">
<directory prefix="test" suffix=".php">tests/php</directory>
</testsuite>
</testsuites>
</phpunit>
Loading