From 0a27655f22c254f0c728c5b41e93a0d578a9d1e2 Mon Sep 17 00:00:00 2001 From: Giovanni Bassi Date: Sat, 26 Oct 2013 14:28:00 -0200 Subject: [PATCH] site map, #138 --- app/routes/home.coffee | 29 +++++++++++++++++++++++++++++ app/routes/router.coffee | 1 + npm-shrinkwrap.json | 8 ++++++-- package.json | 3 ++- 4 files changed, 38 insertions(+), 3 deletions(-) diff --git a/app/routes/home.coffee b/app/routes/home.coffee index b7d79bc..aaa1714 100644 --- a/app/routes/home.coffee +++ b/app/routes/home.coffee @@ -74,3 +74,32 @@ module.exports = class HomeRoutes (req, res) -> filePath = path.join publicDir, file res.sendfile filePath + + sitemap: -> + sm = require 'sitemap' + map = + hostname: 'https://www.atelies.com.br/', + cacheTime: 12 * 60 * 60 * 1000 # twice a day, in miliseconds + urls: [ + { url: '', changefreq: 'always', priority: 0.6 } + { url: 'faq', changefreq: 'monthly', priority: 0.1 } + { url: "about", changefreq: 'monthly', priority: 0.1 } + { url: "terms", changefreq: 'monthly', priority: 0.1 } + { url: "faq", changefreq: 'monthly', priority: 0.1 } + { url: "technology", changefreq: 'monthly', priority: 0.1 } + { url: "iWantToBuy", changefreq: 'monthly', priority: 0.1 } + { url: "iWantToSell", changefreq: 'monthly', priority: 0.1 } + { url: "contribute", changefreq: 'monthly', priority: 0.1 } + { url: "donating", changefreq: 'monthly', priority: 0.1 } + ] + Store.find().select('slug').exec (err, stores) -> + unless err? + map.urls.push { url: store.slug, changefreq: 'weekly', priority: 0.7 } for store in stores + Product.find().select('slug storeSlug').exec (err, products) -> + unless err? + map.urls.push { url: product.url(), changefreq: 'weekly', priority: 0.7 } for product in products + sitemap = sm.createSitemap map + (req, res) -> + sitemap.toXML (xml) -> + res.header 'Content-Type', 'application/xml' + res.send xml diff --git a/app/routes/router.coffee b/app/routes/router.coffee index e4c426c..55eb9f0 100644 --- a/app/routes/router.coffee +++ b/app/routes/router.coffee @@ -33,6 +33,7 @@ exports.route = (app) -> app.post "/api/error", home.errorCreate app.get "/humans.txt", home.staticFile 'humans.txt' app.get "/robots.txt", home.staticFile 'robots.txt' + app.get "/sitemap.xml", home.sitemap() #home client routes app.get "/searchProducts/:searchTerm?", home.index domain app.get "/searchStores/:searchTerm?", home.index domain diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index 78c3d7a..4d7e30a 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -931,8 +931,7 @@ }, "requirejs": { "version": "2.1.8", - "from": "requirejs@2.1.8", - "resolved": "https://registry.npmjs.org/requirejs/-/requirejs-2.1.8.tgz" + "from": "requirejs@2.1.8" }, "connect-mongo": { "version": "0.3.3", @@ -1019,6 +1018,11 @@ "version": "0.1.3", "from": "prerender-node@0.1.3", "resolved": "https://registry.npmjs.org/prerender-node/-/prerender-node-0.1.3.tgz" + }, + "sitemap": { + "version": "0.7.0", + "from": "sitemap@", + "resolved": "https://registry.npmjs.org/sitemap/-/sitemap-0.7.0.tgz" } } } diff --git a/package.json b/package.json index 90078de..3f7f7cb 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,8 @@ "gm": "~1.13.3", "marked": "~0.2.9", "grunt-wait": "~0.1.0", - "prerender-node": "~0.1.3" + "prerender-node": "~0.1.3", + "sitemap": "~0.7.0" }, "devDependencies": { "grunt-coffeelint": "0.0.x",