Skip to content

Commit 7c049b2

Browse files
authored
Merge pull request #346 from baby230211/feat/generate-static-site-2021
fix : 2021 θ½‰ζ›ιœζ…‹ι 
2 parents 98ad119 + 03da23e commit 7c049b2

File tree

10 files changed

+217
-76
lines changed

10 files changed

+217
-76
lines changed

β€Žnuxt.config.jsβ€Ž

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import axios from 'axios'
2+
13
const DEFAULT_BASE_URL = 'http://staging.pycon.tw/prs'
24
const DEFAULT_ROUTER_BASE = '/2021/'
35
const DEFAULT_BUILD_TARGET = 'static'
@@ -7,6 +9,64 @@ export default {
79
target: process.env.BUILD_TARGET || DEFAULT_BUILD_TARGET,
810

911
// Re-route for GitHub Pages to serve with /assets
12+
generate: {
13+
async routes() {
14+
const config = {
15+
headers: {
16+
authorization: `Token ${process.env.AUTH_TOKEN}`,
17+
},
18+
}
19+
const talks = await axios.get(
20+
`${DEFAULT_BASE_URL}/api/events/speeches/?event_types=talk,sponsored`,
21+
config,
22+
)
23+
const tutorials = await axios.get(
24+
`${DEFAULT_BASE_URL}/api/events/speeches/?event_types=tutorial`,
25+
config,
26+
)
27+
const getAllDetailTalks = async () => {
28+
const data = await Promise.all(
29+
talks.data.map(async (talk) => {
30+
return await axios
31+
.get(
32+
`${DEFAULT_BASE_URL}/api/events/speeches/${talk.event_type}/${talk.id}/`,
33+
config,
34+
)
35+
.then((response) => response.data)
36+
}),
37+
)
38+
return data
39+
}
40+
const getAllDetailTutorials = async () => {
41+
const data = await Promise.all(
42+
tutorials.data.map(async (tutorial) => {
43+
return await axios
44+
.get(
45+
`${DEFAULT_BASE_URL}/api/events/speeches/${tutorial.event_type}/${tutorial.id}/`,
46+
config,
47+
)
48+
.then((response) => response.data)
49+
}),
50+
)
51+
return data
52+
}
53+
54+
const detailTalks = await getAllDetailTalks()
55+
const detailTutorials = await getAllDetailTutorials()
56+
57+
const routes = [
58+
...detailTalks.map((talk) => ({
59+
route: `/conference/${talk.event_type}/${talk.id}`,
60+
payload: talk,
61+
})),
62+
...detailTutorials.map((tutorial) => ({
63+
route: `/conference/${tutorial.event_type}/${tutorial.id}`,
64+
payload: tutorial,
65+
})),
66+
]
67+
return routes
68+
},
69+
},
1070
router: {
1171
base: process.env.ROUTER_BASE || DEFAULT_ROUTER_BASE,
1272
// scroll behavior config for scroll to hash

β€Žpackage-lock.jsonβ€Ž

Lines changed: 85 additions & 36 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Žpackage.jsonβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"core-js": "^3.6.5",
2424
"dayjs": "^1.10.6",
2525
"nuxt": "^2.15.3",
26+
"axios": "^0.27.2",
2627
"nuxt-fontawesome": "^0.4.0",
2728
"nuxt-i18n": "^6.18.0",
2829
"uuid": "^8.3.2",

β€Žpages/conference/_eventType/_id.vueβ€Ž

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,19 @@ export default {
185185
Youtube,
186186
MarkdownRenderer,
187187
},
188+
async asyncData({ store, params, payload }) {
189+
if (payload && Object.keys(payload).length !== 0) {
190+
return {
191+
speechData: payload,
192+
}
193+
}
194+
await store.dispatch('$getSpeechData', {
195+
eventType: params.eventType,
196+
eventId: params.id,
197+
})
198+
const speechData = store.state.speechData
199+
return { speechData }
200+
},
188201
data() {
189202
return {
190203
data: {
@@ -215,10 +228,6 @@ export default {
215228
...mapState(['speechData']),
216229
},
217230
async created() {
218-
await this.$store.dispatch('$getSpeechData', {
219-
eventType: this.$route.params.eventType,
220-
eventId: this.$route.params.id,
221-
})
222231
await this.processData()
223232
this.$root.$emit('initTabs')
224233
},

0 commit comments

Comments
Β (0)