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

Copies local files relative linked to/from markdown to your public folder with preserve directory structure.
MIT License
6 stars 3 forks source link

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

Closed karlhorky closed 3 years ago

karlhorky commented 4 years ago

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?