question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`gatsby-plugin-sharp` / `gatsby-remark-images`: Set destination directory with destinationDir option

See original GitHub issue

Summary

For the plugins gatsby-plugin-sharp and/or gatsby-remark-images (whichever makes sense and is necessary), an option destinationDir (string or function) that works similarly to the option in gatsby-remark-copy-linked-files

// save `my-awesome-pdf.pdf` to `public/downloads/2a0039f3a61f4510f41678438e4c863a/my-awesome-pdf.pdf`
destinationDir: f => `downloads/${f.hash}/${f.name}`

// save `my-awesome-pdf.pdf` to `public/downloads/2a0039f3a61f4510f41678438e4c863a-my-awesome-pdf.pdf`
destinationDir: f => `downloads/${f.hash}-${f.name}`

// save `my-awesome-pdf.pdf` to `public/my-awesome-pdf/2a0039f3a61f4510f41678438e4c863a.pdf`
destinationDir: f => `${f.name}/${f.hash}`

…also with the new relativeDirectory property in the returned file object:

// save `my-awesome-pdf.pdf` to `public/original-path-in-src-pages/my-awesome-pdf.pdf`
destinationDir: f => `${f.relativeDirectory}/${f.name}`,

Basic example

See examples above.

Motivation

The structure of the files in the output public folder is more configurable and using the relativeDirectory option, can also match 1 to 1 the folder structure of the input src/pages directory. This makes the output easier to reason about and also easier to build tooling upon.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:17 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
sidharthachatterjeecommented, Sep 28, 2020

This makes a lot of sense. Happy to receive a PR adding this!

0reactions
karlhorkycommented, Jan 8, 2021

The project that I’m using it in is this Gatsby Server-side Authentication here: https://github.com/upleveled/gatsby-serverside-auth0

Read more comments on GitHub >

github_iconTop Results From Across the Web

gatsby-remark-copy-linked-files
Option : destinationDir. By default, all files will be copied to the root of the public folder in the following format: contentHash/fileName.
Read more >
How do I unzip a tar gz archive to a specific destination?
I want to unzip it into /root/Desktop/folder . The folder structure in zipped file should be preserved in the destination directory.
Read more >
tar gz a directory in another location into a destination directory
As mentioned in the comment, use the -C option to "change to the target directory" if your tar implemention supports it:
Read more >
How To Extract a Tar Files To a Different Directory on a Linux ...
This tutorial explains how to extract a tar ball archive to a specific directory on a Linux, BSD, macOS, and Unix using command...
Read more >
linux - Specify Destination Directory for 'zip' Command Output ...
Adjecent to this question, relative directories also work. zip -r ../app.zip . will put files in the current directory in a .zip in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found