Skip to content

Commit

Permalink
DOP-4394: save files to public (#1021)
Browse files Browse the repository at this point in the history
  • Loading branch information
seungpark authored and anabellabuckvar committed Feb 23, 2024
1 parent 3dca3fd commit 9685411
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/utils/setup/save-asset-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ const GATSBY_IMAGE_EXTENSIONS = ['webp', 'png', 'avif'];
const isPreview = isGatsbyPreview();

const saveFile = async (file, data) => {
// if this is preview, always save to 'public'
// images saved in /src/images are transformed and processed by gatsby-source-filesystem and gatsby-transformer-sharp
// save files both to "public" and "src/images" directories
// the first is for public access, and the second is for image processing
await fs.mkdir(path.join('public', path.dirname(file)), {
recursive: true,
});
await fs.writeFile(path.join('public', file), data, 'binary');

const pathList =
!isPreview && GATSBY_IMAGE_EXTENSIONS.some((ext) => file.endsWith(ext)) ? ['src', 'images'] : ['public'];
await fs.mkdir(path.join(...pathList, path.dirname(file)), {
Expand Down

0 comments on commit 9685411

Please sign in to comment.