Skip to content

Commit 200a0ef

Browse files
author
Evgheni C.
committed
Merge pull request #12 from rtirserio/master
create sitemap dir if it does not exist
2 parents dc8bdae + 12cc242 commit 200a0ef

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

routes/index.js

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -107,18 +107,23 @@ function postAddScraper(req, res)
107107

108108
case "sitemap-created":
109109

110-
var sitemap_path = "public/sitemaps/sitemap_"+ data.host +".xml";
111-
fs.writeFile(sitemap_path, data.content, function(err)
112-
{
113-
if(err)
114-
console.log(err);
115-
else
116-
io.sockets.emit('sitemap-ready', {path: sitemap_path.replace("public/", "")})
117-
118-
// Terminate crawling daemon
119-
child.kill();
120-
});
121-
110+
var sitemap_path = "public/sitemaps/";
111+
fs.exists(sitemap_path, function(exists) {
112+
if (!exists) {
113+
fs.mkdir(sitemap_path);
114+
}
115+
var filename = "sitemap_"+ data.host +".xml";
116+
fs.writeFile(sitemap_path + filename, data.content, function(err)
117+
{
118+
if(err)
119+
console.log(err);
120+
else
121+
io.sockets.emit('sitemap-ready', {path: sitemap_path.replace("public/", "")})
122+
123+
// Terminate crawling daemon
124+
child.kill();
125+
});
126+
});
122127
break;
123128
}
124129
})

0 commit comments

Comments
 (0)