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

feat: advanced query schema #2213

Merged
merged 10 commits into from
Aug 3, 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
2 changes: 1 addition & 1 deletion docs/components/content/ChangeLog.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div>
<GithubReleases v-slot="{releases}">
<GithubReleases v-slot="{ releases }">
<div v-for="release in releases" :key="release.name" class="release">
<div class="release-name">
<h2 class="">
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
},
"dependencies": {
"@nuxt/kit": "^3.6.5",
"@vueuse/head": "^1.1.26",
"consola": "^3.2.3",
"defu": "^6.1.2",
"destr": "^2.0.0",
Expand Down
4 changes: 3 additions & 1 deletion playground/shared/components/NavItem.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<script setup lang="ts">
import type { NavItem } from '../../../src/runtime/types'

const props = defineProps<{
navItem: any
navItem: NavItem
}>()
const icon = computed(() => {
if (props.navItem.icon) { return props.navItem.icon }
Expand Down
6 changes: 1 addition & 5 deletions playground/shared/components/content/MarkdownBetween.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
<template>
<ContentSlot :use="$slots.default" unwrap="ul li">
<template #between>
<br>
</template>
</ContentSlot>
<ContentSlot :use="$slots.default" unwrap="ul li" />
</template>
76 changes: 24 additions & 52 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 14 additions & 5 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ export interface ModuleOptions {
experimental: {
clientDB: boolean
stripQueryParameters: boolean
advanceQuery: boolean
}
}

Expand Down Expand Up @@ -293,7 +294,8 @@ export default defineNuxtModule<ModuleOptions>({
respectPathCase: false,
experimental: {
clientDB: false,
stripQueryParameters: false
stripQueryParameters: false,
advanceQuery: false
}
},
async setup (options, nuxt) {
Expand Down Expand Up @@ -328,6 +330,7 @@ export default defineNuxtModule<ModuleOptions>({
if (code.includes('<ContentSlot')) {
code = code.replace(/<ContentSlot (.*)(:use=['"](\$slots.)?([a-z]*)['"]|use=['"]([a-z]*)['"])/g, '<MDCSlot $1 name="$4"')
code = code.replace(/<\/ContentSlot>/g, '</MDCSlot>')
code = code.replace(/<ContentSlot/g, '<MDCSlot')
return code
}
}
Expand Down Expand Up @@ -421,7 +424,7 @@ export default defineNuxtModule<ModuleOptions>({

// Register composables
addImports([
{ name: 'queryContent', as: 'queryContent', from: resolveRuntimeModule('./composables/query') },
{ name: 'queryContent', as: 'queryContent', from: resolveRuntimeModule(`./${options.experimental.advanceQuery ? '' : 'legacy/'}composables/query`) },
{ name: 'useContentHelpers', as: 'useContentHelpers', from: resolveRuntimeModule('./composables/helpers') },
{ name: 'useContentHead', as: 'useContentHead', from: resolveRuntimeModule('./composables/head') },
{ name: 'useContentPreview', as: 'useContentPreview', from: resolveRuntimeModule('./composables/preview') },
Expand Down Expand Up @@ -475,7 +478,7 @@ export default defineNuxtModule<ModuleOptions>({
filename: 'types/content.d.ts',
getContents: () => [
'declare module \'#content/server\' {',
` const serverQueryContent: typeof import('${resolve('./runtime/server')}').serverQueryContent`,
` const serverQueryContent: typeof import('${resolve(options.experimental.advanceQuery ? './runtime/server' : './runtime/legacy/types')}').serverQueryContent`,
` const parseContent: typeof import('${resolve('./runtime/server')}').parseContent`,
'}'
].join('\n')
Expand Down Expand Up @@ -562,7 +565,11 @@ export default defineNuxtModule<ModuleOptions>({
{ name: 'useContent', as: 'useContent', from: resolveRuntimeModule('./composables/content') }
])

addPlugin(resolveRuntimeModule('./plugins/documentDriven'))
addPlugin(resolveRuntimeModule(
options.experimental.advanceQuery
? './plugins/documentDriven'
: './legacy/plugins/documentDriven'
))

if (options.documentDriven.injectPage) {
nuxt.options.pages = true
Expand Down Expand Up @@ -631,6 +638,7 @@ export default defineNuxtModule<ModuleOptions>({
integrity: buildIntegrity,
experimental: {
stripQueryParameters: options.experimental.stripQueryParameters,
advanceQuery: options.experimental.advanceQuery === true,
clientDB: options.experimental.clientDB && nuxt.options.ssr === false
},
respectPathCase: options.respectPathCase ?? false,
Expand Down Expand Up @@ -700,7 +708,7 @@ export default defineNuxtModule<ModuleOptions>({
return true
})
await Promise.all(
keys.map(async key => await storage.setItem(
keys.map(async (key: string) => await storage.setItem(
`cache:content:parsed:${key.substring(15)}`,
await storage.getItem(key)
))
Expand Down Expand Up @@ -757,6 +765,7 @@ interface ModulePublicRuntimeConfig {
experimental: {
stripQueryParameters: boolean
clientDB: boolean
advanceQuery: boolean
}
respectPathCase: boolean

Expand Down