astro博客问题记录
问题汇总
修改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