Merge branch 'dev'

This commit is contained in:
2020-05-09 19:04:13 +02:00
2 changed files with 49 additions and 12 deletions

View File

@@ -26,7 +26,6 @@ steps:
mount: mount:
- "node_modules" - "node_modules"
# #
# Build Node.js app # Build Node.js app
# #
@@ -36,7 +35,6 @@ steps:
- npm install -s - npm install -s
- npm run build - npm run build
# #
# Build the Docker image # Build the Docker image
# #
@@ -65,6 +63,7 @@ steps:
- master - master
# #
# Restart container # Restart container
# #
@@ -72,13 +71,13 @@ steps:
- name: restart-container-dev - name: restart-container-dev
image: appleboy/drone-ssh image: appleboy/drone-ssh
settings: settings:
host: flayks.com host: housesof.world
username: username:
from_secret: ssh_user from_secret: ssh_user
key: key:
from_secret: ssh_key from_secret: ssh_key
script: script:
- cd /data/sites/housesof.world/dev - cd /data/sites/housesof.world/test
- docker-compose down - docker-compose down
- docker-compose up -d --remove-orphans - docker-compose up -d --remove-orphans
when: when:
@@ -89,7 +88,7 @@ steps:
- name: restart-container-prod - name: restart-container-prod
image: appleboy/drone-ssh image: appleboy/drone-ssh
settings: settings:
host: flayks.com host: housesof.world
username: username:
from_secret: ssh_user from_secret: ssh_user
key: key:
@@ -103,6 +102,38 @@ steps:
- master - master
#
# Purge CDN
#
# DEV
- name: cdn-purge-dev
image: plugins/webhook
settings:
urls:
from_secret: cdn_purgeurl_dev
headers:
from_secret: cdn_accesskey
method: POST
when:
branch:
- dev
# PROD
- name: cdn-purge-prod
image: plugins/webhook
settings:
urls:
from_secret: cdn_purgeurl_prod
headers:
from_secret: cdn_accesskey
method: POST
when:
branch:
- master
# #
# Rebuild cache # Rebuild cache
# #

View File

@@ -45,20 +45,26 @@ const render = (pages, locations) => {
// Get function // Get function
export async function get (req, res, next) { export async function get (req, res, next) {
let locations
// Define base url from request // Define base url from request
baseURL = `https://${req.headers.host}` baseURL = `https://${req.headers.host}`
// Get locations // Get locations
const locationsReq = await fetch(`${apiEndpoints.rest}/items/locations?fields=slug,country.slug,modified_on&status=published`) await fetch(`${apiEndpoints.rest}/items/locations?fields=slug,country.slug,modified_on&status=published&sort=created_on`)
const locationsData = await locationsReq.json() .then(res => res.json())
const locations = locationsData.data .then(res => {
locations = res.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&status=published&filter[location.slug][rlike]=%${location.slug}`) 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() .then(res => res.json())
const latestPhoto = latestPhotoData.data[0] .then(res => {
location.updated = latestPhoto ? latestPhoto.created_on : location.modified_on const latestPhoto = res.data[0]
location.updated = latestPhoto ? latestPhoto.created_on : location.modified_on
})
return location return location
}) })
await Promise.all(updatedLocations) await Promise.all(updatedLocations)