Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(document-driven): page layout detection #1955

Merged
merged 4 commits into from
Mar 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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