Skip to content

Commit

Permalink
Merge pull request #346 from baby230211/feat/generate-static-site-2021
Browse files Browse the repository at this point in the history
fix : 2021 θ½‰ζ›ιœζ…‹ι 
  • Loading branch information
josix authored Nov 27, 2022
2 parents 98ad119 + 03da23e commit 7c049b2
Show file tree
Hide file tree
Showing 10 changed files with 217 additions and 76 deletions.
60 changes: 60 additions & 0 deletions nuxt.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import axios from 'axios'

const DEFAULT_BASE_URL = 'http://staging.pycon.tw/prs'
const DEFAULT_ROUTER_BASE = '/2021/'
const DEFAULT_BUILD_TARGET = 'static'
Expand All @@ -7,6 +9,64 @@ export default {
target: process.env.BUILD_TARGET || DEFAULT_BUILD_TARGET,

// Re-route for GitHub Pages to serve with /assets
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
},
},
router: {
base: process.env.ROUTER_BASE || DEFAULT_ROUTER_BASE,
// scroll behavior config for scroll to hash
Expand Down
121 changes: 85 additions & 36 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"core-js": "^3.6.5",
"dayjs": "^1.10.6",
"nuxt": "^2.15.3",
"axios": "^0.27.2",
"nuxt-fontawesome": "^0.4.0",
"nuxt-i18n": "^6.18.0",
"uuid": "^8.3.2",
Expand Down
17 changes: 13 additions & 4 deletions pages/conference/_eventType/_id.vue
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,19 @@ export default {
Youtube,
MarkdownRenderer,
},
async asyncData({ store, params, payload }) {
if (payload && Object.keys(payload).length !== 0) {
return {
speechData: payload,
}
}
await store.dispatch('$getSpeechData', {
eventType: params.eventType,
eventId: params.id,
})
const speechData = store.state.speechData
return { speechData }
},
data() {
return {
data: {
Expand Down Expand Up @@ -215,10 +228,6 @@ export default {
...mapState(['speechData']),
},
async created() {
await this.$store.dispatch('$getSpeechData', {
eventType: this.$route.params.eventType,
eventId: this.$route.params.id,
})
await this.processData()
this.$root.$emit('initTabs')
},
Expand Down
Loading

0 comments on commit 7c049b2

Please sign in to comment.