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

Relocate manifest.json to ./public/ #4890

Merged
merged 3 commits into from
Apr 9, 2018
Merged
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
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