Skip to content

Commit

Permalink
Relocate manifest.json to ./public/ (#4890)
Browse files Browse the repository at this point in the history
* Relocate manifest.json to ./public/

* Remove unused variables

* Use path.join
  • Loading branch information
dojineko authored and KyleAMathews committed Apr 9, 2018
1 parent b7de352 commit 3dafecf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
13 changes: 7 additions & 6 deletions packages/gatsby-plugin-manifest/src/gatsby-node.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const fs = require(`fs`)
const path = require(`path`)
const Promise = require(`bluebird`)
const sharp = require(`sharp`)
const defaultIcons = require(`./common.js`).defaultIcons
Expand All @@ -8,8 +9,8 @@ sharp.simd(true)
function generateIcons(icons, srcIcon) {
return Promise.map(icons, icon => {
const size = parseInt(icon.sizes.substring(0, icon.sizes.lastIndexOf(`x`)))
const imgPath = `./public/` + icon.src
const imgPath = path.join(`public`, icon.src)

return sharp(srcIcon)
.resize(size)
.toFile(imgPath)
Expand All @@ -22,7 +23,7 @@ exports.onPostBuild = (args, pluginOptions) =>
new Promise(resolve => {
const { icon } = pluginOptions
const manifest = { ...pluginOptions }

// Delete options we won't pass to the manifest.json.
delete manifest.plugins
delete manifest.icon
Expand All @@ -33,15 +34,15 @@ exports.onPostBuild = (args, pluginOptions) =>
}

// Determine destination path for icons.
const iconPath = `./public/` + manifest.icons[0].src.substring(0, manifest.icons[0].src.lastIndexOf(`/`))
const iconPath = path.join(`public`, manifest.icons[0].src.substring(0, manifest.icons[0].src.lastIndexOf(`/`)))

//create destination directory if it doesn't exist
if (!fs.existsSync(iconPath)){
fs.mkdirSync(iconPath)
}

fs.writeFileSync(`${iconPath}/manifest.json`, JSON.stringify(manifest))
fs.writeFileSync(path.join(`public`, `manifest.json`), JSON.stringify(manifest))

// Only auto-generate icons if a src icon is defined.
if (icon !== undefined) {
generateIcons(manifest.icons, icon).then(() => {
Expand Down
8 changes: 1 addition & 7 deletions packages/gatsby-plugin-manifest/src/gatsby-ssr.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
import React from "react"
import { withPrefix } from "gatsby-link"
import { defaultIcons } from "./common.js"


exports.onRenderBody = ({ setHeadComponents }, pluginOptions) => {

const icons = pluginOptions.icons || defaultIcons
const iconPath = icons[0].src.substring(0, icons[0].src.lastIndexOf(`/`))

setHeadComponents([
<link
key={`gatsby-plugin-manifest-link`}
rel="manifest"
href={withPrefix(`${iconPath}/manifest.json`)}
href={withPrefix(`manifest.json`)}
/>,
<meta
key={`gatsby-plugin-manifest-meta`}
Expand Down

0 comments on commit 3dafecf

Please sign in to comment.