├── .gitignore ├── index.js ├── README.md ├── package.json ├── LICENSE └── gatsby-ssr.js /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | // don't care 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # gatsby-plugin-google-fonts 2 | 3 | ## How to use it ? 4 | 5 | ```js 6 | yarn add gatsby-plugin-google-fonts 7 | // or 8 | npm install gatsby-plugin-google-fonts --save 9 | ``` 10 | 11 | Add some fonts to your `gatsby-config.js`: 12 | 13 | ```js 14 | module.exports = { 15 | siteMetadata: { 16 | title: `I like Google fonts` 17 | }, 18 | plugins: [ 19 | { 20 | resolve: `gatsby-plugin-google-fonts`, 21 | options: { 22 | fonts: [ 23 | `limelight`, 24 | `source sans pro\:300,400,400i,700` // you can also specify font weights and styles 25 | ], 26 | display: 'swap' 27 | } 28 | } 29 | ] 30 | } 31 | ``` 32 | 33 | 34 | ## How to find great ideas ? 35 | 36 | - https://fonts.google.com 37 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "gatsby-plugin-google-fonts", 3 | "version": "1.0.1", 4 | "description": "Bring Google Fonts to Gatsby", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+ssh://git@github.com/didierfranc/gatsby-plugin-google-fonts.git" 12 | }, 13 | "keywords": [ 14 | "gatsby", 15 | "gatsby-plugin", 16 | "react", 17 | "google", 18 | "fonts" 19 | ], 20 | "author": "Didier Franc ", 21 | "license": "MIT", 22 | "bugs": { 23 | "url": "https://github.com/didierfranc/gatsby-plugin-google-fonts/issues" 24 | }, 25 | "homepage": "https://github.com/didierfranc/gatsby-plugin-google-fonts#readme" 26 | } 27 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Didier Franc 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /gatsby-ssr.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | var _react = require('react') 4 | 5 | var _react2 = _interopRequireDefault(_react) 6 | 7 | function _interopRequireDefault(obj) { 8 | return obj && obj.__esModule ? obj : { default: obj } 9 | } 10 | 11 | var format = function format(string) { 12 | return string 13 | .split(' ') 14 | .map(function(s) { 15 | return s.replace(/^\w/, function(s) { 16 | return s.toUpperCase() 17 | }) 18 | }) 19 | .join(' ') 20 | } 21 | 22 | var getFonts = function getFonts(options) { 23 | return options.fonts 24 | .map(format) 25 | .join('|') 26 | .replace(/ /g, '+') 27 | } 28 | 29 | function getDisplay(options) { 30 | return options.display ? '&display=' + options.display : '' 31 | } 32 | 33 | exports.onRenderBody = function(_ref, options) { 34 | var setHeadComponents = _ref.setHeadComponents 35 | 36 | var link = 'https://fonts.googleapis.com/css?family=' + getFonts(options) + getDisplay(options) 37 | setHeadComponents([ 38 | _react2.default.createElement('link', { 39 | key: 'google-fonts-preconnect', 40 | rel: 'preconnect', 41 | href: 'https://fonts.gstatic.com/', 42 | crossOrigin: 'anonymous' 43 | }), 44 | _react2.default.createElement('link', { 45 | key: 'fonts', 46 | href: link, 47 | rel: 'stylesheet', 48 | crossOrigin: 'anonymous' 49 | }) 50 | ]) 51 | } 52 | --------------------------------------------------------------------------------