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 = [ const fields = [
'id', 'name', 'slug', 'date', 'image.*', 'id', 'name', 'slug', 'date', 'image.*',
'location.id', 'location.name', 'location.slug', 'location.region', 'location.country.name', 'location.country.slug', 'location.id', 'location.name', 'location.slug', 'location.region', 'location.country.name', 'location.country.slug',
'created_on' 'created_on', 'modified_on'
].join(',') ].join(',')
const sort = ['-created_on', 'name'].join(',') const sort = ['-created_on', 'name'].join(',')
const limit = -1 const limit = -1

View File

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

View File

@@ -1,7 +1,6 @@
.photos { .photos {
position: relative; position: relative;
margin-top: -22px; margin-top: -22px;
overflow-x: hidden;
background-color: #fff; background-color: #fff;
@include breakpoint (sm) { @include breakpoint (sm) {
@@ -55,6 +54,7 @@
position: relative; position: relative;
z-index: 4; z-index: 4;
margin-bottom: 88px; margin-bottom: 88px;
overflow-x: hidden;
@include breakpoint (sm) { @include breakpoint (sm) {
margin-bottom: 120px; margin-bottom: 120px;