skip to content
菜鸟文档

Astro 博客问题记录

/ 3 min read

问题列表

修改frontmatter的description之后,vercal build失败

错误日志如下:

 error   post → my-first-blog.md frontmatter does not match collection schema.
  description: String must contain at least 50 character(s)
  Hint:
    See  https://docs.astro.build/en/guides/content-collections/  for more information on content schemas.
  Error reference:
    https://docs.astro.build/en/reference/errors/invalid-content-entry-frontmatter-error/
  File:
    /vercel/path0/src/content/post/my-first-blog.md?astroContentCollectionEntry=true
  Code:
    2 | title: "我的第一篇博客"
    > 3 | description: "我的第一篇博客"
        | ^
      4 | publishDate: "16 Sept 2023"
      5 | tags: ["随笔"]
      6 | draft: true
  Stacktrace:
InvalidContentEntryFrontmatterError: **post → my-first-blog.md** frontmatter does not match collection schema.

错误还是很清晰的,修改src/content/config.ts即可

const post = defineCollection({
	type: "content",
	schema: ({ image }) =>
		z.object({
			title: z.string().max(60),
			description: z.string().min(50).max(160),
			publishDate: z
				.string()
				.or(z.date())
				.transform((val) => new Date(val)),
			updatedDate: z
				.string()
				.optional()
				.transform((str) => (str ? new Date(str) : undefined)),
			coverImage: z
				.object({
					src: image(),
					alt: z.string(),
				})
				.optional(),
			draft: z.boolean().default(false),
			tags: z.array(z.string()).default([]).transform(removeDupsAndLowerCase),
			ogImage: z.string().optional(),
		}),
});

slug解析失败

问题:

 error   Expected "slug" to match "[^\/#\?]+?", but got "problem-log/astro-blog-probs"
  File:
    /vercel/path0/node_modules/.pnpm/path-to-regexp@6.2.1/node_modules/path-to-regexp/dist/index.js:229:27
  Code:
    228 |                 if (validate && !matches[i].test(segment)) {
    > 229 |                     throw new TypeError("Expected \"".concat(token.name, "\" to match \"").concat(token.pattern, "\", but got \"").concat(segment, "\""));
          |                           ^
      230 |                 }
      231 |                 path += token.prefix + segment + token.suffix;
      232 |                 continue;
  Stacktrace:
TypeError: Expected "slug" to match "[^\/#\?]+?", but got "problem-log/astro-blog-probs"
    at Object.generate (/vercel/path0/node_modules/.pnpm/path-to-regexp@6.2.1/node_modules/path-to-regexp/dist/index.js:229:27)
    at stringifyParams (file:///vercel/path0/node_modules/.pnpm/astro@3.0.8/node_modules/astro/dist/core/routing/params.js:26:31)
    at callGetStaticPaths (file:///vercel/path0/node_modules/.pnpm/astro@3.0.8/node_modules/astro/dist/core/render/route-cache.js:37:23)
    at async getPathsForRoute (file:///vercel/path0/node_modules/.pnpm/astro@3.0.8/node_modules/astro/dist/core/build/generate.js:250:25)
    at async generatePage (file:///vercel/path0/node_modules/.pnpm/astro@3.0.8/node_modules/astro/dist/core/build/generate.js:227:17)
    at async generatePages (file:///vercel/path0/node_modules/.pnpm/astro@3.0.8/node_modules/astro/dist/core/build/generate.js:144:9)
    at async staticBuild (file:///vercel/path0/node_modules/.pnpm/astro@3.0.8/node_modules/astro/dist/core/build/static-build.js:85:7)
    at async AstroBuilder.build (file:///vercel/path0/node_modules/.pnpm/astro@3.0.8/node_modules/astro/dist/core/build/index.js:127:5)
    at async AstroBuilder.run (file:///vercel/path0/node_modules/.pnpm/astro@3.0.8/node_modules/astro/dist/core/build/index.js:158:7)
    at async build (file:///vercel/path0/node_modules/.pnpm/astro@3.0.8/node_modules/astro/dist/core/build/index.js:37:3)
    at async build (file:///vercel/path0/node_modules/.pnpm/astro@3.0.8/node_modules/astro/dist/cli/build/index.js:20:3)
    at async runCommand (file:///vercel/path0/node_modules/.pnpm/astro@3.0.8/node_modules/astro/dist/cli/index.js:116:7)
    at async cli (file:///vercel/path0/node_modules/.pnpm/astro@3.0.8/node_modules/astro/dist/cli/index.js:144:5)
 ELIFECYCLE  Command failed with exit code 1.
Error: Command "pnpm run build" exited with 1

todo:待继续看原因 不支持直接获取目录以及目录下的文件

Cannot read properties of undefined (reading ‘depth’)


 error   Cannot read properties of undefined (reading 'depth')
TypeError: Cannot read properties of undefined (reading 'depth')
    at file:///vercel/path0/dist/chunks/pages/__4fac34a3.mjs:294:41
    at Array.forEach (<anonymous>)
    at generateToc (file:///vercel/path0/dist/chunks/pages/__4fac34a3.mjs:288:16)
    at file:///vercel/path0/dist/chunks/pages/_slug__53614ea7.mjs:36:15
    at AstroComponentInstance.TOC [as factory] (file:///vercel/path0/dist/chunks/astro_de9e2161.mjs:205:12)
    at AstroComponentInstance.init (file:///vercel/path0/dist/chunks/astro_de9e2161.mjs:1045:29)
    at AstroComponentInstance.render (file:///vercel/path0/dist/chunks/astro_de9e2161.mjs:1050:18)
    at Object.render (file:///vercel/path0/dist/chunks/astro_de9e2161.mjs:1501:22)
    at renderChild (file:///vercel/path0/dist/chunks/astro_de9e2161.mjs:1008:17)
    at async Object.renderToFinalDestination (file:///vercel/path0/dist/chunks/astro_de9e2161.mjs:826:7)
    at async RenderTemplateResult.render (file:///vercel/path0/dist/chunks/astro_de9e2161.mjs:1120:9)
    at async renderChild (file:///vercel/path0/dist/chunks/astro_de9e2161.mjs:1008:5)
 ELIFECYCLE  Command failed with exit code 1.
Error: Command "pnpm run build" exited with 1

原因: 这个博客插件在解析markdown文本是,要求必须按照级别逐步渲染 对的: # => ## => ### 错误: # => ###