Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(gatsby-plugin-subfont): Make async, add configurable option #21768

Merged
merged 10 commits into from
Mar 2, 2020
11 changes: 10 additions & 1 deletion packages/gatsby-plugin-subfont/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ If you want the ability to run font subsetting locally you'l need Python and ins
```javascript
// In your gatsby-config.js
module.exports = {
plugins: [`gatsby-plugin-subfont`],
plugins: [{
resolve: `gatsby-plugin-subfont`,
options: {
silent: true,
fallback: false,
inlineFonts: true,
}
}],
}
```

You can use any option of [https://github.com/Munter/subfont/blob/4b5a59afd17008ca35b6c32b52e3e922159e22fc/lib/subfont.js#L10](subfont)
5 changes: 2 additions & 3 deletions packages/gatsby-plugin-subfont/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gatsby-plugin-subfont",
"version": "1.1.21",
"version": "1.2.0",
"description": "Runs the font delivery optimizing CLI tool subfont on the homepage of your site during the Gatsby build",
"main": "index.js",
"scripts": {
Expand All @@ -25,8 +25,7 @@
"license": "MIT",
"dependencies": {
"@babel/runtime": "^7.7.6",
"shell-escape": "^0.2.0",
"subfont": "^3.7.1"
"subfont": "^4.2.0"
},
"devDependencies": {
"@babel/cli": "^7.7.5",
Expand Down
33 changes: 17 additions & 16 deletions packages/gatsby-plugin-subfont/src/gatsby-node.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
const path = require(`path`)
const { execSync } = require(`child_process`)
const shellescape = require(`shell-escape`)
const subfont = require(`subfont`)

exports.onPostBuild = ({ store }) => {
exports.onPostBuild = async ({ store }, options) => {
const root = path.join(store.getState().program.directory, `public`)
// TODO make this configurable

const urlPaths = [`/`]
const baseArgs = [
`node_modules/.bin/subfont`,
`-i`,
`--no-recursive`,
`--inline-css`,
`--root`,
`file://${root}`,
]
const args = baseArgs.concat(
urlPaths.map(currentPath => path.join(root, currentPath, `index.html`))

await subfont(
{
root: `file://${root}`,
palindrom615 marked this conversation as resolved.
Show resolved Hide resolved
inPlace: true,
inlineCss: true,
silent: true,
inputFiles: urlPaths.map(currentPath =>
path.join(root, currentPath, `index.html`)
),
palindrom615 marked this conversation as resolved.
Show resolved Hide resolved
...options,
},
console
palindrom615 marked this conversation as resolved.
Show resolved Hide resolved
)
const command = shellescape(args)
execSync(command)
return
}