akabekobeko/npm-gatsby-remark-copy-relative-linked-files

Custom `filename` Function Option (for use case of appending hash)

karlhorky opened this issue ยท 0 comments

Hi @akabekobeko ! ๐Ÿ‘‹

In order to achieve good long-term caching of files, it is good if the filenames change if the contents change.

To do this, very often an md5 digest is generated of the file and then included in the filename (see how gatsby-remark-copy-linked-files does it)

Would you be open to accepting a new option called filename that would have access to this hash, in case a user would like to prepend the hash:

// In your `gatsby-config.js`
plugins: [
  {
    resolve: 'gatsby-transformer-remark',
    options: {
      plugins: [
        {
          resolve: 'gatsby-remark-copy-relative-linked-files',
          options: {
            // would generate file-1abcb33beeb811dca15f0ac3e47b88d9.pdf
            filename: ({hash, name, extension}) => `${name}-${hash}.${extension}`
          },
        },
      ],
    },
  },
]

May be able to use the existing linkNode.internal.contentDigest property from Gatsby (as gatsby-remark-copy-linked-files also does).


One more question: how do you feel about changing the default to append this hash on the end?