Sitemap: Get location modified date if no photo exists

Only for not throwing an error
This commit is contained in:
2020-04-19 12:26:16 +02:00
parent ef287a432d
commit 06c1475c5f

View File

@@ -47,7 +47,7 @@ export async function get (req, res, next) {
baseURL = `http${(req.httpVersion >= 2) ? 's' : ''}://${req.headers.host}`
// 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,modified_on`)
const locationsData = await locationsReq.json()
const locations = locationsData.data
@@ -56,7 +56,7 @@ export async function get (req, res, next) {
const latestPhotoReq = await fetch(`${apiEndpoints.rest}/items/photos?fields=created_on&limit=1&sort=created_on&filter[location.slug][rlike]=%${location.slug}`)
const latestPhotoData = await latestPhotoReq.json()
const latestPhoto = latestPhotoData.data[0]
location.updated = latestPhoto.created_on
location.updated = latestPhoto ? latestPhoto.created_on : location.modified_on
return location
})
await Promise.all(updatedLocations)
@@ -68,4 +68,4 @@ export async function get (req, res, next) {
// Render sitemap
const sitemap = render(pages, locations)
res.end(sitemap)
}
}