-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sitemap generator #27
base: master
Are you sure you want to change the base?
Changes from 4 commits
43720a4
dd46cbe
9e105d7
f09fc70
a0f287b
3356d73
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
var fs = require('fs') | ||
var path = require('path') | ||
var async = require('async') | ||
var packageJson = require('../package.json') | ||
var inputDir = path.normalize(path.join(__dirname, '..', 'pages')) | ||
var outputDir = path.normalize(path.join(__dirname, '..', 'dist')) | ||
|
||
async.waterfall([ | ||
function read (done) { | ||
fs.readdir(inputDir, done) | ||
}, | ||
function filter (contents, done) { | ||
var pages = contents.filter(function (item) { | ||
var pathToFile = path.join(inputDir, item) | ||
return fs.statSync(pathToFile).isDirectory() | ||
}).filter(function (item) { | ||
return item !== 'home' | ||
}) | ||
done(null, pages) | ||
}, | ||
function createUrls (pages, done) { | ||
var routes = pages.map(function (page) { return 'https://' + packageJson.config.deploy.prod + '/' + page }) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might be an idea to check this value exists before starting the waterfall and throw an error if not. I also think our build config should all be in a "tune" property in the |
||
var sitemap = routes.join('\n').toString() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
var writePath = path.join(outputDir, 'sitemap.txt') | ||
fs.writeFile(writePath, sitemap, done) | ||
} | ||
], function (err) { | ||
return err || console.log('Created dist/sitemap.txt') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is no output if err. You want: if (err) throw err
console.log('Created dist/sitemap.txt') |
||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/caolan/async#filter ?