-
-
Notifications
You must be signed in to change notification settings - Fork 657
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
[v3] Can queryCollectionWithEvent be used as a replacement for serverQueryContent? How should it be imported? #2968
Comments
You can simply use queryCollection with the event as first param: export default defineEventHandler(async (event) => {
const items = await queryCollection(event, 'collectionName').all()
if (!items) {
throw createError({
statusCode: 404,
statusMessage: 'Items not found'
})
}
return items
}) @farnabaz We're lacking types in this case, wrong method definition is used. |
it works now. TypeScript's type error messages misled me. I used Looking forward to your next update! 😊 |
This should be fixed in the latest commit release.
|
@farnabaz I've done these steps but got failure in dev [14:29:31] WARN "#content/server" is imported by "node_modules/.pnpm/@nuxtjs+sitemap@5.3.5_h3@1.13.1_magicast@0.3.5_rollup@4.30.1_vite@6.0.7_@types+node@22.10.5_j_2oyst4ksuidprlez5dr6q7axeu/node_modules/@nuxtjs/sitemap/dist/runtime/nitro/routes/__sitemap__/nuxt-content-urls.js", but could not be resolved – treating it as an external dependency.
✔ Nuxt Nitro server built in 3578 ms nitro 14:29:34
ℹ Vite client warmed up in 5ms 14:29:34
ERROR [worker reload] [worker init] E:/code/nuxt-blog/.nuxt/dev/index.mjs failed 14:29:34
[cause]: Package import specifier "#content/server" is not defined in package E:\code\nuxt-blog\package.json imported from E:\code\nuxt-blog\.nuxt\dev\index.mjs
at importNotDefined (node:internal/modules/esm/resolve:286:10)
at packageImportsResolve (node:internal/modules/esm/resolve:736:9)
at moduleResolve (node:internal/modules/esm/resolve:905:16)
at defaultResolve (node:internal/modules/esm/resolve:1124:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:557:12)
at ModuleLoader.resolve (node:internal/modules/esm/loader:526:25)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:249:38)
at ModuleJob._link (node:internal/modules/esm/module_job:126:49) // server/routes/rss.xml.ts
import { Feed } from 'feed'
const basePath = 'https://blog.xx.cn'
export default defineEventHandler(async (event) => {
setHeader(event, 'content-type', 'text/xml')
const docs = await queryCollection(event, 'blogs').order('date', 'DESC').all()
const feed = new Feed({
title: "Zayn's personal blog site",
description: "Zayn's personal blog site",
id: basePath,
link: basePath,
language: 'zh',
favicon: `${basePath}/favicon.ico`,
copyright: 'MIT',
author: {
name: 'xx',
email: 'xx@gmail.com',
link: basePath,
},
})
// Add the feed items
docs.forEach((doc) => {
feed.addItem({
title: doc.title || '',
id: basePath + doc.path,
link: basePath + doc.path,
description: doc.description,
content: doc.description,
date: new Date(doc.date as string),
})
})
return feed.rss2()
})
|
@DSYZayn Looks like you are using older version of |
In Content v2, serverQueryContent could be used to fetch content.
What should be used in v3?
I found
queryCollectionWithEvent
in the source code.Is it safe to use this API now? How should it be imported?
The text was updated successfully, but these errors were encountered: