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

Obsolete? #43

Open karlhorky opened 2 years ago

karlhorky commented 2 years ago

Hi @akabekobeko ! 👋 Hope you are well.

I have worked on a PR for gatsby-remark-copy-linked-files for a while now, and it finally got merged:

https://github.com/gatsbyjs/gatsby/pull/36213

This allows for specifying a relative destination dir, which may make gatsby-remark-copy-relative-linked-files obsolete:

module.exports = {
  plugins: [
    {
      resolve: `gatsby-transformer-remark`,
      options: {
        plugins: [
          {
            resolve: `gatsby-remark-copy-linked-files`,
            options: {
              // save `src/pages/custom-folder/my-awesome-pdf.pdf` to `public/custom-folder/my-awesome-pdf.pdf`
              // Note: Import `path` to use this example https://nodejs.org/api/path.html
              destinationDir: f => `${path.dirname(path.relative(path.join(__dirname, `src`, `pages`), f.absolutePath))}/${f.name}`,
            },
          },
        ],
      },
    },
  ],
}

What are your thoughts on this?

Should gatsby-remark-copy-relative-linked-files be deprecated (along with a link to gatsby-remark-copy-linked-files)?

akabekobeko commented 2 years ago

@karlhorky gatsby-remark-copy-relative-linked-files is a plugin created to compensate for the missing behavior in gatsby-remark-copy-linked-files.

Therefore, gatsby-remark-copy-relative-linked-files may be deprecated if gatsby-remark-copy-linked-files has equivalent functionality.

Please let me know when a version of gatsby-remark-copy-linked-files is released that confirms the merged functionality. I would like to use that functionality too, so I will check the behavior.

karlhorky commented 2 years ago

Sure, will do! I imagine the new version 5.24.0 will be released within a week.

karlhorky commented 2 years ago

So gatsby-remark-copy-linked-files@5.24.0 does indeed have equivalent functionality (at least for our project).

However, there is an unusual bug with it right now, which makes it a bit more involved to configure:

{
  resolve: 'gatsby-remark-copy-linked-files',
  options: {
    destinationDir: (f: {
      name: string;
      hash: string;
      absolutePath: string;
    }) =>
      // Avoid errors when Gatsby calls function using this data:
      // { name: n, hash: h, absolutePath: a }
      // https://github.com/gatsbyjs/gatsby/pull/36213#issuecomment-1279789118
      !f.absolutePath.includes('/')
        ? `${f.hash}/${f.name}`
        : `${path.dirname(
            path.relative(
              path.join(__dirname, 'src', 'pages'),
              f.absolutePath,
            ),
          )}/${f.name}-${f.hash}`,
  },
},

So maybe it makes sense to wait until this is resolved and the ternary is no longer needed.

HarshilShah commented 1 year ago

Chiming in a bit here because I came here just to try out this package because I noticed it does have one feature that the official one doesn't: Support for source tags. For videos, responsive images, etc. the official plugin is woefully incomplete