Fix things
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2020-03-22 20:07:11 +01:00
parent 039e664325
commit dedf400ea8
3 changed files with 12 additions and 10 deletions

View File

@@ -7,7 +7,7 @@
const fields = [
'id', 'name', 'slug', 'date', 'image.*',
'location.id', 'location.name', 'location.slug', 'location.region', 'location.country.name', 'location.country.slug',
'created_on'
'created_on', 'modified_on'
].join(',')
const sort = ['-created_on', 'name'].join(',')
const limit = -1

View File

@@ -4,10 +4,10 @@ import { apiEndpoints } from '../utils/store'
// Variables
let BASE_URL
let baseURL
const pages = ['']
// Get each route
// Get routes and push it to array
fs.readdirSync('./src/routes').forEach(file => {
const filename = file.split('.')[0]
if (!file.startsWith('.') && !filename.startsWith('_') && ['sitemap', 'index', 'location', 'viewer'].indexOf(filename) === -1) {
@@ -15,10 +15,9 @@ fs.readdirSync('./src/routes').forEach(file => {
}
})
// Render function
const render = (pages, locations) => {
console.log(locations)
return `<?xml version="1.0" encoding="UTF-8" ?>
<urlset
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
@@ -27,13 +26,13 @@ const render = (pages, locations) => {
>
${pages.map(page => `
<url>
<loc>${BASE_URL}/${page}</loc>
<loc>${baseURL}/${page}</loc>
<priority>0.75</priority>
</url>`).join('\n')}
${locations.map(loc => `
<url>
<loc>${BASE_URL}/location/${loc.country.slug}/${loc.slug}</loc>
<loc>${baseURL}/location/${loc.country.slug}/${loc.slug}</loc>
<priority>1</priority>
</url>`).join('\n')}
</urlset>`
@@ -41,15 +40,18 @@ const render = (pages, locations) => {
// Get function
export async function get (req, res, next) {
BASE_URL = `http${(req.httpVersion >= 2) ? 's' : ''}://${req.headers.host}`
// Define base url from request
baseURL = `http${(req.httpVersion >= 2) ? 's' : ''}://${req.headers.host}`
// Get locations
const locationsReq = await fetch(`${apiEndpoints.rest}/items/locations?fields=slug,country.slug`)
const locations = await locationsReq.json()
res.setHeader('Cache-Control', `max-age=0, s-max-age=${600}`) // 10 minutes
// Set headers
res.setHeader('Cache-Control', 'max-age=0, s-max-age=600') // 10 minutes
res.setHeader('Content-Type', 'application/rss+xml')
// Render sitemap
const sitemap = render(pages, locations.data)
res.end(sitemap)
}