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

Changes for generating full static site #315

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion components/core/header/HomeIcon.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ export default {

<style scoped>
.core-homeIcon {
@apply text-pink-500 whitespace-nowrap;
@apply text-pink-700;
}
</style>
2 changes: 1 addition & 1 deletion components/core/header/locale-switch/LocaleSwitch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ export default {
@apply font-bold;
}
.core-localeSwitch:hover {
color: #c386ae;
@apply text-pink-700;
}
</style>
4 changes: 2 additions & 2 deletions components/core/header/nav-bar/NavBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,11 @@ export default {
}

.core-navBarItem:hover {
@apply text-pink-500;
@apply text-pink-700;
}

.core-navBarItem.--active,
.core-navBarItem.--active .options-menu {
@apply text-pink-500;
@apply text-pink-700;
}
</style>
61 changes: 60 additions & 1 deletion 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 = '/2022/'
const DEFAULT_BUILD_TARGET = 'static'
Expand All @@ -11,7 +13,64 @@ export default {
},
// Target (https://go.nuxtjs.dev/config-target)
target: process.env.BUILD_TARGET || DEFAULT_BUILD_TARGET,

generate: {
dir: DEFAULT_ROUTER_BASE.replace(/\/+/g, ''),
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.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,
Expand Down
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
22 changes: 13 additions & 9 deletions pages/conference/_eventType/_id.vue
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,6 @@
</template>

<script>
import { mapState } from 'vuex'

import i18n from '@/i18n/conference/speeches.i18n'

import I18nPageWrapper from '@/components/core/i18n/PageWrapper'
Expand Down Expand Up @@ -184,6 +182,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,
Comment on lines +192 to +193
Copy link
Contributor

@yungshenglu yungshenglu Jan 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eventType: params?.eventType,
eventId: params?.id,

})
const speechData = store.state.speechData
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

store.state?.speechData

return { speechData }
},
data() {
return {
eventType: '',
Expand All @@ -209,14 +220,7 @@ export default {
},
}
},
computed: {
...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
21 changes: 10 additions & 11 deletions pages/conference/_eventType/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,23 @@ export default {
SpeechCardCollection,
Banner,
},
asyncData({ redirect, params }) {
async asyncData({ redirect, params, store }) {
const eventType = params.eventType
if (!['talks', 'tutorials'].includes(eventType)) {
redirect('/')
}
await store.dispatch('$getSpeechesData', eventType)
const speechesData = store.state.speechesData.map((speech) => ({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const speechesData = store.state?.speechesData.map((speech) => ({

...speech,
begin_time: speech.begin_time ? new Date(speech.begin_time) : null,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

speech?.begin_time

}))
return {
speechesData,
eventType,
}
},
data() {
return {
eventType: '',
speechesData: [],
checkedCategories: [],
aboutBanner: AboutBanner,
}
Expand Down Expand Up @@ -133,14 +140,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
18 changes: 11 additions & 7 deletions pages/conference/keynotes.vue
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,17 @@ export default {
GithubIcon,
TwitterIcon,
},
async asyncData({ store, app }) {
await store.dispatch('$getKeynotesData')

const keynotesData = store.state.keynotesData.map((keynote) => ({
Copy link
Contributor

@yungshenglu yungshenglu Jan 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const keynotesData = store.state?.keynotesData.map((keynote) => ({

...keynote,
id: app.$makeId(),
}))
return {
keynotesData,
}
},
data() {
return {
keynotesData: [],
Expand All @@ -159,13 +170,6 @@ 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
17 changes: 11 additions & 6 deletions pages/events/jobs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,24 @@ export default {
JobsCardCollection,
JobsPanel,
},
async asyncData({ store, app }) {
await store.dispatch('$getJobsData')
const jobsData = store.state.jobsData.map((sponsor) => ({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
12 changes: 7 additions & 5 deletions pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@
</template>

<script>
import { mapState } from 'vuex'
import i18n from '@/i18n/index.i18n'
import I18nPageWrapper from '@/components/core/i18n/PageWrapper'
import TextButton from '~/components/core/buttons/TextButton'
Expand All @@ -120,6 +119,13 @@ export default {
I18nPageWrapper,
Intro,
},
async asyncData({ store }) {
await store.dispatch('$getSponsorsData')
const sponsorsData = store.state.sponsorsData
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const sponsorsData = store.state?.sponsorsData

return {
sponsorsData,
}
},
data() {
return {
isOpened: false,
Expand All @@ -129,7 +135,6 @@ export default {
},
fetchOnServer: false,
computed: {
...mapState(['sponsorsData']),
isBulleted() {
if (process.client) {
const width = window.innerWidth
Expand All @@ -140,9 +145,6 @@ export default {
return true
},
},
created() {
this.$store.dispatch('$getSponsorsData')
},
methods: {
showModal(sponsor) {
this.isOpened = true
Expand Down
10 changes: 7 additions & 3 deletions static/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.