Skip to content

Commit

Permalink
fix(document-driven): page layout detection (#1955)
Browse files Browse the repository at this point in the history
Co-authored-by: Sébastien Chopin <seb@nuxt.com>
Co-authored-by: Sébastien Chopin <seb@nuxtjs.com>
  • Loading branch information
3 people committed Mar 8, 2023
1 parent 45b44a6 commit b92d18a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/runtime/composables/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const navBottomLink = (link: NavItem): string | undefined => {
*/
const navDirFromPath = (path: string, tree: NavItem[]): NavItem[] | undefined => {
for (const file of tree) {
if (file._path === path && !file._id) { return file.children }
if (file._path === path && !file._id) { return tree }

if (file.children) {
const result = navDirFromPath(path, file.children)
Expand All @@ -41,13 +41,17 @@ const navPageFromPath = (path: string, tree: NavItem[]): NavItem | undefined =>
}

/**
* Find a nav field node from a path.
* Find a navigation field node from a path.
*/
const navKeyFromPath = (path: string, key: string, tree: NavItem[]) => {
let value: any

const goDeep = (path: string, tree: NavItem[]) => {
for (const file of tree) {
if (path !== '/' && file._path === '/') {
// Ignore root page
continue
}
if (path?.startsWith(file._path) && file[key]) { value = file[key] }

if (file._path === path) { return }
Expand Down
5 changes: 4 additions & 1 deletion src/runtime/composables/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const addPrerenderPath = (path: string) => {

export const shouldUseClientDB = () => {
const { experimental } = useRuntimeConfig().content
if (!process.client) { return false }
if (process.server) { return false }
if (experimental.clientDB) { return true }

const query = useRoute().query
Expand All @@ -55,6 +55,9 @@ export const shouldUseClientDB = () => {
}
// Enable clientDB when preview mode is enabled
if (query.preview || useCookie('previewToken').value) {
if (process.dev) {
console.warn('[content] Client DB enabled since a preview token is set (either in query or cookie).')
}
return true
}

Expand Down

0 comments on commit b92d18a

Please sign in to comment.