Only fetch published photos and locations
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
- Globally for photos - For sitemap locations and photos
This commit is contained in:
@@ -11,7 +11,7 @@
|
|||||||
'location.country.name', 'location.country.slug'
|
'location.country.name', 'location.country.slug'
|
||||||
]
|
]
|
||||||
const sort = '?' // Random sort
|
const sort = '?' // Random sort
|
||||||
const req = await this.fetch(`${apiEndpoints.rest}/items/photos?fields=${fields.join()}&sort=${sort}&limit=${limit}`, {
|
const req = await this.fetch(`${apiEndpoints.rest}/items/photos?fields=${fields.join()}&status=published&sort=${sort}&limit=${limit}`, {
|
||||||
'Authorization': 'bearer ' + process.env.CONFIG.API_TOKEN
|
'Authorization': 'bearer ' + process.env.CONFIG.API_TOKEN
|
||||||
})
|
})
|
||||||
const photos = await req.json()
|
const photos = await req.json()
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
].join(',')
|
].join(',')
|
||||||
const sort = ['-created_on', 'name'].join(',')
|
const sort = ['-created_on', 'name'].join(',')
|
||||||
const limit = -1
|
const limit = -1
|
||||||
const req = await this.fetch(`${apiEndpoints.rest}/items/photos?fields=${fields}&filter[location.slug][rlike]=%${page.params.place}%&limit=${limit}&sort=${sort}`, {
|
const req = await this.fetch(`${apiEndpoints.rest}/items/photos?fields=${fields}&status=published&filter[location.slug][rlike]=%${page.params.place}%&limit=${limit}&sort=${sort}`, {
|
||||||
'Authorization': 'bearer ' + process.env.CONFIG.API_TOKEN
|
'Authorization': 'bearer ' + process.env.CONFIG.API_TOKEN
|
||||||
})
|
})
|
||||||
const photos = await req.json()
|
const photos = await req.json()
|
||||||
|
|||||||
@@ -47,13 +47,13 @@ export async function get (req, res, next) {
|
|||||||
baseURL = `http${(req.httpVersion >= 2) ? 's' : ''}://${req.headers.host}`
|
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,modified_on`)
|
const locationsReq = await fetch(`${apiEndpoints.rest}/items/locations?fields=slug,country.slug,modified_on&status=published`)
|
||||||
const locationsData = await locationsReq.json()
|
const locationsData = await locationsReq.json()
|
||||||
const locations = locationsData.data
|
const locations = locationsData.data
|
||||||
|
|
||||||
// Add last modified date to each location from its last photo
|
// Add last modified date to each location from its last photo
|
||||||
const updatedLocations = locations.map(async (location, i) => {
|
const updatedLocations = locations.map(async (location, i) => {
|
||||||
const latestPhotoReq = await fetch(`${apiEndpoints.rest}/items/photos?fields=created_on&limit=1&sort=created_on&filter[location.slug][rlike]=%${location.slug}`)
|
const latestPhotoReq = await fetch(`${apiEndpoints.rest}/items/photos?fields=created_on&limit=1&sort=created_on&status=published&filter[location.slug][rlike]=%${location.slug}`)
|
||||||
const latestPhotoData = await latestPhotoReq.json()
|
const latestPhotoData = await latestPhotoReq.json()
|
||||||
const latestPhoto = latestPhotoData.data[0]
|
const latestPhoto = latestPhotoData.data[0]
|
||||||
location.updated = latestPhoto ? latestPhoto.created_on : location.modified_on
|
location.updated = latestPhoto ? latestPhoto.created_on : location.modified_on
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
'location.id', 'location.name', 'location.slug',
|
'location.id', 'location.name', 'location.slug',
|
||||||
'location.country.name', 'location.country.slug'
|
'location.country.name', 'location.country.slug'
|
||||||
]
|
]
|
||||||
const req = await this.fetch(`${apiEndpoints.rest}/items/photos?fields=${fields.join()}&filter[location.slug][rlike]=%${page.params.place}%`, {
|
const req = await this.fetch(`${apiEndpoints.rest}/items/photos?fields=${fields.join()}&status=published&filter[location.slug][rlike]=%${page.params.place}%`, {
|
||||||
'Authorization': 'bearer ' + process.env.CONFIG.API_TOKEN
|
'Authorization': 'bearer ' + process.env.CONFIG.API_TOKEN
|
||||||
})
|
})
|
||||||
const photos = await req.json()
|
const photos = await req.json()
|
||||||
|
|||||||
Reference in New Issue
Block a user