-
-
Notifications
You must be signed in to change notification settings - Fork 2
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
fix: tested and verified the article data transformation #317
fix: tested and verified the article data transformation #317
Conversation
if (process.env.NODE_ENV === 'development') { | ||
ArticleSchema.parse(document) | ||
} | ||
const article = normalizeArticle(document as TypesenseArticleLike) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (process.env.NODE_ENV === 'development') { | ||
QueryArticleSchema.parse(data.article) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果驗證失敗的話會導致沒有 return article 直接顯示 500 error
export const ArticleSchema = z.object({ | ||
authors: z.array(AuthorSchema), | ||
blurb: z.string(), | ||
cover: z.string(), | ||
desk: DeskSchema, | ||
featured: z.boolean(), | ||
id: z.string(), | ||
order: z.number(), | ||
pathnames: z.array(z.string()), | ||
plan: z.string(), | ||
published_at: z.number(), | ||
seo: z.string(), | ||
slug: z.string(), | ||
tags: z.array(DeskSchema), | ||
title: z.string(), | ||
updated_at: z.number(), | ||
}) | ||
export type Article = z.infer<typeof ArticleSchema> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cover
、seo
有可能會是 null
export const AuthorSchema = z.object({ | ||
avatar: z.string(), | ||
bio: z.string(), | ||
full_name: z.string(), | ||
id: z.number(), | ||
location: z.string(), | ||
slug: z.string(), | ||
socials: z.string(), | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bio
、location
、socials
有可能會是 null
Added schema validation in dev, and when validation fails, access to the article page is denied.