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

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

Closed
karlhorky opened this issue Oct 31, 2020 · 0 comments · Fixed by #19
Closed

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

karlhorky opened this issue Oct 31, 2020 · 0 comments · Fixed by #19
Labels
enhancement New feature or request
Milestone

Comments

@karlhorky
Copy link
Contributor

karlhorky commented Oct 31, 2020

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?

@karlhorky karlhorky changed the title Calculate and Append File Hash with Custom filename Function Option? Custom filename Function Option (for use case of appending hash) Oct 31, 2020
@akabekobeko akabekobeko added the enhancement New feature or request label Nov 1, 2020
@akabekobeko akabekobeko added this to the v1.3.0 milestone Nov 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants