Appearance
SEO 管理插件
插件信息
名称:SEO 管理插件(seo) 版本:v0.3.1 类型:官方插件 状态:已内置
概述
SEO 管理插件为 MengStack 提供全面的搜索引擎优化能力,包括站点 TDK 配置、TDK 模板生成、动态 Sitemap、Robots.txt 管理、301/302 重定向、内链管理和 JSON-LD 结构化数据。支持 Open Graph 和 Twitter Card 社交分享标签。
功能特性
- 站点 SEO 配置:全局站点名称、URL、默认 TDK、OG 图片、Twitter 账号
- TDK 模板生成:
GenerateTDK()为任意页面生成 Title / Description / Keywords / OG / Twitter Card / JSON-LD - 动态 Sitemap:
GenerateSitemapXML()生成符合 sitemaps.org 规范的 XML - Robots.txt 管理:
GenerateRobotsTxt()根据规则动态生成,自动追加 Sitemap URL - 重定向规则:支持 301/302 重定向,默认 301 永久重定向
- 内链管理:关键词自动链接到目标 URL,可控制单页最大内链数
- 推送记录:记录向搜索引擎推送 URL 的状态和响应
数据模型
SEO 配置(SeoConfig)
| 字段 | 类型 | 说明 |
|---|---|---|
id | uuid | 主键(继承自 BaseModel) |
tenant_id | uuid | 租户 ID(继承自 BaseModel) |
site_name | string | 站点名称 |
site_url | string | 站点 URL |
default_title | string | 默认页面标题 |
default_desc | string | 默认页面描述 |
default_keywords | string | 默认关键词 |
default_og_image | string | 默认 OG 分享图 URL |
twitter_site | string | Twitter 站点账号 |
twitter_creator | string | Twitter 创作者账号 |
favicon_url | string | Favicon URL |
created_at | time | 创建时间(继承自 BaseModel) |
updated_at | time | 更新时间(继承自 BaseModel) |
deleted_at | time | 软删除时间(继承自 BaseModel) |
Sitemap 条目(SitemapEntry)
| 字段 | 类型 | 说明 |
|---|---|---|
id | uuid | 主键 |
tenant_id | uuid | 租户 ID |
loc | string | 页面完整 URL |
last_mod | time | 最后修改时间 |
change_freq | string | 更新频率:always / hourly / daily / weekly / monthly / yearly / never |
priority | float | 优先级(0.0 ~ 1.0) |
entity_type | string | 关联内容类型 |
entity_id | uuid | 关联内容 ID |
created_at | time | 创建时间 |
updated_at | time | 更新时间 |
deleted_at | time | 软删除时间 |
重定向规则(RedirectRule)
| 字段 | 类型 | 说明 |
|---|---|---|
id | uuid | 主键 |
tenant_id | uuid | 租户 ID |
source_path | string | 源路径 |
target_path | string | 目标路径 |
status_code | int | HTTP 状态码(默认 301) |
is_active | bool | 是否启用 |
created_at | time | 创建时间 |
updated_at | time | 更新时间 |
deleted_at | time | 软删除时间 |
内链(InternalLink)
| 字段 | 类型 | 说明 |
|---|---|---|
id | uuid | 主键 |
tenant_id | uuid | 租户 ID |
keyword | string | 触发关键词 |
target_url | string | 目标 URL |
target_title | string | 目标标题 |
max_links | int | 单页最大链接数(默认 5) |
is_active | bool | 是否启用 |
created_at | time | 创建时间 |
updated_at | time | 更新时间 |
deleted_at | time | 软删除时间 |
Robots 规则(RobotsRule)
| 字段 | 类型 | 说明 |
|---|---|---|
id | uuid | 主键 |
tenant_id | uuid | 租户 ID |
user_agent | string | User-Agent(* 表示全部) |
path | string | 路径 |
allow | bool | 允许(true)或禁止(false) |
sort_order | int | 排序权重 |
created_at | time | 创建时间 |
updated_at | time | 更新时间 |
deleted_at | time | 软删除时间 |
推送记录(PushRecord)
| 字段 | 类型 | 说明 |
|---|---|---|
id | uuid | 主键 |
tenant_id | uuid | 租户 ID |
url | string | 推送的 URL |
platform | string | 推送平台 |
status | string | 状态:pending / success / failed |
status_code | int | 响应状态码 |
response | text | 响应内容 |
pushed_at | time | 推送时间 |
created_at | time | 创建时间 |
updated_at | time | 更新时间 |
deleted_at | time | 软删除时间 |
核心方法
GenerateTDK
为指定页面生成完整的 SEO 元数据,输出包含:
<title>和<meta name="description">/<meta name="keywords">- Open Graph 标签(
og:title、og:description、og:image、og:url、og:type) - Twitter Card 标签(
twitter:card、twitter:site、twitter:creator) - JSON-LD 结构化数据(
schema.org/WebSite)
GenerateSitemapXML
生成符合 sitemaps.org 规范的 XML Sitemap,包含 urlset 命名空间,遍历所有 SitemapEntry 输出 <url> 节点。
GenerateRobotsTxt
根据 RobotsRule 规则动态生成 robots.txt 内容,按 sort_order 排序,自动在末尾追加 Sitemap: {site_url}/sitemap.xml。
API 接口
公开接口
| 方法 | 路径 | 说明 |
|---|---|---|
GET | /api/v1/seo/tdk | 生成页面 TDK 元数据 |
GET | /api/v1/seo/sitemap.xml | 获取动态 Sitemap XML |
GET | /api/v1/seo/robots.txt | 获取动态 Robots.txt |
GET | /api/v1/seo/links/active | 获取启用的内链列表 |
需认证接口
| 方法 | 路径 | 权限 | 说明 |
|---|---|---|---|
GET | /api/v1/seo/config | seo.config.write | 获取 SEO 配置 |
PUT | /api/v1/seo/config | seo.config.write | 更新 SEO 配置 |
POST | /api/v1/seo/sitemap | seo.sitemap.write | 创建 Sitemap 条目 |
GET | /api/v1/seo/sitemap | seo.config.write | 获取 Sitemap 条目列表 |
DELETE | /api/v1/seo/sitemap/:id | seo.sitemap.write | 删除 Sitemap 条目 |
POST | /api/v1/seo/robots | seo.redirect.write | 创建 Robots 规则 |
GET | /api/v1/seo/robots | seo.config.write | 获取 Robots 规则列表 |
DELETE | /api/v1/seo/robots/:id | seo.redirect.write | 删除 Robots 规则 |
POST | /api/v1/seo/redirects | seo.redirect.write | 创建重定向规则 |
GET | /api/v1/seo/redirects | seo.config.write | 获取重定向规则列表 |
PUT | /api/v1/seo/redirects/:id | seo.redirect.write | 更新重定向规则 |
DELETE | /api/v1/seo/redirects/:id | seo.redirect.write | 删除重定向规则 |
POST | /api/v1/seo/links | seo.link.write | 创建内链 |
GET | /api/v1/seo/links | seo.config.write | 获取内链列表 |
DELETE | /api/v1/seo/links/:id | seo.link.write | 删除内链 |
GET | /api/v1/seo/push-records | seo.config.write | 获取推送记录 |
数据库表
| 表名 | 说明 |
|---|---|
seo_configs | SEO 配置表 |
sitemap_entries | Sitemap 条目表 |
push_records | 推送记录表 |
robots_rules | Robots 规则表 |
redirect_rules | 重定向规则表 |
internal_links | 内链表 |
权限
| 权限标识 | 说明 |
|---|---|
seo.config.write | 管理 SEO 配置 |
seo.sitemap.write | 管理 Sitemap |
seo.redirect.write | 管理重定向 |
seo.link.write | 管理友链 |
依赖
- auth:用户认证
- rbac:权限模型
- org:多租户隔离

