From 06c1475c5f6a4c5d56f3b87ca0512407acc18e04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fe=CC=81lix=20Pe=CC=81ault?= Date: Sun, 19 Apr 2020 12:26:16 +0200 Subject: [PATCH] Sitemap: Get location modified date if no photo exists Only for not throwing an error --- src/routes/sitemap.xml.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/routes/sitemap.xml.js b/src/routes/sitemap.xml.js index f1de5b4..da8e216 100644 --- a/src/routes/sitemap.xml.js +++ b/src/routes/sitemap.xml.js @@ -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) -} +} \ No newline at end of file