robots.txt + sitemap.xml

This commit is contained in:
tmshv committed 2019-08-03 19:02:07 +03:00
1 parent 5ab2084763
commit 1b77f6b2de
6 files changed
+85 -88

No files matched your search

-86
View File
@@ -1,86 +0,0 @@
const sitemap = require('sitemap')
const route = require('koa-route')
const {c} = require('../core/db')
const {getPageUrls: pages} = require('../core/pages')
const getPathWithNoTrailingSlash = require('../lib/url').getPathWithNoTrailingSlash
const {homeUrl, sitemapCacheTime} = require('../config')
const menu = require('../models/menu').default
module.exports = function () {
return route.get('/sitemap.xml', async ctx => {
let urls = await Promise.all([
getMenuUrls(),
getPageUrls(),
getGalleryUrls(),
getTeacherUrls(),
getArticleUrls(),
])
urls = urls.reduce((urls, i) => urls.concat(i))
let map = sitemap.createSitemap({
hostname: homeUrl,
cacheTime: sitemapCacheTime,
urls: urls
})
ctx.set('Content-Type', 'application/xml')
ctx.body = map.toString()
})
}
async function getMenuUrls(frequency = 'daily') {
return menu
.filter(i => 'url' in i)
.map(i => ({
url: getPathWithNoTrailingSlash(i.url),
changefreq: frequency
}))
}
async function getPageUrls(frequency = 'daily') {
const ps = await pages()
return ps.map(i => ({
url: i.url,
changefreq: frequency
}))
}
async function getGalleryUrls() {
let docs = await c('albums')
.find({})
.toArray()
return docs.map(i => {
return {
url: `/album/${i.id}`,
changefreq: 'monthly'
}
})
}
async function getTeacherUrls() {
let docs = await c('collective')
.find({})
.toArray()
return docs.map(i => {
return {
url: `/teacher/${i.id}`,
changefreq: 'monthly'
}
})
}
async function getArticleUrls() {
let docs = await c('articles')
.find({})
.toArray()
return docs.map(i => {
return {
url: `/article/${i.id}`,
changefreq: 'monthly'
}
})
}