Lynx SEO
lynxcms/seo 写入标题、描述、规范链接、机器人标签、Open Graph、X(Twitter)和 hreflang 标签,并提供 /robots.txt 服务。
渲染
<head>
<meta charset="utf-8">
<x-lynx-seo :page="$page" />
</head>
它会替换 <title> 和 @hreflang。如需过滤列表,可按响应覆盖:<x-lynx-seo :page="$page" robots="noindex, follow" :canonical="$page->url" />(键为 title、description、canonical、robots;相同的数组也适用于 @seo($page, [...]) 和 lynx()->seo($page, [...]))。@seo($page) 功能相同;lynx()->seo($page) 返回一个 SeoData 对象用于自定义 head。
字段
按模板启用 SEO;页面随后获得 seo_title、seo_description、seo_image、seo_noindex 和 seo_canonical:
lynx()->run(\LynxCms\Seo\Actions\EnableSeo::class, ['template' => 'article']);
空字段依次回退为:站点标题模式中的页面标题、lynx-seo.description_fields 中第一个包含文本的字段、lynx-seo.image_fields 中的第一个图片,最后是设置页面上的默认值(lynx()->settings('seo-settings'))。
在非生产环境中,每个页面都设为 noindex,并且 robots.txt 禁止所有爬取(lynx-seo.block_non_production)。
结构化数据
每个页面都会获得一个 JSON-LD 图(WebSite、Organization、WebPage、BreadcrumbList)。在 SEO 设置页面(seo_schemas 矩阵,项目类型 mapping:seo_schema_template、seo_schema_type、seo_schema_map)或管理后台的“结构化数据”标签页中,将模板映射到 schema.org 类型。映射行格式为 property: source,其中 source 可以是字段、@title、@url、@published、@modified、常量(如 =EUR)或 @organization(站点的所有者,用于 author、publisher、provider 或 organizer):
name: @title
startDate: starts
location: venue
offers.priceCurrency: =EUR
使用 app(\LynxCms\Seo\JsonLd\JsonLd::class)->extend(fn ($page, $graph) => $graph->add([...])) 添加其他节点。
检查
seo_inspect 读取工具会以某种语言显示页面的最终标签。管理 SEO 需要 seo.manage 权限。