Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate static version of all space pages #62

Merged
merged 5 commits into from
Aug 6, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions config/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import flattenDeep from 'lodash/flattenDeep'
import pagesI18n from '../src/pages.i18n'
const locales = ['en', 'nl']
const buildings = require('../src/static/data/buildings.json')
const spaces = require('../src/static/data/spaces.json')

const rootRoutes = locales.map(locale => {
const route = pagesI18n['buildings/index'][locale]
Expand All @@ -17,9 +18,20 @@ const buildingRoutes = flattenDeep(buildings.map(building => {
})
}))

const spaceRoutes = flattenDeep(spaces.map(space => {
return locales.map(locale => {
const building = buildings.find((building) => building.number === space.buildingNumber)
const route = pagesI18n['buildings/_buildingSlug/spaces/_spaceSlug'][locale]
.replace(':buildingSlug', building.i18n[locale].slug)
.replace(':spaceSlug', space.slug)
return `/${locale}${route}`
})
}))

const routes = [
...rootRoutes,
...buildingRoutes,
...spaceRoutes
]

export default routes
12 changes: 12 additions & 0 deletions src/pages/buildings/_buildingSlug/spaces/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<script>
export default {
validate({ app, params, redirect }) {
const { buildingSlug } = params
const url = app.localePath({
name: 'buildings-buildingSlug',
params: { buildingSlug }
})
redirect(url)
}
}
</script>
12 changes: 10 additions & 2 deletions src/static/_redirects
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# our default language is English, so redirect to it:
/ /en/ 301
/en/* /en/ 200
/nl/* /nl/ 200

# a list of spaces is available on the building page, so redirect to it:
/en/buildings/:buildingSlug/spaces/ /en/buildings/:buildingSlug 302
/nl/gebouwen/:buildingSlug/ruimtes/ /en/gebouwen/:buildingSlug 302

# all existing routes are pre-generated, so missing routes are non-existing (404):
/en/* /en/404/ 404
/nl/* /nl/404/ 404
/* /en/404/ 404