sitemap eslinted

This commit is contained in:
tmshv committed 2016-11-12 12:21:07 +03:00
1 parent da5823ddf7
commit a5f95a36c5
1 file changed
+65 -65
+65 -65
View File
@@ -1,41 +1,41 @@
import sitemap from 'sitemap'; import sitemap from 'sitemap';
import route from 'koa-route'; import route from 'koa-route';
import {c} from '../core/db'; import {c} from '../core/db';
import {getPageUrls as pages} from '../core/pages'; import {getPageUrls as pages} from '../core/pages';
import {homeUrl, sitemapCacheTime} from '../config'; import {homeUrl, sitemapCacheTime} from '../config';
import menu from '../models/menu'; import menu from '../models/menu';
export default function () { export default function () {
return route.get('/sitemap.xml', async ctx => { return route.get('/sitemap.xml', async ctx => {
let urls = await Promise.all([ let urls = await Promise.all([
getMenuUrls(), getMenuUrls(),
getPageUrls(), getPageUrls(),
getGalleryUrls(), getGalleryUrls(),
getTeacherUrls(), getTeacherUrls(),
getEventsUrls(), getEventsUrls(),
getNewsUrls() getNewsUrls()
]); ]);
urls = urls.reduce((urls, i) => urls.concat(i)); urls = urls.reduce((urls, i) => urls.concat(i));
let map = sitemap.createSitemap({ let map = sitemap.createSitemap({
hostname: homeUrl, hostname: homeUrl,
cacheTime: sitemapCacheTime, cacheTime: sitemapCacheTime,
urls: urls urls: urls
}); });
ctx.set('Content-Type', 'application/xml'); ctx.set('Content-Type', 'application/xml');
ctx.body = map.toString(); ctx.body = map.toString();
}) })
}; };
async function getMenuUrls(frequency='daily') { async function getMenuUrls(frequency = 'daily') {
return menu return menu
.filter(i => 'url' in i) .filter(i => 'url' in i)
.map(i => ({ .map(i => ({
url: i.url, url: i.url,
changefreq: frequency changefreq: frequency
})); }));
} }
async function getPageUrls(frequency = 'daily') { async function getPageUrls(frequency = 'daily') {
@@ -47,53 +47,53 @@ async function getPageUrls(frequency = 'daily') {
} }
async function getGalleryUrls() { async function getGalleryUrls() {
let docs = await c('albums') let docs = await c('albums')
.find({}) .find({})
.toArray(); .toArray();
return docs.map(i => { return docs.map(i => {
return { return {
url: `/album/${i.id}`, url: `/album/${i.id}`,
changefreq: 'monthly' changefreq: 'monthly'
} }
}); });
} }
async function getTeacherUrls() { async function getTeacherUrls() {
let docs = await c('collective') let docs = await c('collective')
.find({}) .find({})
.toArray(); .toArray();
return docs.map(i => { return docs.map(i => {
return { return {
url: `/teacher/${i.id}`, url: `/teacher/${i.id}`,
changefreq: 'monthly' changefreq: 'monthly'
} }
}); });
} }
async function getEventsUrls() { async function getEventsUrls() {
let docs = await c('events') let docs = await c('events')
.find({}) .find({})
.toArray(); .toArray();
return docs.map(i => { return docs.map(i => {
return { return {
url: `/article/${i.id}`, url: `/article/${i.id}`,
changefreq: 'monthly' changefreq: 'monthly'
} }
}); });
} }
async function getNewsUrls() { async function getNewsUrls() {
let docs = await c('timeline') let docs = await c('timeline')
.find({type: 'post'}) .find({type: 'post'})
.toArray(); .toArray();
return docs.map(i => { return docs.map(i => {
return { return {
url: `/article/${i.id}`, url: `/article/${i.id}`,
changefreq: 'monthly' changefreq: 'monthly'
} }
}); });
} }