Skip to content
This repository has been archived by the owner on Nov 11, 2020. It is now read-only.

Oswald doesn't fetch #27

Open
thornyweb opened this issue Dec 4, 2019 · 4 comments
Open

Oswald doesn't fetch #27

thornyweb opened this issue Dec 4, 2019 · 4 comments

Comments

@thornyweb
Copy link

thornyweb commented Dec 4, 2019

No matter what combination of variants / subsets I can never get Oswald to pre-fetch, there are no errors logged in the process it just silently doesnt fetch the font.

If I change the name to 'oswald' rather than 'Oswald' I see errors in terminal whilst running gatsby develop where the response from Google has returned a 400.

from gatsby-config.js

{
  resolve: `gatsby-plugin-prefetch-google-fonts`,
  options: {
    fonts: [
      {
        family: `Roboto`,
        variants: [`300`, `400`, `500`, `600`, `700`],
        subsets: [`latin`],
      },
      {
        family: `Oswald`,
        variants: [`200`, `700`],
        subsets: [`latin`],
      },
    ],
  },
}
@tbaustin
Copy link
Contributor

Will be fixing this soon! We are very busy so any help would be greatly appreciated :D

@ptrkvsky
Copy link

I was thinking i was crazy, i am glad i am not alone.

@zuyetawarmatik
Copy link

Same issue with any font family name containing space character, such as "EB Garamond"

@vinkodlak
Copy link

Will be fixing this soon! We are very busy so any help would be greatly appreciated :D

Problem is in merge-css.js on line 41
https://github.com/escaladesports/gatsby-plugin-prefetch-google-fonts/blob/657ef59d611b55aa6d9ac056c76b9be4b3a8aa1a/plugins/export/merge-css.js#L41

it happens when only url is available, no local versions, and it gets shifted in name generation, so items array is empty. we need new name generator. i have good results when i changed the function to this

function getLines(data) {
  const lines = {}
  const name = {}
  data.split(`\n`).forEach(line => {
    line = line.trim()
    if (line.indexOf(`font-family:`) === 0) {
      name.family = line
        .replace(`;`, ``)
        .replace(`font-family:`, ``)
        .replace(/'/g, ``)
        .trim()
    }
    if (line.indexOf(`font-style:`) === 0) {
      name.style = line
        .replace(`;`, ``)
        .replace(`font-style:`, ``)
        .replace(/'/g, ``)
        .trim()
    }
    if (line.indexOf(`font-weight:`) === 0) {
      name.weight = line
        .replace(`;`, ``)
        .replace(`font-weight:`, ``)
        .replace(/'/g, ``)
        .trim()
    }
    if (line.indexOf(`src:`) === 0) {
      let items = line
        .replace(`;`, ``)
        .replace(`src:`, ``)
        .split(`,`)
        .map(item => item.trim())
      
      lines[`${name.family} ${name.style} ${name.weight}`] = {
        items,
        line: line.replace(`;`, ``),
      }
    }
  })
  return lines
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants