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

Update google-fonts-plugin #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ coverage
# Temporary
temp
temp-*

# Jetbrains products
.idea
3 changes: 3 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,6 @@ plugins/dist
# Temporary
temp
temp-*

# Jetbrains products
.idea
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
"fs-extra": "^7.0.0",
"get-urls": "^8.0.0",
"globby": "^8.0.1",
"google-fonts-plugin": "2.0.2",
"google-fonts-plugin": "^5.0.2",
"object-hash": "^1.3.0"
},
"main": "gatsby-ssr.js",
Expand Down
40 changes: 20 additions & 20 deletions plugins/export/download-css.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
const GoogleFontsWebpackPlugin = require(`google-fonts-plugin`)
const GoogleFontsPluginOptions = require(`google-fonts-plugin/dist/Options/Options`).default
const GoogleFontsPluginFonts = require(`google-fonts-plugin/dist/Fonts/Fonts`).default
const fs = require(`fs`)
const path = require(`path`)

module.exports = async ({
fonts,
formats = [
//`eot`,
`woff2`,
module.exports = async (options, config) => {
// override specific options for this plugin
options.formats = [
`woff`,
//`ttf`,
//`svg`,
],
}, config) => {
const googleFontsPlugin = new GoogleFontsWebpackPlugin({
fonts,
formats,
outputDir: path.join(`.cache/google-fonts`, config.pathPrefix),
encode: false,
minify: false,
verbose: true,
})
await googleFontsPlugin.make()
}
`woff2`,
]
options.encode = false // Triggers font-display property

const googleFontsPluginOptions = new GoogleFontsPluginOptions(options)
const outputPath = path.join(`.cache`, `google-fonts`, config.pathPrefix)
fs.mkdirSync(outputPath, { recursive: true })

for (const format of Object.values(googleFontsPluginOptions.formats)) {
const fonts = new GoogleFontsPluginFonts(format, googleFontsPluginOptions)
let css = await fonts.requestFontsCSS()
fs.writeFileSync(path.join(outputPath, `${format}.css`), css)
}
}
4 changes: 0 additions & 4 deletions plugins/export/merge-css.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ module.exports = async (config) => {

let css = createCssString(woff2, woff2Lines)
css = new CleanCss().minify(css).styles

// Add font-display swap as recommended here https://css-tricks.com/font-display-masses/.
css = css.replace(/}/g, `;font-display: swap;}`)

await outputFile(`${cachedPath}/google-fonts.css`, css)
}

Expand Down
Loading