Skip to content

Commit

Permalink
fix api and font servers are not the same fix #15
Browse files Browse the repository at this point in the history
  • Loading branch information
lexoyo committed May 24, 2024
1 parent 9824c63 commit 7a26d59
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,13 @@ Also you should style the dialog:

## Options

The options `api_url` and `server_url` are used to support Google fonts proxies, e.g fontlay and a privacy-friendly drop-in replacement for Google Fonts, e.g coollabsio's fonts server. Their default values are the Google fonts API and server.

| Option | Description | Default |
|-|-|-
| `api_key` | Google fonts API key, [see this doc to get an API key](https://developers.google.com/fonts/docs/developer_api#APIKey) | Required |
| `server_url` | Google fonts server or a free [privacy-friendly drop-in replacement for Google Fonts](https://github.com/coollabsio/fonts) or [a proxy server to speed up the load and protect privacy](https://fontlay.com/) | `https://fonts.googleapis.com` |
| `api_url` | Fonts API | `https://www.googleapis.com` |
| `server_url` | Fonts server | `https://fonts.googleapis.com` |

## Download

Expand Down
4 changes: 3 additions & 1 deletion src/fonts.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ let defaults = []
* Options
*/
let fontServer = 'https://fonts.googleapis.com'
let fontApi = 'https://www.googleapis.com'

/**
* Load available fonts only once per session
Expand Down Expand Up @@ -82,6 +83,7 @@ async function loadFontList(url) {
export const fontsDialogPlugin = (editor, opts) => {
defaults = editor.StyleManager.getBuiltIn('font-family').options
if(opts.server_url) fontServer = opts.server_url
if(opts.api_url) fontApi = opts.api_url
if(!opts.api_key) throw new Error(editor.I18n.t('grapesjs-fonts.You must provide Google font api key'))
editor.Commands.add(cmdOpenFonts, {
/* eslint-disable-next-line */
Expand All @@ -97,7 +99,7 @@ export const fontsDialogPlugin = (editor, opts) => {
modal.setContent(el)
loadFonts(editor)
displayFonts(editor, opts, [])
loadFontList(`${ fontServer }/webfonts/v1/webfonts?key=${ opts.api_key }`)
loadFontList(`${ fontApi }/webfonts/v1/webfonts?key=${ opts.api_key }`)
.then(fontsList => { // the run command will terminate before this is done, better for performance
displayFonts(editor, opts, fontsList)
const form = el.querySelector('form')
Expand Down

0 comments on commit 7a26d59

Please sign in to comment.