moxystudio / gatsby-plugin-ipfs

Adds support for deploying Gatsby to IPFS by ensuring that assets are relative
MIT License
114 stars 37 forks source link

Remove prefix in manifest file (manifest.webmanifest) #24

Open jsonsivar opened 4 years ago

jsonsivar commented 4 years ago

Currently the manifest file is not getting the prefix replaced. I think it's safe just to remove it since it's already relative. Looking at this line, it looks like if we add a special case for a .webmanifest file that removes it the URLs for the icons should be fine.

Let me know if that makes sense, I can try creating a PR for it if you think that's the right direction.

jsonsivar commented 4 years ago

I added this snippet in a local project and it seemed to have cleared the manifest file:


exports.onPostBuild = async ({ reporter }) => {
    // replace prefix paths for manifest file   
    const path = 'public/manifest.webmanifest';
    const buffer = await readFileAsync(path);
    let contents = buffer.toString();

    if (!contents.includes('__GATSBY_IPFS_PATH_PREFIX__')) {
        return;
    }

    contents = contents
    .replace("\"/__GATSBY_IPFS_PATH_PREFIX__\"", "\"/\"")
    .replace(/\/__GATSBY_IPFS_PATH_PREFIX__\//g, "/");

    await writeFileAsync(path, contents);
}