From c0abd76e6da39741de434d01c027d03e83d7bc92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ya=C3=ABl=20Guilloux?= Date: Mon, 27 Jun 2022 14:18:20 +0200 Subject: [PATCH 1/2] fix(document-driven): update documentDriven feature --- src/runtime/plugins/documentDriven.ts | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/runtime/plugins/documentDriven.ts b/src/runtime/plugins/documentDriven.ts index 297ff95c2..1beed15f7 100644 --- a/src/runtime/plugins/documentDriven.ts +++ b/src/runtime/plugins/documentDriven.ts @@ -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' @@ -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!') }) } @@ -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}`) }) } ) @@ -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}`) }) } @@ -174,20 +175,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) { @@ -196,8 +191,6 @@ export default defineNuxtPlugin((nuxt) => { // Update values page.value = _page - } else { - page.value = undefined } // Find used layout From 872b2350a18b7ebe6b42ffc9eb50e12e20254f08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ya=C3=ABl=20Guilloux?= Date: Mon, 27 Jun 2022 14:19:49 +0200 Subject: [PATCH 2/2] fix(surround): add surround queries to the fix --- src/runtime/plugins/documentDriven.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/runtime/plugins/documentDriven.ts b/src/runtime/plugins/documentDriven.ts index 1beed15f7..a72a2de5b 100644 --- a/src/runtime/plugins/documentDriven.ts +++ b/src/runtime/plugins/documentDriven.ts @@ -157,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}`) }) }