feat(blog-seo): add SEO quality checker for post#20
Open
yumingHe0705 wants to merge 2 commits into
Open
Conversation
Adds an admin-only blog CMS to the Wasp app: - Data model: Post, Author, Tag (+ PostStatus enum) with a many-to-many Post<->Tag relation and an optional Author<->User link. - Operations: admin CRUD, public read (published only), tag/author creation, with zod input validation and admin-only authorization. - Slug handling: auto-slugify from title, app-level uniqueness with a numeric suffix, and a DB unique constraint as the final guard (P2002 -> 409). - Publish lifecycle modeled as an explicit state machine (DRAFT/PUBLISHED/ ARCHIVED); publishedAt is stamped on first publish; archived posts must be restored to draft before going live again. - Admin UI: posts list (filter/search/paginate, inline status transitions, delete) and a create/edit editor (inline author/tag creation, SEO fields), plus a "Blog Posts" sidebar entry. - Dev seed (seedBlogContent) and unit tests for slug + status-machine logic. Co-authored-by: Cursor <cursoragent@cursor.com>
Adds an SEO quality gate on top of the blog CMS: - A framework-free rule engine (`seoChecker.ts`) that scores a post 0-100 and reports per-rule results with actionable fixes. Rules cover title/meta-title length, meta description (with excerpt fallback), slug validity, a competing H1, missing H2 structure, image alt text, links, canonical URL validity, and thin content. Thresholds are named constants based on common SEO guidance. - The same pure engine runs in two places (DRY): live in the post editor for instant feedback while typing (`SeoReportPanel`), and server-side via the admin-only `analyzePostSeo` query for auditing a saved post. - Unit tests (`seoChecker.test.ts`) for the rules and the markdown/HTML parsing helpers (heading counts, image alt detection, link counting, word count). Stacked on the blog CMS (Post/Author/Tag) change. Co-authored-by: Cursor <cursoragent@cursor.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
博客 SEO 质检器 —— PR 说明
概述
新增一个零框架依赖的 SEO 规则引擎,对文章的标题、meta、正文结构、图片、链接、canonical 等做体检,输出 0–100 分和逐项结果(含可执行的修复建议)。同一套纯逻辑在两处复用:
analyzePostSeo(管理员)对已保存文章做审计(可供程序化/流水线调用)。改动内容
src/blog-cms/seoChecker.ts:纯规则引擎(analyzeSeo+ 解析辅助函数)。src/blog-cms/SeoReportPanel.tsx:展示评分与逐项结果的纯展示组件。src/blog-cms/AdminPostEditorPage.tsx:接入实时体检面板(useMemo对当前表单计算)。src/blog-cms/operations.ts+blog-cms.wasp.ts:新增服务端analyzePostSeo查询(管理员鉴权)。src/blog-cms/seoChecker.test.ts:规则与解析函数的单元测试。检查规则(阈值均为具名常量,便于调优与引用)
评分:满分 100,每个 error −20、每个 warning −8,截断到 [0,100]。
关键设计取舍
analyzePostSeo)跑的是同一份代码,规则永远一致,且每条规则都能纯函数级单测。error/warning/ok三级 + 加权分数,给出的是"如何改进"的可执行反馈,而非二元结论。SEO_LIMITS),依据常见 SEO 实践(标题 ≤60、meta 描述 50–160、单一 H1、图片 alt、canonical 等),便于团队按需调整。type而非interface。 Wasp operation 的返回值必须是 SuperJSON 可序列化的Payload;TS 中对象type满足该索引签名约束、interface不满足,因此SeoReport/SeoCheck用type定义。isValidSlug,类型导入会被打包器擦除),可安全进客户端包。边界处理
与 HTML<img alt>,alt 为空才算缺失。![...]不计为链接)。analyzePostSeo对不存在的文章返回 404;非管理员 401/403。测试方式
wasp test client run),本 PR 新增 11 个(全仓库 27 个全过):countHeadings(Markdown+HTML 分级)、analyzeImages(alt 检测)、countLinks(排除图片)、wordCount(去语法计词)。本地评审步骤
局限与后续