Skip to content
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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
29 changes: 29 additions & 0 deletions build/sitemap.js
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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}).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 })
Copy link
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').toString()
Copy link
Member

Choose a reason for hiding this comment

The 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')
Copy link
Member

Choose a reason for hiding this comment

The 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')

})
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"
}
}
}
}