Skip to content

Commit

Permalink
fix: support components/content in layers for extends (#1404)
Browse files Browse the repository at this point in the history
  • Loading branch information
Atinux committed Aug 2, 2022
1 parent 83b72d6 commit f439178
Showing 1 changed file with 23 additions and 20 deletions.
43 changes: 23 additions & 20 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,27 +346,30 @@ export default defineNuxtModule<ModuleOptions>({
})

// Register user global components
const globalComponents = resolve(nuxt.options.srcDir, 'components/content')
const dirStat = await fs.promises.stat(globalComponents).catch(() => null)
if (dirStat && dirStat.isDirectory()) {
logger.success('Using `~/components/content` for components in Markdown')
nuxt.hook('components:dirs', (dirs) => {
// Unshift to make it before ~/components
dirs.unshift({
path: globalComponents,
global: true,
pathPrefix: false,
prefix: ''
for (const layer of nuxt.options._layers) {
const srcDir = layer.config.srcDir
const globalComponents = resolve(srcDir, 'components/content')
const dirStat = await fs.promises.stat(globalComponents).catch(() => null)
if (dirStat && dirStat.isDirectory()) {
if (nuxt.options._layers.length === 1) {
logger.success('Using `~/components/content` for components in Markdown')
}
nuxt.hook('components:dirs', (dirs) => {
dirs.unshift({
path: globalComponents,
global: true,
pathPrefix: false,
prefix: ''
})
})
})
} else {
const componentsDir = resolve(nuxt.options.srcDir, 'components/')
const componentsDirStat = await fs.promises.stat(componentsDir).catch(() => null)

if (componentsDirStat && componentsDirStat.isDirectory()) {
// TODO: watch for file creation and tell Nuxt to restart
// Not possible for now since directories are hard-coded: https://github.com/nuxt/framework/blob/5b63ae8ad54eeb3cb49479da8f32eacc1a743ca0/packages/nuxi/src/commands/dev.ts#L94
logger.info('Please create `~/components/content` and restart the Nuxt server to use components in Markdown')
} else if (nuxt.options._layers.length === 1) {
const componentsDir = resolve(srcDir, 'components/')
const componentsDirStat = await fs.promises.stat(componentsDir).catch(() => null)
if (componentsDirStat && componentsDirStat.isDirectory()) {
// TODO: watch for file creation and tell Nuxt to restart
// Not possible for now since directories are hard-coded: https://github.com/nuxt/framework/blob/5b63ae8ad54eeb3cb49479da8f32eacc1a743ca0/packages/nuxi/src/commands/dev.ts#L94
logger.info('Please create `~/components/content` and restart the Nuxt server to use components in Markdown')
}
}
}

Expand Down

0 comments on commit f439178

Please sign in to comment.