Gatsby: Typography Plugin - Not importing Google Fonts?

Created on 18 Jun 2018  路  4Comments  路  Source: gatsbyjs/gatsby

Am I wrong to think this setup should result in my site making a network request for the relevant Google Font? Does the font loading feature only work for themes? I'm in development using localhost:8000.

/*  src/utils/typography.js  */
import Typography from 'typography';
import grandViewTheme from "typography-theme-grand-view";

grandViewTheme.bodyFontFamily = ['Alegreya', 'Sans-Serif'];

const typography = new Typography({
  ...grandViewTheme
});

export default typography;

/*  gatsby-config.js  */
module.exports = {
  plugins: [
    {
      resolve: `gatsby-plugin-typography`,
      options: {
        pathToConfigModule: `src/utils/typography.js`,
      },
    },
    'gatsby-plugin-react-helmet',
    'gatsby-plugin-sass',
  ],
};

Most helpful comment

Here is an example for anyone who might be running into this

import Typography from "typography"
import fairyGateTheme from "typography-theme-fairy-gates"

fairyGateTheme.headerFontFamily = ['Open Sans', 'sans-serif']
fairyGateTheme.bodyFontFamily = ['Open Sans', 'sans-serif']
fairyGateTheme.googleFonts = [
  {
    name: 'Open Sans',
    styles: [
      '300',
      '400',
      '500',
      '600',
      '700'
    ],
  }
]

const typography = new Typography(fairyGateTheme)

export default typography

All 4 comments

You need to add the fonts to the googleFonts array to trigger a download.

Oh that's really simple... Thanks very much @KyleAMathews!

Might I suggest adding that nothing will be downloaded without this array to the TypographyJS Readme?

Here is an example for anyone who might be running into this

import Typography from "typography"
import fairyGateTheme from "typography-theme-fairy-gates"

fairyGateTheme.headerFontFamily = ['Open Sans', 'sans-serif']
fairyGateTheme.bodyFontFamily = ['Open Sans', 'sans-serif']
fairyGateTheme.googleFonts = [
  {
    name: 'Open Sans',
    styles: [
      '300',
      '400',
      '500',
      '600',
      '700'
    ],
  }
]

const typography = new Typography(fairyGateTheme)

export default typography

Here is an example for anyone who might be running into this

import Typography from "typography"
import fairyGateTheme from "typography-theme-fairy-gates"

fairyGateTheme.headerFontFamily = ['Open Sans', 'sans-serif']
fairyGateTheme.bodyFontFamily = ['Open Sans', 'sans-serif']
fairyGateTheme.googleFonts = [
  {
    name: 'Open Sans',
    styles: [
      '300',
      '400',
      '500',
      '600',
      '700'
    ],
  }
]

const typography = new Typography(fairyGateTheme)

export default typography

thank you dude. helped me a lot, thank you.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rossPatton picture rossPatton  路  3Comments

andykais picture andykais  路  3Comments

benstr picture benstr  路  3Comments

dustinhorton picture dustinhorton  路  3Comments

jimfilippou picture jimfilippou  路  3Comments