Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions build/sitemap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
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'))

if (!packageJson.config.deploy.prod) throw new Error('Can\'t find packageJson.config.deploy.prod')

async.waterfall([
function read (done) {
fs.readdir(inputDir, done)
},
function filter (contents, done) {
async.filter(contents, function (item, callback) {
fs.stat(path.join(inputDir, item), function (err, stat) {
if (err) return callback(err)
callback(null, stat.isDirectory && item !== 'home')
})
}, done)
},
function createUrls (pages, done) {
var routes = pages.map(function (page) { return 'https://' + packageJson.config.deploy.prod + '/' + page })

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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 package.json. Currently, we're scattered in config.deploy.prod, subPages etc. for another PR perhaps

var sitemap = routes.join('\n')
var writePath = path.join(outputDir, 'sitemap.txt')
fs.writeFile(writePath, sitemap, done)
}
], function (err) {
if (err) throw err
console.log('Created dist/sitemap.txt')
})
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"build:css": "node build/sass.js | postcss --local-plugins --use autoprefixer --output dist/bundle.css",
"build:html": "node build/jade.js",
"build:js": "browserify -t jadeify pages/main.js -o dist/bundle.js",
"build:sitemap": "node build/sitemap.js",
"minify:js": "uglifyjs dist/bundle.js -o dist/bundle.js",
"minify:css": "postcss -u cssnano -i dist/bundle.css -o dist/bundle.css",
"minify:svg": "svgo --disable=cleanupIDs --disable=removeHiddenElems dist/bundle.svg",
Expand Down Expand Up @@ -86,4 +87,4 @@
"template": "wedding"
}
}
}
}