@easy-cms/plugin-seo 0.43.0 → 0.45.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
@@ -1,4 +1,4 @@
1
- import { EasyCMS, AuthUser, Field, Label as Label$1, TypedPlugin } from '@easy-cms/core';
1
+ import { RequestContext, EasyCMS, AuthUser, Field, Label as Label$1, TypedPlugin } from '@easy-cms/core';
2
2
 
3
3
  interface IndexNowOptions {
4
4
  /**
@@ -95,6 +95,11 @@ interface SeoCMS {
95
95
  interface LlmsTxtOptions {
96
96
  /** The site's public address, to make links absolute. Default `admin.siteUrl`, then `serverURL`. */
97
97
  readonly siteUrl?: string;
98
+ /**
99
+ * The context to read in, e.g. the tenant of the requesting domain (`cms.forRequest(request)`,
100
+ * or `context` of an endpoint). Default: none.
101
+ */
102
+ readonly context?: RequestContext;
98
103
  }
99
104
  interface LlmsFullTxtOptions extends LlmsTxtOptions {
100
105
  /** Stop adding pages after this many bytes. Default about 5 MB. */
@@ -483,6 +488,11 @@ interface SitemapOptions {
483
488
  * `admin.siteUrl`, then `serverURL`.
484
489
  */
485
490
  readonly siteUrl?: string;
491
+ /**
492
+ * The context to read in, e.g. the tenant of the requesting domain (`cms.forRequest(request)`,
493
+ * or `context` of an endpoint). Default: none.
494
+ */
495
+ readonly context?: RequestContext;
486
496
  }
487
497
  interface SitemapXmlOptions extends SitemapOptions {
488
498
  /** Which part of a large sitemap (over 50,000 URLs) to render, from 1. */
package/dist/index.js CHANGED
@@ -128,6 +128,7 @@ async function visiblePages(cms, source, options) {
128
128
  () => cms.find(collection, {
129
129
  overrideAccess: false,
130
130
  user: null,
131
+ ...options.context ? { context: options.context } : {},
131
132
  depth: options.depth ?? 0,
132
133
  sort: options.sort ?? "id",
133
134
  limit,
@@ -146,6 +147,7 @@ async function visiblePages(cms, source, options) {
146
147
  () => cms.findGlobal(global, {
147
148
  overrideAccess: false,
148
149
  user: null,
150
+ ...options.context ? { context: options.context } : {},
149
151
  depth: options.depth ?? 0,
150
152
  ...locale ? { locale } : {}
151
153
  })
@@ -168,6 +170,7 @@ async function llmsTxt(cms, options = {}) {
168
170
  const site = siteOf(cms, options.siteUrl);
169
171
  const sections = /* @__PURE__ */ new Map();
170
172
  await visiblePages(cms, source, {
173
+ ...options.context ? { context: options.context } : {},
171
174
  locale,
172
175
  site,
173
176
  sort: "-createdAt",
@@ -181,7 +184,7 @@ async function llmsTxt(cms, options = {}) {
181
184
  sections.set(heading, [...sections.get(heading) ?? [], line]);
182
185
  }
183
186
  });
184
- const lines = [`# ${inline(await siteTitle(cms, source, locale))}`];
187
+ const lines = [`# ${inline(await siteTitle(cms, source, locale, options.context))}`];
185
188
  if (source.llms.description) lines.push("", `> ${inline(source.llms.description)}`);
186
189
  for (const [heading, items] of sections) lines.push("", `## ${inline(heading)}`, "", ...items);
187
190
  return `${lines.join("\n")}
@@ -192,12 +195,13 @@ async function llmsFullTxt(cms, options = {}) {
192
195
  const locale = localeOf(cms, source);
193
196
  const site = siteOf(cms, options.siteUrl);
194
197
  const max = options.maxBytes ?? DEFAULT_MAX_BYTES;
195
- const header = [`# ${inline(await siteTitle(cms, source, locale))}`];
198
+ const header = [`# ${inline(await siteTitle(cms, source, locale, options.context))}`];
196
199
  if (source.llms.description) header.push("", `> ${inline(source.llms.description)}`);
197
200
  const parts = [];
198
201
  let bytes = byteLength(header.join("\n"));
199
202
  let full = false;
200
203
  await visiblePages(cms, source, {
204
+ ...options.context ? { context: options.context } : {},
201
205
  locale,
202
206
  site,
203
207
  sort: "-createdAt",
@@ -307,11 +311,16 @@ function localeOf(cms, source) {
307
311
  if (!localization) return null;
308
312
  return source.llms.locale ?? localization.defaultLocale;
309
313
  }
310
- async function siteTitle(cms, source, locale) {
314
+ async function siteTitle(cms, source, locale, context) {
311
315
  if (source.llms.title) return source.llms.title;
312
316
  for (const global of source.globals) {
313
317
  const doc = await visitor(
314
- () => cms.findGlobal(global, { overrideAccess: false, user: null, ...locale ? { locale } : {} })
318
+ () => cms.findGlobal(global, {
319
+ overrideAccess: false,
320
+ user: null,
321
+ ...context ? { context } : {},
322
+ ...locale ? { locale } : {}
323
+ })
315
324
  );
316
325
  const name = text(doc?.siteName) ?? text(doc?.name) ?? text(doc?.title);
317
326
  if (name) return name;
@@ -513,7 +522,7 @@ function jsonLdScript(value) {
513
522
  // src/info.ts
514
523
  var INFO = {
515
524
  name: "@easy-cms/plugin-seo",
516
- ...true ? { version: "0.43.0" } : {}
525
+ ...true ? { version: "0.45.0" } : {}
517
526
  };
518
527
 
519
528
  // src/robots.ts
@@ -579,6 +588,7 @@ async function sitemap(cms, options = {}) {
579
588
  await visiblePages(cms, source, {
580
589
  locale,
581
590
  site,
591
+ ...options.context ? { context: options.context } : {},
582
592
  each: ({ key, doc, url }) => {
583
593
  const page = pages.get(key) ?? { urls: /* @__PURE__ */ new Map() };
584
594
  page.urls.set(locale, url);
@@ -864,11 +874,12 @@ function seoPlugin(options = {}) {
864
874
  });
865
875
  const api = config.routes?.api ?? "/api/cms";
866
876
  const sitemapHandler = (base) => Object.assign(
867
- async ({ url, cms }) => {
877
+ async ({ url, cms, context }) => {
868
878
  const site = config.admin?.siteUrl || config.serverURL || url.origin;
869
879
  return xmlResponse(
870
880
  await sitemapXml(cms, {
871
881
  siteUrl: site,
882
+ context,
872
883
  page: url.searchParams.get("page"),
873
884
  base: base(url.origin)
874
885
  })
@@ -914,8 +925,8 @@ function seoPlugin(options = {}) {
914
925
  path: "/llms.txt",
915
926
  method: "get",
916
927
  root: true,
917
- handler: async ({ url, cms }) => textResponse(
918
- await llmsTxt(cms, { siteUrl: site(url.origin) }),
928
+ handler: async ({ url, cms, context }) => textResponse(
929
+ await llmsTxt(cms, { siteUrl: site(url.origin), context }),
919
930
  "text/markdown"
920
931
  )
921
932
  },
@@ -923,8 +934,8 @@ function seoPlugin(options = {}) {
923
934
  path: "/llms-full.txt",
924
935
  method: "get",
925
936
  root: true,
926
- handler: async ({ url, cms }) => textResponse(
927
- await llmsFullTxt(cms, { siteUrl: site(url.origin) }),
937
+ handler: async ({ url, cms, context }) => textResponse(
938
+ await llmsFullTxt(cms, { siteUrl: site(url.origin), context }),
928
939
  "text/markdown"
929
940
  )
930
941
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easy-cms/plugin-seo",
3
- "version": "0.43.0",
3
+ "version": "0.45.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.43.0"
20
+ "@easy-cms/richtext": "^0.45.0"
21
21
  },
22
22
  "peerDependencies": {
23
- "@easy-cms/core": "^0.43.0"
23
+ "@easy-cms/core": "^0.45.0"
24
24
  },
25
25
  "devDependencies": {
26
26
  "happy-dom": "^20.14.5",
27
- "@easy-cms/core": "^0.43.0",
28
- "@easy-cms/db-sqlite": "^0.43.0"
27
+ "@easy-cms/core": "^0.45.0",
28
+ "@easy-cms/db-sqlite": "^0.45.0"
29
29
  },
30
30
  "engines": {
31
31
  "node": ">=22.12"