Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Next.js 使用pt::text时,sanity algolia获取错误_Next.js_Algolia_Sanity_Groq - Fatal编程技术网

Next.js 使用pt::text时,sanity algolia获取错误

Next.js 使用pt::text时,sanity algolia获取错误,next.js,algolia,sanity,groq,Next.js,Algolia,Sanity,Groq,我正在尝试使用SanityAlgolia库(ref)将algolia搜索与SanityCMS集成 但是当我尝试使用pt::text函数从可移植文本富文本内容中获取纯文本时。 我在对象体之后得到了预期的'}',我真的不知道我在哪里遗漏了一个括号 (另一个注意事项:由于我使用sanitystart托管sanity,因此我使用nextjs(我的前端)来运行函数,而不是使用nextjs中的/api路由),因此sanity有一个指向此路由的webhook 有关错误的详细信息: details: {

我正在尝试使用SanityAlgolia库(ref)将algolia搜索与SanityCMS集成

但是当我尝试使用pt::text函数从可移植文本富文本内容中获取纯文本时。 我在对象体之后得到了
预期的'}',我真的不知道我在哪里遗漏了一个括号

(另一个注意事项:由于我使用
sanitystart
托管sanity,因此我使用nextjs(我的前端)来运行函数,而不是使用nextjs中的/api路由),因此sanity有一个指向此路由的webhook

有关错误的详细信息:

  details: {
    description: "expected '}' following object body",
    end: 174,
    query: '* [(_id in $created || _id in $updated) && _type in $types] {\n' +
      '  _id,\n' +
      '  _type,\n' +
      '  _rev,\n' +
      '  _type == "post" => {\n' +
      '        title,\n' +
      '        "path": slug.current,\n' +
      '        "body": pt::text(body)\n' +
      '      }\n' +
      '}',
    start: 107,
    type: 'queryParseError'
  }
这是我正在运行的无服务器功能:

export default async function handler(req, res) {
  if (req.headers["content-type"] !== "application/json") {
    res.status(400);
    res.json({ message: "Bad request" });
    return;
  }

  const algoliaIndex = algolia.initIndex("dev_kim_miles");

  const sanityAlgolia = indexer(
    {
      post: {
        index: algoliaIndex,
        projection: `{
        title,
        "path": slug.current,
        "body": pt::text(body)
      }`,
      },
    },
    (document) => {
      console.log(document);
      return document;
    },
    (document) => {
      if (document.hasOwnProperty("isHidden")) {
        return !document.isHidden;
      }
      return true;
    }
  );
  return sanityAlgolia
    .webhookSync(sanityClient, req.body)
    .then(() => res.status(200).send("ok"));
}
以及我在sanity的帖子模式:

export default {
  name: 'post',
  title: 'Post',
  type: 'document',
  fields: [
    {
      name: 'title',
      title: 'Title',
      type: 'string',
    },
    {
      name: 'slug',
      title: 'Slug',
      type: 'slug',
      options: {
        source: 'title',
        maxLength: 96,
      },
    },
    {
      name: 'author',
      title: 'Author',
      type: 'reference',
      to: {type: 'author'},
    },
    {
      name: 'mainImage',
      title: 'Main image',
      type: 'image',
      options: {
        hotspot: true,
      },
    },
    {
      name: 'categories',
      title: 'Categories',
      type: 'array',
      of: [{type: 'reference', to: {type: 'category'}}],
    },
    {
      name: 'publishedAt',
      title: 'Published at',
      type: 'datetime',
    },
    {
      name: 'body',
      title: 'Body',
      type: 'blockContent',
    },
    {
      name: 'extra',
      title: 'extra',
      type: 'blockContent',
    },
  ],

  preview: {
    select: {
      title: 'title',
      author: 'author.name',
      media: 'mainImage',
    },
    prepare(selection) {
      const {author} = selection
      return Object.assign({}, selection, {
        subtitle: author && `by ${author}`,
      })
    },
  },
}

SanityAPI v1不适用于函数,我使用的是

const sanityClient = client({
  dataset: "production",
  useCdn: true,
  projectId: "project_id",
});
默认为v1,但为了使用函数,我添加了一个apiVersion参数,使其使用更高版本的api:

const sanityClient = client({
  dataset: "production",
  useCdn: true,
  projectId: "9dz8b3g1",
  apiVersion: "2021-03-25",
});