diff --git a/nuxt.config.js b/nuxt.config.js index 67dbc96e4f..05c4415014 100644 --- a/nuxt.config.js +++ b/nuxt.config.js @@ -1,3 +1,5 @@ +import axios from 'axios' + const DEFAULT_BASE_URL = 'http://staging.pycon.tw/prs' const DEFAULT_ROUTER_BASE = '/2022/' const DEFAULT_BUILD_TARGET = 'static' @@ -5,7 +7,63 @@ const DEFAULT_BUILD_TARGET = 'static' export default { // Target (https://go.nuxtjs.dev/config-target) target: process.env.BUILD_TARGET || DEFAULT_BUILD_TARGET, - + generate: { + async routes() { + const config = { + headers: { + authorization: `Token ${process.env.AUTH_TOKEN}`, + }, + } + const talks = await axios.get( + `${DEFAULT_BASE_URL}/api/events/speeches/?event_types=talk,sponsored`, + config, + ) + const tutorials = await axios.get( + `${DEFAULT_BASE_URL}/api/events/speeches/?event_types=tutorial`, + config, + ) + const getAllDetailTalks = async () => { + const data = await Promise.all( + talks.data.map(async (talk) => { + return await axios + .get( + `${DEFAULT_BASE_URL}/api/events/speeches/${talk.event_type}/${talk.id}/`, + config, + ) + .then((response) => response.data) + }), + ) + return data + } + const getAllDetailTutorials = async () => { + const data = await Promise.all( + tutorials.data.map(async (tutorial) => { + return await axios + .get( + `${DEFAULT_BASE_URL}/api/events/speeches/${tutorial.event_type}/${tutorial.id}/`, + config, + ) + .then((response) => response.data) + }), + ) + return data + } + const detailTalks = await getAllDetailTalks() + const detailTutorials = await getAllDetailTutorials() + + const routes = [ + ...detailTalks.map((talk) => ({ + route: `/conference/${talk.event_type}/${talk.id}`, + payload: talk, + })), + ...detailTutorials.map((tutorial) => ({ + route: `/conference/${tutorial.event_type}/${tutorial.id}`, + payload: tutorial, + })), + ] + return routes + }, + }, // Re-route for GitHub Pages to serve with /assets router: { base: process.env.ROUTER_BASE || DEFAULT_ROUTER_BASE, diff --git a/pages/conference/_eventType/_id.vue b/pages/conference/_eventType/_id.vue index 00afa01816..c1730ecf9e 100644 --- a/pages/conference/_eventType/_id.vue +++ b/pages/conference/_eventType/_id.vue @@ -144,8 +144,6 @@