dynamic sitemap.xml

This commit is contained in:
tmshv committed 2015-08-05 02:48:41 +03:00
1 parent 084001791b
commit 4c25f36816
4 files changed
+59 -31

No files matched your search

-3
View File
@@ -49,9 +49,6 @@ gulp.task("copy", function(){
gulp.src("robots.txt")
.pipe(gulp.dest("./public"));
gulp.src("sitemap.xml")
.pipe(gulp.dest("./public"));
});
gulp.task("compile", function(){
+57
View File
@@ -0,0 +1,57 @@
/**
* Created by tmshv on 22/11/14.
*/
var co = require("co");
var sitemap = require("sitemap");
var route = require("koa-route");
var router = require("./");
var db = require("../core/db");
module.exports = function (app) {
app.use(route.get("/sitemap.xml", function *() {
var urls = yield [menu(), gallery()];
urls = urls.reduce(function (urls, i) {
return urls.concat(i);
});
var sm = sitemap.createSitemap({
hostname: 'http://art.shlisselburg.org',
cacheTime: 600000, // 600 sec - cache purge period
urls: urls
});
var data = yield new Promise(function (resolve) {
sm.toXML(resolve);
});
this.set('Content-Type', 'application/xml');
this.body = data;
}));
};
function *menu(){
return require('../models/menu.json')
.filter(function(item){
return 'url' in item
})
.map(function (item) {
return {
url: item.url,
changefreq: 'daily'
}
});
}
function *gallery(){
var albums = yield db.c("albums")
.find({})
.toArray();
return albums.map(function (album) {
return {
url: `/gallery/${album.date.getFullYear()}${album.course_uri}${album.uri}`,
changefreq: 'monthly'
}
});
}
+2
View File
@@ -61,6 +61,8 @@ app.use(route.get("/document/:doc", routes.index(
path.join(__dirname, "templates/document.html")
)));
require("./routes/sitemap")(app);
require("./routes/schedule")(app);
require("./routes/news")(app);
require("./routes/gallery")(app);
-28
View File
@@ -1,28 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>http://art.shlisselburg.org</loc>
<changefreq>daily</changefreq>
</url>
<url>
<loc>http://art.shlisselburg.org/schedule</loc>
<changefreq>weekly</changefreq>
</url>
<url>
<loc>http://art.shlisselburg.org/team</loc>
<changefreq>monthly</changefreq>
</url>
<url>
<loc>http://art.shlisselburg.org/gallery</loc>
<changefreq>weekly</changefreq>
</url>
<url>
<loc>http://art.shlisselburg.org/docs</loc>
<changefreq>weekly</changefreq>
</url>
</urlset>