Skip to content

Commit

Permalink
Handle copying assets from assets-only directories
Browse files Browse the repository at this point in the history
Fixes #39

Previously when Gatsby was copying assets in the post-build step, it
assumed that all assets were in the same directory as an html page as
page paths can be written programatically, to ensure assets are copied
to the right directory, they too need to follow however the page path
is modified.

This created a bug however when assets were placed in a directory
without a page as then the code couldn't find a page associated with the
assets.

This commit checks now if page is returned undefined and if it is,
copies the asset to /public to a directory with the same name e.g.
/pages/images/foo.jpg is copied to /public/images/foo.jpg.
  • Loading branch information
KyleAMathews committed Sep 22, 2015
1 parent 1bd737d commit 221d2a0
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/utils/post-build.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,16 @@ module.exports = (program, cb) ->
if page.file.name.slice(0,1) isnt '_'
parsePath(page.requirePath).dirname is oldPath

newPath = parsePath(page.path).dirname + parsed.basename
if page?
newPath = parsePath(page.path).dirname + parsed.basename

# If a page wasn't found, this probably means the asset is in
# a folder without a page e.g. an images directory. In this case,
# there is no path rewriting so just copy to a directory with
# the same name.
else
relativePath = path.relative(directory + "/pages", parsed.dirname)
newPath = "#{relativePath}/#{parsed.basename}"

newPath = directory + "/public/" + newPath
fs.copy(file, newPath, (err) ->
Expand Down

0 comments on commit 221d2a0

Please sign in to comment.