-
Notifications
You must be signed in to change notification settings - Fork 36
/
nuxt.config.js
251 lines (232 loc) Β· 8.1 KB
/
nuxt.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
import axios from 'axios'
const DEFAULT_BASE_URL = 'https://tw.pycon.org/prs'
const DEFAULT_ROUTER_BASE = '/2024/'
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,
)
.catch((error) => { // eslint-disable-line
return { data: [] }
})
const tutorials = await axios
.get(
`${DEFAULT_BASE_URL}/api/events/speeches/?event_types=tutorial`,
config,
)
.catch((error) => { // eslint-disable-line
return { data: [] }
})
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,
},
},
// Target (https://go.nuxtjs.dev/config-target)
target: process.env.BUILD_TARGET || DEFAULT_BUILD_TARGET,
// Re-route for GitHub Pages to serve with /assets
router: {
base: process.env.ROUTER_BASE || DEFAULT_ROUTER_BASE,
// scroll behavior config for scroll to hash
// https://nuxtjs.org/docs/2.x/configuration-glossary/configuration-router#scrollbehavior
// https://stackoverflow.com/questions/60952725/anchor-in-nuxt-component-not-working-on-same-page-the-anchor-is-included-on
async scrollBehavior(to, from, savedPosition) {
if (savedPosition) {
return savedPosition
}
const findEl = (hash, x = 0) => {
return (
document.querySelector(hash) ||
new Promise((resolve) => {
if (x > 50) {
return resolve(document.querySelector('#app'))
}
setTimeout(() => {
resolve(findEl(hash, ++x || 1))
}, 100)
})
)
}
if (to.hash) {
const el = await findEl(to.hash)
if ('scrollBehavior' in document.documentElement.style) {
return window.scrollTo({
top: el.offsetTop,
behavior: 'smooth',
})
} else {
return window.scrollTo(0, el.offsetTop)
}
}
return { x: 0, y: 0 }
},
},
// Global page headers (https://go.nuxtjs.dev/config-head)
// Move to layout/default.vue due to gtm-module not support head function (https://github.com/nuxt-community/gtm-module/issues/56)
head: {},
// Global CSS (https://go.nuxtjs.dev/config-css)
css: [],
// Plugins to run before rendering page (https://go.nuxtjs.dev/config-plugins)
plugins: [
{ src: '~/plugins/iterator.js' },
{ src: '~/plugins/http.js' },
{ src: '~/plugins/strings.js' },
{ src: '~/plugins/vue-dompurify.js' },
{ src: '~/plugins/vue-awesome-swiper.js' },
],
// Auto import components (https://go.nuxtjs.dev/config-components)
components: [{ path: '~/components/', extensions: ['vue'] }],
// Modules for dev and build (recommended) (https://go.nuxtjs.dev/config-modules)
buildModules: [
// https://go.nuxtjs.dev/eslint
'@nuxtjs/eslint-module',
// https://go.nuxtjs.dev/tailwindcss
'@nuxtjs/tailwindcss',
// https://github.com/nuxt-community/dotenv-module
'@nuxtjs/dotenv',
[
'@nuxtjs/router',
{
path: 'configs',
keepDefaultRouter: true,
},
],
],
// Modules (https://go.nuxtjs.dev/config-modules)
modules: [
// https://go.nuxtjs.dev/axios
'@nuxt/http',
// https://github.com/nuxt-community/gtm-module
'@nuxtjs/gtm',
// https://github.com/WilliamDASILVA/nuxt-facebook-pixel-module
'nuxt-facebook-pixel-module',
// https://i18n.nuxtjs.org/
'@nuxtjs/i18n',
[
'nuxt-fontawesome',
{
component: 'fa',
imports: [
{
set: '@fortawesome/free-brands-svg-icons',
icons: ['fab'],
},
{
set: '@fortawesome/free-solid-svg-icons',
icons: ['fas'],
},
{
set: '@fortawesome/free-regular-svg-icons',
icons: ['far'],
},
],
},
],
// https://github.com/nuxt-community/markdownit-module
'@nuxtjs/markdownit',
// https://sitemap.nuxtjs.org/
// This module must be at the end of the modules array
'@nuxtjs/sitemap',
// https://github.com/schlunsen/nuxt-leaflet
'nuxt-leaflet',
],
i18n: {
strategy: 'prefix',
locale: 'en-us',
defaultLocale: 'en-us',
fallbackLocale: 'en-us',
locales: ['en-us', 'zh-hant'],
detectBrowserLanguage: {
redirectOn: 'root',
},
},
// http module configuration (https://http.nuxtjs.org/options)
http: {
baseURL: process.env.BASE_URL || DEFAULT_BASE_URL,
},
// Build Configuration (https://go.nuxtjs.dev/config-build)
build: {},
gtm: {
id: process.env.GOOGLE_TAG_MANAGER_ID,
},
facebook: {
track: 'PageView',
pixelId: '164677453055289',
autoPageView: true,
disabled: false,
},
markdownit: {
runtime: true,
html: true,
preset: 'default',
linkify: true,
breaks: true,
},
sitemap: {
hostname: 'https://tw.pycon.org/',
defaults: {
priority: 1.0, // suggestion: decrease priority before archiving
},
gzip: true,
i18n: true,
exclude: [
'**/ext/**', // exclude pages only for attendees
],
},
publicRuntimeConfig: {
gtm: {
id: process.env.GOOGLE_TAG_MANAGER_ID,
},
},
}