Skip to content

Commit

Permalink
When copying static assets, don't try to rewrite directory names if f…
Browse files Browse the repository at this point in the history
…ile in directory not associated with a page
  • Loading branch information
KyleAMathews committed Nov 22, 2015
1 parent 018fccf commit 6750a2d
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions lib/utils/post-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,31 @@ module.exports = function(program, cb) {
// our asset gets copied to the right directory.
var parsed = parsePath(file);
var relativePath = path.relative(directory + "/pages", file);
var oldPath = parsePath(relativePath).dirname;
var oldDirectory = parsePath(relativePath).dirname;

// Wouldn't rewrite basePath
if (oldPath === ".") {
oldPath = "/";
if (oldDirectory === ".") {
oldDirectory = "/";
var newPath = "/" + parsed.basename;
}

if (!(oldPath === "/")) {
if (!(oldDirectory === "/")) {
var page = _.find(pages, function(page) {
// Ignore files that start with underscore (they're not pages).
if (page.file.name.slice(0,1) !== '_') {
return parsePath(page.requirePath).dirname === oldPath;
return parsePath(page.requirePath).dirname === oldDirectory;
}
});

newPath = parsePath(page.path).dirname + parsed.basename;
if (page) {
newPath = parsePath(page.path).dirname + parsed.basename;
}
// We couldn't find a page associated with this file. Probably
// the file is in a directory of static files. In any case,
// we'll leave the file directory alone.
else {
newPath = relativePath;
}
}

newPath = directory + "/public/" + newPath;
Expand Down

0 comments on commit 6750a2d

Please sign in to comment.