Skip to content

Commit

Permalink
Merge pull request #380 from baby230211/pycontw-2022
Browse files Browse the repository at this point in the history
feat: add dynamic routes configuration for generate
  • Loading branch information
josix authored Feb 25, 2023
2 parents 1a7bd4c + b06502c commit 3afab52
Show file tree
Hide file tree
Showing 11 changed files with 160 additions and 50 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ jobs:
- name: Build 👷🏽
run: npm run generate
env:
ROUTER_BASE: /pycontw-2021/ # repo name
ROUTER_BASE: /pycontw-frontend/ # repo name
BUILD_TARGET: static
API_URL_BROWSER: https://staging.pycon.tw/prs
API_URL_BROWSER: https://tw.pycon.org/temp
AUTH_TOKEN: ${{ secrets.AUTH_TOKEN }}
GOOGLE_TAG_MANAGER_ID: ${{ secrets.GOOGLE_TAG_MANAGER_ID }}

Expand Down
61 changes: 60 additions & 1 deletion nuxt.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,68 @@
const DEFAULT_BASE_URL = 'http://staging.pycon.tw/prs'
import axios from 'axios'
const DEFAULT_BASE_URL = 'https://tw.pycon.org/temp'
const DEFAULT_ROUTER_BASE = '/2022/'
const DEFAULT_BUILD_TARGET = 'static'
const DEFAULT_VUE_DEVTOOL = false

export default {
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
},
},
vue: {
config: {
devtools: process.env.VUE_DEVTOOL || DEFAULT_VUE_DEVTOOL,
Expand Down
28 changes: 23 additions & 5 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 @@ -20,6 +20,7 @@
"@nuxt/http": "^0.6.2",
"@nuxtjs/markdownit": "^2.0.0",
"@tailwindcss/aspect-ratio": "^0.2.1",
"axios": "^0.27.2",
"core-js": "^3.6.5",
"dayjs": "^1.10.6",
"nuxt": "^2.15.3",
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 @@ -184,6 +184,19 @@ export default {
MarkdownRenderer,
RelatedCardCollection,
},
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 {
eventType: '',
Expand Down Expand Up @@ -213,10 +226,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')
await this.$store.dispatch('$getRelatedData', this.data.category)
Expand Down
23 changes: 12 additions & 11 deletions pages/conference/_eventType/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,25 @@ export default {
SpeechCardCollection,
Banner,
},
asyncData({ redirect, params }) {
async asyncData({ redirect, params, payload, store }) {
const eventType = params.eventType
if (!['talks', 'tutorials'].includes(eventType)) {
redirect('/')
}
if (payload && Object.keys(payload).length !== 0)
return { eventType, speechesData: payload }
await store.dispatch('$getSpeechesData', eventType)
const speechesData = store.state.speechesData.map((speech) => ({
...speech,
begin_time: speech.begin_time ? new Date(speech.begin_time) : null,
}))
return {
eventType,
speechesData,
}
},
data() {
return {
eventType: '',
speechesData: [],
checkedCategories: [],
aboutBanner: AboutBanner,
}
Expand Down Expand Up @@ -133,14 +142,6 @@ export default {
return false
},
},
async mounted() {
this.eventType = this.$route.params.eventType
await this.$store.dispatch('$getSpeechesData', this.eventType)
this.speechesData = this.$store.state.speechesData.map((speech) => ({
...speech,
begin_time: speech.begin_time ? new Date(speech.begin_time) : null,
}))
},
methods: {
metaInfo() {
return {
Expand Down
20 changes: 12 additions & 8 deletions pages/conference/keynotes.vue
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,19 @@ export default {
GithubIcon,
TwitterIcon,
},
async asyncData({ store, app, payload }) {
if (payload) return { keynotesData: payload }
await store.dispatch('$getKeynotesData')
const keynotesData = store.state.keynotesData.map((keynote) => ({
...keynote,
id: app.$makeId(),
}))
return {
keynotesData,
}
},
data() {
return {
keynotesData: [],
aboutBanner: AboutBanner,
}
},
Expand All @@ -159,13 +169,7 @@ export default {
}
},
},
async mounted() {
await this.$store.dispatch('$getKeynotesData')
this.keynotesData = this.$store.state.keynotesData.map((keynote) => ({
...keynote,
id: this.$makeId(),
}))
},
methods: {
getKeynoteId(keynote) {
return keynote.speaker.name_en_us
Expand Down
11 changes: 9 additions & 2 deletions pages/conference/schedule.vue
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ export default {
ScheduleEvent,
ScheduleTick,
},
async asyncData({ store, payload }) {
if (payload) return { schedulesData: payload }
await store.dispatch('$getSchedulesData')
const schedulesData = store.state.schedulesData
return { schedulesData }
},
data() {
return {
selectedDayIndex: 0,
Expand All @@ -118,6 +124,7 @@ export default {
},
}
},
computed: {
...mapState(['schedulesData']),
table() {
Expand All @@ -132,8 +139,8 @@ export default {
this.makeRooms()
},
},
async created() {
await this.$store.dispatch('$getSchedulesData')
created() {
this.processData()
},
activated() {
Expand Down
17 changes: 10 additions & 7 deletions pages/events/jobs-gather.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,22 @@ export default {
JobsCardCollection,
JobsPanel,
},
async asyncData({ store, app, payload }) {
if (payload) return { jobsData: payload }
await store.dispatch('$getJobsData')
const jobsData = store.state.jobsData.map((sponsor) => ({
...sponsor,
id: app.$makeId(),
}))
return { jobsData }
},
data() {
return {
selectedSponsor: {},
jobsData: [],
pivot: 0,
}
},
async mounted() {
await this.$store.dispatch('$getJobsData')
this.jobsData = this.$store.state.jobsData.map((sponsor) => ({
...sponsor,
id: this.$makeId(),
}))
mounted() {
this.setSelectedSponsor(this.jobsData[0])
this.setPivot()
},
Expand Down
17 changes: 10 additions & 7 deletions pages/events/jobs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,22 @@ export default {
JobsCardCollection,
JobsPanel,
},
async asyncData({ store, app, payload }) {
if (payload) return { jobsData: payload }
await store.dispatch('$getJobsData')
const jobsData = store.state.jobsData.map((sponsor) => ({
...sponsor,
id: app.$makeId(),
}))
return { jobsData }
},
data() {
return {
selectedSponsor: {},
jobsData: [],
pivot: 0,
}
},
async mounted() {
await this.$store.dispatch('$getJobsData')
this.jobsData = this.$store.state.jobsData.map((sponsor) => ({
...sponsor,
id: this.$makeId(),
}))
mounted() {
this.setSelectedSponsor(this.jobsData[0])
this.setPivot()
},
Expand Down
11 changes: 8 additions & 3 deletions pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,14 @@ export default {
I18nPageWrapper,
Intro,
},
async asyncData({ store, payload }) {
if (payload) return { sponsorsData: payload }
await store.dispatch('$getSponsorsData')
const sponsorsData = store.state.sponsorsData
return {
sponsorsData,
}
},
data() {
return {
isOpened: false,
Expand All @@ -140,9 +148,6 @@ export default {
return true
},
},
created() {
this.$store.dispatch('$getSponsorsData')
},
methods: {
showModal(sponsor) {
this.isOpened = true
Expand Down

0 comments on commit 3afab52

Please sign in to comment.