Skip to content

Commit 1c84288

Browse files
benjamincanacpi0atinux
authored
fix(theme-docs): prevent warning when global components missing (#542)
Co-authored-by: pooya parsa <[email protected]> Co-authored-by: Sébastien Chopin <[email protected]>
1 parent 57bdb16 commit 1c84288

File tree

7 files changed

+45
-14
lines changed

7 files changed

+45
-14
lines changed

packages/theme-docs/src/components/app/AppFooter.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
<BuiltWithNuxtDark class="h-4 dark-img" />
88
</a>
99
</div>
10-
<div class="flex">
10+
<div class="flex items-center space-x-4">
1111
<AppLangSwitcher />
12-
<AppColorSwitcher class="ml-4" />
12+
<AppColorSwitcher />
1313
</div>
1414
</div>
1515
</footer>

packages/theme-docs/src/components/app/AppNav.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,17 @@
3838
</li>
3939
</ul>
4040
</li>
41-
<li class="lg:hidden">
41+
<li class="lg:hidden space-x-2">
4242
<p class="mb-2 text-gray-500 uppercase tracking-wider font-bold text-sm lg:text-xs">More</p>
43-
<div class="flex items-center ml-2">
43+
<div class="flex items-center space-x-4">
4444
<a
4545
v-if="settings.twitter"
4646
:href="`https://twitter.com/${settings.twitter}`"
4747
target="_blank"
4848
rel="noopener noreferrer"
4949
title="Twitter"
5050
name="Twitter"
51-
class="inline-flex text-gray-700 dark:text-gray-300 hover:text-primary-500 mr-4"
51+
class="inline-flex text-gray-700 dark:text-gray-300 hover:text-primary-500"
5252
>
5353
<IconTwitter class="w-5 h-5" />
5454
</a>
@@ -59,12 +59,12 @@
5959
rel="noopener noreferrer"
6060
title="Github"
6161
name="Github"
62-
class="inline-flex text-gray-700 dark:text-gray-300 hover:text-primary-500 mr-4"
62+
class="inline-flex text-gray-700 dark:text-gray-300 hover:text-primary-500"
6363
>
6464
<IconGithub class="w-5 h-5" />
6565
</a>
6666

67-
<AppLangSwitcher class="mr-4" />
67+
<AppLangSwitcher />
6868
<AppColorSwitcher />
6969
</div>
7070
</li>

packages/theme-docs/src/index.js

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import path from 'path'
22
import defu from 'defu'
3+
import gracefulFs from 'graceful-fs'
34

45
import tailwindConfig from './tailwind.config'
56

7+
const fs = gracefulFs.promises
8+
69
function themeModule () {
710
// wait for nuxt options to be normalized
811
const { nuxt } = this
@@ -13,11 +16,27 @@ function themeModule () {
1316
// Configure `static/ dir
1417
options.dir.static = path.resolve(options.rootDir, options.dir.static || 'static')
1518
// Configure `components/` dir
16-
hook('components:dirs', (dirs) => {
17-
dirs.push({
18-
path: path.resolve(options.rootDir, 'components/global'),
19-
global: true
20-
})
19+
hook('components:dirs', async (dirs) => {
20+
const componentsDirPath = path.resolve(nuxt.options.rootDir, 'components')
21+
const componentsDirStat = await fs.stat(componentsDirPath).catch(() => null)
22+
if (componentsDirStat && componentsDirStat.isDirectory()) {
23+
dirs.push({
24+
path: componentsDirPath
25+
})
26+
} else {
27+
nuxt.options.watch.push(componentsDirPath)
28+
}
29+
30+
const globalComponentsDirPath = path.resolve(nuxt.options.rootDir, 'components/global')
31+
const globalComponentsDirStat = await fs.stat(globalComponentsDirPath).catch(() => null)
32+
if (globalComponentsDirStat && globalComponentsDirStat.isDirectory()) {
33+
dirs.push({
34+
path: globalComponentsDirPath,
35+
global: true
36+
})
37+
} else {
38+
nuxt.options.watch.push(globalComponentsDirPath)
39+
}
2140
})
2241
// Configure content after each hook
2342
hook('content:file:beforeInsert', (document) => {

packages/theme-docs/src/pages/_.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,14 @@
2020
<div v-if="document.subtitle" class="-mt-4">
2121
<p class="text-gray-600 dark:text-gray-400">{{ document.subtitle }}</p>
2222
</div>
23+
2324
<NuxtContent :document="document" />
2425
</article>
26+
2527
<AppGithubLink :document="document" />
2628
<AppPrevNext :prev="prev" :next="next" />
2729
</div>
30+
2831
<AppToc v-if="!document.fullscreen" :toc="document.toc" />
2932
</div>
3033
</template>

packages/theme-docs/src/pages/releases.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
</div>
2727
</article>
2828
</div>
29+
2930
<AppToc :toc="toc" />
3031
</div>
3132
</template>

packages/theme-docs/src/store/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Vue from 'vue'
22
import groupBy from 'lodash.groupby'
3+
import defu from 'defu'
34

45
export const state = () => ({
56
categories: {},
@@ -60,7 +61,7 @@ export const mutations = {
6061
state.settings.defaultBranch = branch
6162
},
6263
SET_SETTINGS (state, settings) {
63-
state.settings = Object.assign({}, state.settings, settings, { filled: true })
64+
state.settings = defu({ filled: true }, settings, state.settings)
6465
if (!state.settings.url) {
6566
console.warn('Please provide the `url` property in `content/setting.json`')
6667
}
@@ -143,7 +144,8 @@ export const actions = {
143144
},
144145
async fetchSettings ({ commit }) {
145146
try {
146-
const settings = await this.$content('settings').fetch()
147+
const { dir, extension, path, slug, to, createdAt, updatedAt, ...settings } = await this.$content('settings').fetch()
148+
147149
commit('SET_SETTINGS', settings)
148150
} catch (e) {
149151
// eslint-disable-next-line no-console

packages/theme-docs/src/tailwind.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ module.exports = ({ nuxt }) => ({
8383
},
8484
'pre code': {
8585
fontFamily: 'DM Mono'
86+
},
87+
'a code': {
88+
color: theme('colors.primary.500')
8689
}
8790
}
8891
},
@@ -133,6 +136,9 @@ module.exports = ({ nuxt }) => ({
133136
backgroundColor: theme('colors.gray.800'),
134137
borderWidth: 0
135138
},
139+
'a code': {
140+
color: theme('colors.primary.500')
141+
},
136142
thead: {
137143
color: theme('colors.gray.100'),
138144
borderBottomColor: theme('colors.gray.600')

0 commit comments

Comments
 (0)