Skip to content

Commit

Permalink
fix(document-driven): update documentDriven feature (#1294)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tahul authored Jun 27, 2022
1 parent fe1ebb5 commit cfd8782
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions src/runtime/plugins/documentDriven.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { RouteLocationNormalized, RouteLocationNormalizedLoaded } from 'vue-router'
// @ts-ignore
import { useRuntimeConfig, addRouteMiddleware } from '#app'
import { withoutTrailingSlash } from 'ufo'
import { NavItem, ParsedContent } from '../types'
// @ts-ignore
import { defineNuxtPlugin, queryContent, useContentHelpers, useContentState, fetchContentNavigation, useRoute } from '#imports'
Expand Down Expand Up @@ -60,7 +61,7 @@ export default defineNuxtPlugin((nuxt) => {
})
.catch((_) => {
// eslint-disable-next-line no-console
console.log('Could not fetch navigation!')
// console.log('Could not fetch navigation!')
})
}

Expand Down Expand Up @@ -94,7 +95,7 @@ export default defineNuxtPlugin((nuxt) => {

return queryContent(query)[type]().catch(() => {
// eslint-disable-next-line no-console
console.log(`Could not find globals key: ${key}`)
// console.log(`Could not find globals key: ${key}`)
})
}
)
Expand Down Expand Up @@ -128,11 +129,11 @@ export default defineNuxtPlugin((nuxt) => {
}

return queryContent()
.where({ _path: to.path })
.where({ _path: withoutTrailingSlash(to.path) })
.findOne()
.catch(() => {
// eslint-disable-next-line no-console
console.log(`Could not find page: ${to.path}`)
// console.log(`Could not find page: ${to.path}`)
})
}

Expand All @@ -156,10 +157,12 @@ export default defineNuxtPlugin((nuxt) => {
})
// Exclude `body` for `surround`
.without(['body'])
.findSurround(to.path)
.findSurround(
withoutTrailingSlash(to.path)
)
.catch(() => {
// eslint-disable-next-line no-console
console.log(`Could not find surrounding pages for: ${to.path}`)
// console.log(`Could not find surrounding pages for: ${to.path}`)
})
}

Expand All @@ -174,20 +177,14 @@ export default defineNuxtPlugin((nuxt) => {
]) => {
if (_navigation) {
navigation.value = _navigation
} else {
navigation.value = []
}

if (_globals) {
globals.value = _globals
} else {
globals.value = {}
}

if (_surround) {
surround.value = _surround
} else {
surround.value = []
}

if (_page) {
Expand All @@ -196,8 +193,6 @@ export default defineNuxtPlugin((nuxt) => {

// Update values
page.value = _page
} else {
page.value = undefined
}

// Find used layout
Expand Down

0 comments on commit cfd8782

Please sign in to comment.