-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
214 lines (202 loc) · 5.6 KB
/
index.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
import path from 'path'
import defu from 'defu'
import gracefulFs from 'graceful-fs'
import tailwindConfig from './tailwind.config'
const fs = gracefulFs.promises
function themeModule () {
// wait for nuxt options to be normalized
const { nuxt } = this
const { options, hook } = this.nuxt
// Configure `content/` dir
options.content.dir = path.resolve(options.rootDir, options.content.dir || 'content')
// Configure `static/ dir
options.dir.static = path.resolve(options.rootDir, options.dir.static || 'static')
// Configure `components/` dir
hook('components:dirs', async (dirs) => {
const componentsDirPath = path.resolve(nuxt.options.rootDir, 'components')
const componentsDirStat = await fs.stat(componentsDirPath).catch(() => null)
if (componentsDirStat && componentsDirStat.isDirectory()) {
dirs.push({
path: componentsDirPath
})
} else {
nuxt.options.watch.push(componentsDirPath)
}
const globalComponentsDirPath = path.resolve(nuxt.options.rootDir, 'components/global')
const globalComponentsDirStat = await fs.stat(globalComponentsDirPath).catch(() => null)
if (globalComponentsDirStat && globalComponentsDirStat.isDirectory()) {
dirs.push({
path: globalComponentsDirPath,
global: true
});
dirs.push({
path: path.resolve(globalComponentsDirPath, 'app'),
global: true
});
dirs.push({
path: path.resolve(globalComponentsDirPath, 'base'),
global: true
});
dirs.push({
path: path.resolve(globalComponentsDirPath, 'icons'),
global: true
});
} else {
nuxt.options.watch.push(globalComponentsDirPath)
}
})
// Configure content after each hook
hook('content:file:beforeInsert', (document) => {
const regexp = new RegExp(`^/(${options.i18n.locales.map(locale => locale.code).join('|')})`, 'gi')
const { dir, slug, category } = document
const _dir = dir.replace(regexp, '')
const _slug = slug.replace(/^index/, '')
const _category = category && typeof category === 'string' ? category : ''
document.to = `${_dir}/${_slug}`
document.category = _category
})
// Extend `/` route
hook('build:extendRoutes', (routes) => {
const allRoute = routes.find(route => route.name === 'all')
routes.push({
...allRoute,
path: '/',
name: 'index'
})
})
// Override editor style on dev mode
if (options.dev) {
options.css.push(path.resolve(__dirname, 'assets/css/main.dev.css'))
}
// Configure `tailwind.config.js` path
options.tailwindcss.configPath = options.tailwindcss.configPath || path.resolve(options.rootDir, 'tailwind.config.js')
options.tailwindcss.cssPath = options.tailwindcss.cssPath || path.resolve(options.rootDir, options.dir.assets, 'css', 'tailwind.css')
// Configure TailwindCSS
hook('tailwindcss:config', function (defaultTailwindConfig) {
Object.assign(defaultTailwindConfig, defu(defaultTailwindConfig, tailwindConfig({ nuxt })))
})
}
const defaultConfig = docsOptions => ({
target: 'static',
ssr: true,
srcDir: __dirname,
privateRuntimeConfig: {
githubToken: process.env.GITHUB_TOKEN
},
head: {
meta: [
{ title: 'Sevrerless Devs' },
{ charset: 'utf-8' },
{ name: 'viewport', content: 'width=device-width, initial-scale=1' }
],
link: [
{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }
]
},
generate: {
fallback: '404.html',
routes: ['/']
},
transpile: [
__dirname // transpile node_modules/@nuxt/content-theme-docs
],
css: [
'~/assets/css/main.css'
],
plugins: [
'@/plugins/markdown',
'@/plugins/init',
'@/plugins/i18n.client',
'@/plugins/vue-scrollactive',
'@/plugins/menu.client',
'@/plugins/element-ui',
'@/plugins/nav',
],
buildModules: [
themeModule,
'@nuxtjs/tailwindcss',
'@nuxtjs/color-mode',
'@nuxtjs/pwa',
'@nuxtjs/google-fonts'
],
modules: [
'nuxt-i18n',
'@nuxt/content'
],
components: [
{ path: '~/components', pathPrefix: false, level: 1 }
],
loading: {
color: docsOptions.primaryColor
},
meta: {
theme_color: docsOptions.primaryColor
},
content: {
markdown: {
prism: {
theme: 'prism-themes/themes/prism-material-oceanic.css'
}
}
},
i18n: {
locales: [{
code: 'en',
iso: 'en-US',
file: 'en-US.js',
name: 'English'
}],
defaultLocale: 'en',
parsePages: false,
lazy: true,
seo: false,
langDir: 'i18n/',
vueI18n: {
fallbackLocale: 'en',
dateTimeFormats: {
en: {
long: {
year: 'numeric',
month: 'short',
day: 'numeric',
weekday: 'short'
}
},
fr: {
long: {
year: 'numeric',
month: 'long',
day: 'numeric',
weekday: 'short'
}
}
}
}
},
googleFonts: {
families: {
'DM+Sans': true,
'DM+Mono': true
}
},
tailwindcss: {},
build: {
postcss: {
plugins: {
}
}
}
})
export default (userConfig) => {
userConfig.docs = defu(userConfig.docs, {
primaryColor: '#1b58f4'
})
const config = defu.arrayFn(userConfig, defaultConfig(userConfig.docs))
if (userConfig.env && userConfig.env.GITHUB_TOKEN) {
// eslint-disable-next-line no-console
console.warn('[security] Avoid passing `env.GITHUB_TOKEN` directly in `nuxt.config`. Use `.env` file instead!')
userConfig.privateRuntimeConfig.GITHUB_TOKEN = userConfig.env.GITHUB_TOKEN
delete userConfig.env.GITHUB_TOKEN
}
return config
}