@easy-cms/plugin-seo 0.20.1 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -161,6 +161,16 @@ interface SeoMetaOptions {
161
161
  readonly author?: string | ((doc: Doc) => Value);
162
162
  /** Schema.org type of an article's JSON-LD. Default `BlogPosting`. */
163
163
  readonly articleType?: 'Article' | 'BlogPosting' | 'NewsArticle';
164
+ /**
165
+ * The trail to the page, top level first and the page last, for BreadcrumbList JSON-LD
166
+ * (search results can show it). URLs are absolute or paths on the site, e.g. from the nested
167
+ * docs plugin: `page.breadcrumbs.map((b) => ({ name: b.label, url: \`/p${b.url}\` }))`.
168
+ */
169
+ readonly breadcrumbs?: readonly SeoBreadcrumb[];
170
+ }
171
+ interface SeoBreadcrumb {
172
+ readonly name: string;
173
+ readonly url?: string | null;
164
174
  }
165
175
  interface SeoImage {
166
176
  readonly url: string;
@@ -247,11 +257,16 @@ interface SeoMeta {
247
257
  readonly alternates: Readonly<Record<string, string>> | undefined;
248
258
  /** Schema.org data for the page: BlogPosting (or `articleType`) for articles, else WebPage. */
249
259
  readonly jsonLd: JsonLd;
260
+ /** BreadcrumbList JSON-LD from `breadcrumbs`; `undefined` without them. */
261
+ readonly breadcrumbList: JsonLd | undefined;
250
262
  /** For Nuxt's `useSeoMeta()`. */
251
263
  readonly nuxt: NuxtSeoMeta;
252
264
  /** For Nuxt's `useHead()`: canonical and hreflang links, and the JSON-LD script. */
253
265
  readonly head: NuxtSeoHead;
254
- /** For Next.js `generateMetadata()`. Render `jsonLd` with `jsonLdScript()` in the page. */
266
+ /**
267
+ * For Next.js `generateMetadata()`. Render `jsonLd` (and `breadcrumbList`) with
268
+ * `jsonLdScript()` in the page.
269
+ */
255
270
  readonly next: NextSeoMetadata;
256
271
  }
257
272
  /**
@@ -454,4 +469,4 @@ declare function sitemap(cms: SeoCMS, options?: SitemapOptions): Promise<Sitemap
454
469
  */
455
470
  declare function sitemapXml(cms: SeoCMS, options?: SitemapXmlOptions): Promise<string>;
456
471
 
457
- export { AI_CRAWLERS, DEFAULT_DESCRIPTION_LENGTH, DEFAULT_TITLE_LENGTH, type DocMarkdownOptions, type Generate, type GenerateArgs, type IndexNowOptions, type JsonLd, type LlmsFullTxtOptions, type LlmsOptions, type LlmsTxtOptions, type NextSeoMetadata, type NuxtSeoHead, type NuxtSeoMeta, type RobotsRule, type RobotsTxtOptions, SITEMAP_LIMIT, type SeoImage, type SeoMeta, type SeoMetaOptions, type SeoPluginOptions, type SiteJsonLdOptions, type SitemapEntry, type SitemapOptions, type SitemapXmlOptions, docMarkdown, indexNowKeyFile, jsonLdScript, llmsFullTxt, llmsTxt, robotsTxt, seoMeta, seoPlugin, siteJsonLd, sitemap, sitemapXml };
472
+ export { AI_CRAWLERS, DEFAULT_DESCRIPTION_LENGTH, DEFAULT_TITLE_LENGTH, type DocMarkdownOptions, type Generate, type GenerateArgs, type IndexNowOptions, type JsonLd, type LlmsFullTxtOptions, type LlmsOptions, type LlmsTxtOptions, type NextSeoMetadata, type NuxtSeoHead, type NuxtSeoMeta, type RobotsRule, type RobotsTxtOptions, SITEMAP_LIMIT, type SeoBreadcrumb, type SeoImage, type SeoMeta, type SeoMetaOptions, type SeoPluginOptions, type SiteJsonLdOptions, type SitemapEntry, type SitemapOptions, type SitemapXmlOptions, docMarkdown, indexNowKeyFile, jsonLdScript, llmsFullTxt, llmsTxt, robotsTxt, seoMeta, seoPlugin, siteJsonLd, sitemap, sitemapXml };
package/dist/index.js CHANGED
@@ -398,6 +398,20 @@ function seoMeta(doc, options = {}) {
398
398
  primaryImageOfPage: image ? image.url : void 0,
399
399
  inLanguage: locale
400
400
  });
401
+ const trail = (options.breadcrumbs ?? []).filter((b) => text2(b.name));
402
+ const breadcrumbList = trail.length > 0 ? {
403
+ "@context": "https://schema.org",
404
+ "@type": "BreadcrumbList",
405
+ itemListElement: trail.map(
406
+ (b, i) => defined({
407
+ "@type": "ListItem",
408
+ position: i + 1,
409
+ name: text2(b.name),
410
+ // The last step is the page itself: Google takes its URL from the page.
411
+ item: text2(b.url) ? absolute(text2(b.url), site) : void 0
412
+ })
413
+ )
414
+ } : void 0;
401
415
  const link = [];
402
416
  if (canonical) link.push({ rel: "canonical", href: canonical });
403
417
  for (const [hreflang, href] of Object.entries(alternates ?? {}))
@@ -410,9 +424,13 @@ function seoMeta(doc, options = {}) {
410
424
  noindex,
411
425
  alternates,
412
426
  jsonLd,
427
+ breadcrumbList,
413
428
  head: {
414
429
  link,
415
- script: [{ type: "application/ld+json", innerHTML: jsonLdScript(jsonLd) }]
430
+ script: [jsonLd, ...breadcrumbList ? [breadcrumbList] : []].map((value) => ({
431
+ type: "application/ld+json",
432
+ innerHTML: jsonLdScript(value)
433
+ }))
416
434
  },
417
435
  nuxt: defined({
418
436
  title,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easy-cms/plugin-seo",
3
- "version": "0.20.1",
3
+ "version": "0.21.0",
4
4
  "description": "SEO for Easy CMS: meta fields, length meters, a search result preview, generators and page metadata",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -17,15 +17,15 @@
17
17
  "dist"
18
18
  ],
19
19
  "dependencies": {
20
- "@easy-cms/richtext": "^0.20.1"
20
+ "@easy-cms/richtext": "^0.21.0"
21
21
  },
22
22
  "peerDependencies": {
23
- "@easy-cms/core": "^0.20.1"
23
+ "@easy-cms/core": "^0.21.0"
24
24
  },
25
25
  "devDependencies": {
26
26
  "happy-dom": "^20.14.5",
27
- "@easy-cms/core": "^0.20.1",
28
- "@easy-cms/db-sqlite": "^0.20.1"
27
+ "@easy-cms/core": "^0.21.0",
28
+ "@easy-cms/db-sqlite": "^0.21.0"
29
29
  },
30
30
  "engines": {
31
31
  "node": ">=22.12"