@easy-cms/plugin-seo 0.48.0 → 0.49.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/admin.js +1 -1
- package/dist/index.d.ts +14 -14
- package/dist/index.js +27 -25
- package/package.json +5 -5
package/dist/admin.js
CHANGED
|
@@ -43,7 +43,7 @@ var f="/seo/generate";var v=["value","path","doc","collection","global","id","lo
|
|
|
43
43
|
.description { margin: 0; font-size: 0.875rem; line-height: 1.5; color: var(--text-muted); }
|
|
44
44
|
.placeholder { font-style: italic; opacity: 0.75; }
|
|
45
45
|
.noindex { margin: 0.6rem 0 0; font-size: 0.8rem; color: var(--warning, var(--text-muted)); }
|
|
46
|
-
`}render(){let{titleField:e,url:t,
|
|
46
|
+
`}render(){let{titleField:e,url:t,siteURL:n}=this.ctx.options,o=k(this.ctx.doc,this.ctx.path)??{},c=e?this.ctx.doc[e]:void 0,s=[o.title,c].find(u=>typeof u=="string"&&u.trim()),a=typeof o.description=="string"?o.description.trim():"";t&&this.refreshUrl();let l=E(t?this.url:n);return`
|
|
47
47
|
<section class="card" aria-label="${i(this.t("preview"))}">
|
|
48
48
|
<p class="label">${i(this.t("preview"))}</p>
|
|
49
49
|
${l?`<p class="url">${i(l)}</p>`:""}
|
package/dist/index.d.ts
CHANGED
|
@@ -60,7 +60,7 @@ interface FieldLike {
|
|
|
60
60
|
interface SeoCMS {
|
|
61
61
|
readonly config: {
|
|
62
62
|
readonly admin: {
|
|
63
|
-
readonly
|
|
63
|
+
readonly siteURL?: string;
|
|
64
64
|
};
|
|
65
65
|
readonly serverURL?: string;
|
|
66
66
|
readonly localization: {
|
|
@@ -93,8 +93,8 @@ interface SeoCMS {
|
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
interface LlmsTxtOptions {
|
|
96
|
-
/** The site's public address, to make links absolute. Default `admin.
|
|
97
|
-
readonly
|
|
96
|
+
/** The site's public address, to make links absolute. Default `admin.siteURL`, then `serverURL`. */
|
|
97
|
+
readonly siteURL?: string;
|
|
98
98
|
/**
|
|
99
99
|
* The context to read in, e.g. the tenant of the requesting domain (`cms.forRequest(request)`,
|
|
100
100
|
* or `context` of an endpoint). Default: none.
|
|
@@ -136,10 +136,10 @@ type Value = string | null | undefined;
|
|
|
136
136
|
interface SeoMetaOptions {
|
|
137
137
|
/**
|
|
138
138
|
* The site's public address, to make the canonical and image URLs absolute, e.g.
|
|
139
|
-
* `https://example.com`. Default: `config.admin.
|
|
139
|
+
* `https://example.com`. Default: `config.admin.siteURL`, then `config.serverURL`.
|
|
140
140
|
*/
|
|
141
|
-
readonly
|
|
142
|
-
/** Your Easy CMS config, to read `admin.
|
|
141
|
+
readonly siteURL?: string;
|
|
142
|
+
/** Your Easy CMS config, to read `admin.siteURL`, `serverURL` and `localization` from. */
|
|
143
143
|
readonly config?: object;
|
|
144
144
|
/**
|
|
145
145
|
* The page's canonical address: absolute, or a path on the site. As a function it gets the
|
|
@@ -306,11 +306,11 @@ declare function siteJsonLd(options: SiteJsonLdOptions): JsonLd;
|
|
|
306
306
|
declare function jsonLdScript(value: JsonLd): string;
|
|
307
307
|
|
|
308
308
|
interface RobotsTxtOptions {
|
|
309
|
-
/** Your Easy CMS config, for the admin and API paths and `admin.
|
|
309
|
+
/** Your Easy CMS config, for the admin and API paths and `admin.siteURL`. */
|
|
310
310
|
readonly config?: object;
|
|
311
|
-
/** The site's public address, for the `Sitemap:` line. Default `admin.
|
|
312
|
-
readonly
|
|
313
|
-
/** The sitemap's address, or `false` for none. Default `<
|
|
311
|
+
/** The site's public address, for the `Sitemap:` line. Default `admin.siteURL`, then `serverURL`. */
|
|
312
|
+
readonly siteURL?: string;
|
|
313
|
+
/** The sitemap's address, or `false` for none. Default `<siteURL>/sitemap.xml`. */
|
|
314
314
|
readonly sitemap?: string | false;
|
|
315
315
|
/**
|
|
316
316
|
* Ask search engines to stay out of the whole site, e.g. on a staging copy. Not turned on by
|
|
@@ -390,7 +390,7 @@ interface SeoPluginOptions {
|
|
|
390
390
|
readonly generateDescription?: Generate<string>;
|
|
391
391
|
/** Suggests a share image: the id of a media document, e.g. the post's cover. */
|
|
392
392
|
readonly generateImage?: Generate<string | number>;
|
|
393
|
-
/** The page's address (absolute, or a path on `admin.
|
|
393
|
+
/** The page's address (absolute, or a path on `admin.siteURL`), shown in the search preview. */
|
|
394
394
|
readonly generateURL?: Generate<string>;
|
|
395
395
|
/** Fill empty meta fields with the generators when a document is saved. Default false. */
|
|
396
396
|
readonly autoGenerate?: boolean;
|
|
@@ -491,9 +491,9 @@ interface SitemapEntry {
|
|
|
491
491
|
interface SitemapOptions {
|
|
492
492
|
/**
|
|
493
493
|
* The site's public address, to make relative URLs from `generateURL` absolute. Default:
|
|
494
|
-
* `admin.
|
|
494
|
+
* `admin.siteURL`, then `serverURL`.
|
|
495
495
|
*/
|
|
496
|
-
readonly
|
|
496
|
+
readonly siteURL?: string;
|
|
497
497
|
/**
|
|
498
498
|
* The context to read in, e.g. the tenant of the requesting domain (`cms.forRequest(request)`,
|
|
499
499
|
* or `context` of an endpoint). Default: none.
|
|
@@ -503,7 +503,7 @@ interface SitemapOptions {
|
|
|
503
503
|
interface SitemapXmlOptions extends SitemapOptions {
|
|
504
504
|
/** Which part of a large sitemap (over 50,000 URLs) to render, from 1. */
|
|
505
505
|
readonly page?: number | string | null;
|
|
506
|
-
/** Address of this sitemap, for the index of a large one. Default `<
|
|
506
|
+
/** Address of this sitemap, for the index of a large one. Default `<siteURL>/sitemap.xml`. */
|
|
507
507
|
readonly base?: string;
|
|
508
508
|
}
|
|
509
509
|
/** Google's limit of URLs in one sitemap file. */
|
package/dist/index.js
CHANGED
|
@@ -106,7 +106,7 @@ function absolute(url, site) {
|
|
|
106
106
|
if (/^https?:\/\//.test(url) || !site || !/^https?:\/\//.test(site)) return url;
|
|
107
107
|
return `${site.replace(/\/+$/, "")}/${url.replace(/^\/+/, "")}`;
|
|
108
108
|
}
|
|
109
|
-
var siteOf = (cms,
|
|
109
|
+
var siteOf = (cms, siteURL) => siteURL ?? (cms.config.admin.siteURL || cms.config.serverURL);
|
|
110
110
|
var BATCH = 500;
|
|
111
111
|
async function visiblePages(cms, source, options) {
|
|
112
112
|
const generateURL = source.generateURL;
|
|
@@ -167,7 +167,7 @@ var DEFAULT_MAX_BYTES = 5e6;
|
|
|
167
167
|
async function llmsTxt(cms, options = {}) {
|
|
168
168
|
const source = findSource(cms, "llmsTxt");
|
|
169
169
|
const locale = localeOf(cms, source);
|
|
170
|
-
const site = siteOf(cms, options.
|
|
170
|
+
const site = siteOf(cms, options.siteURL);
|
|
171
171
|
const sections = /* @__PURE__ */ new Map();
|
|
172
172
|
await visiblePages(cms, source, {
|
|
173
173
|
...options.context ? { context: options.context } : {},
|
|
@@ -193,7 +193,7 @@ async function llmsTxt(cms, options = {}) {
|
|
|
193
193
|
async function llmsFullTxt(cms, options = {}) {
|
|
194
194
|
const source = findSource(cms, "llmsFullTxt");
|
|
195
195
|
const locale = localeOf(cms, source);
|
|
196
|
-
const site = siteOf(cms, options.
|
|
196
|
+
const site = siteOf(cms, options.siteURL);
|
|
197
197
|
const max = options.maxBytes ?? DEFAULT_MAX_BYTES;
|
|
198
198
|
const header = [`# ${inline(await siteTitle(cms, source, locale, options.context))}`];
|
|
199
199
|
if (source.llms.description) header.push("", `> ${inline(source.llms.description)}`);
|
|
@@ -350,7 +350,7 @@ var defined = (record) => Object.fromEntries(Object.entries(record).filter(([, v
|
|
|
350
350
|
function seoMeta(doc, options = {}) {
|
|
351
351
|
const config = options.config;
|
|
352
352
|
const meta = doc[META_FIELD] ?? {};
|
|
353
|
-
const site = options.
|
|
353
|
+
const site = options.siteURL ?? (config?.admin?.siteURL || config?.serverURL);
|
|
354
354
|
const title = text2(meta.title) ?? text2((options.title ?? ((d) => d.title))(doc));
|
|
355
355
|
const description = text2(meta.description) ?? text2((options.description ?? ((d) => d.excerpt ?? d.description))(doc));
|
|
356
356
|
const noindex = meta.noindex === true;
|
|
@@ -522,7 +522,9 @@ function jsonLdScript(value) {
|
|
|
522
522
|
// src/info.ts
|
|
523
523
|
var INFO = {
|
|
524
524
|
name: "@easy-cms/plugin-seo",
|
|
525
|
-
|
|
525
|
+
// The plugin API it is written for (`PLUGIN_API_VERSION` of @easy-cms/core).
|
|
526
|
+
apiVersion: 1,
|
|
527
|
+
...true ? { version: "0.49.0" } : {}
|
|
526
528
|
};
|
|
527
529
|
|
|
528
530
|
// src/robots.ts
|
|
@@ -545,7 +547,7 @@ function robotsTxt(options = {}) {
|
|
|
545
547
|
const trim = (path) => `/${path.replace(/^\/+|\/+$/g, "")}`;
|
|
546
548
|
const admin = trim(config?.admin?.path ?? "/admin");
|
|
547
549
|
const api = trim(config?.routes?.api ?? "/api/cms");
|
|
548
|
-
const site = options.
|
|
550
|
+
const site = options.siteURL ?? (config?.admin?.siteURL || config?.serverURL);
|
|
549
551
|
const base = options.disallowAll ? ["Disallow: /"] : [
|
|
550
552
|
`Allow: ${api}/media/file/`,
|
|
551
553
|
`Disallow: ${admin}/`,
|
|
@@ -580,7 +582,7 @@ function robotsTxt(options = {}) {
|
|
|
580
582
|
var SITEMAP_LIMIT = 5e4;
|
|
581
583
|
async function sitemap(cms, options = {}) {
|
|
582
584
|
const source = findSource(cms, "sitemap");
|
|
583
|
-
const site = siteOf(cms, options.
|
|
585
|
+
const site = siteOf(cms, options.siteURL);
|
|
584
586
|
const localization = cms.config.localization;
|
|
585
587
|
const locales = localization ? [...localization.locales] : [null];
|
|
586
588
|
const pages = /* @__PURE__ */ new Map();
|
|
@@ -609,7 +611,7 @@ async function sitemap(cms, options = {}) {
|
|
|
609
611
|
for (const url of distinct) {
|
|
610
612
|
if (!/^https?:\/\//.test(url))
|
|
611
613
|
throw new Error(
|
|
612
|
-
`sitemap: "${url}" is not an absolute URL. Set admin.
|
|
614
|
+
`sitemap: "${url}" is not an absolute URL. Set admin.siteURL in the config, or pass siteURL.`
|
|
613
615
|
);
|
|
614
616
|
entries.push({
|
|
615
617
|
url,
|
|
@@ -624,7 +626,7 @@ async function sitemapXml(cms, options = {}) {
|
|
|
624
626
|
const entries = await sitemap(cms, options);
|
|
625
627
|
const page = Number(options.page ?? 0);
|
|
626
628
|
if (entries.length > SITEMAP_LIMIT && !(page >= 1)) {
|
|
627
|
-
const site = siteOf(cms, options.
|
|
629
|
+
const site = siteOf(cms, options.siteURL) ?? "";
|
|
628
630
|
const base = options.base ?? `${site.replace(/\/+$/, "")}/sitemap.xml`;
|
|
629
631
|
const pages = Math.ceil(entries.length / SITEMAP_LIMIT);
|
|
630
632
|
const items = Array.from(
|
|
@@ -730,32 +732,32 @@ function seoPlugin(options = {}) {
|
|
|
730
732
|
name: META_FIELD,
|
|
731
733
|
type: "group",
|
|
732
734
|
label: options.label ?? "SEO",
|
|
733
|
-
...options.position === "sidebar" ? { position: "sidebar" } : {},
|
|
734
735
|
fields: options.fields ? options.fields(defaults) : defaults,
|
|
735
736
|
admin: {
|
|
737
|
+
...options.position === "sidebar" ? { position: "sidebar" } : {},
|
|
736
738
|
after: [
|
|
737
739
|
{
|
|
738
740
|
tag: "ecms-seo-preview",
|
|
739
741
|
props: {
|
|
740
742
|
titleField,
|
|
741
743
|
url: !!generators.url,
|
|
742
|
-
|
|
744
|
+
siteURL: config.admin?.siteURL ?? ""
|
|
743
745
|
}
|
|
744
746
|
}
|
|
745
747
|
]
|
|
746
748
|
}
|
|
747
749
|
};
|
|
748
750
|
};
|
|
749
|
-
const hook = options.autoGenerate ? async ({ data, operation,
|
|
751
|
+
const hook = options.autoGenerate ? async ({ data, operation, previousDoc, cms, user, slug }) => {
|
|
750
752
|
if (operation === "update" && data[META_FIELD] === void 0) return data;
|
|
751
|
-
const saved =
|
|
753
|
+
const saved = previousDoc?.[META_FIELD] ?? {};
|
|
752
754
|
const meta = { ...saved, ...data[META_FIELD] ?? {} };
|
|
753
|
-
const doc = { ...
|
|
755
|
+
const doc = { ...previousDoc, ...data };
|
|
754
756
|
const target = globals.includes(slug) ? { global: slug } : { collection: slug };
|
|
755
757
|
for (const kind of [...TEXT_KINDS, "image"]) {
|
|
756
758
|
const generate = generators[kind];
|
|
757
759
|
if (!generate || !isEmpty(meta[kind])) continue;
|
|
758
|
-
const id =
|
|
760
|
+
const id = previousDoc?.id ?? null;
|
|
759
761
|
const value = await generate({ doc, id, locale: null, cms, user, ...target });
|
|
760
762
|
if (value !== null && value !== void 0 && value !== "") meta[kind] = value;
|
|
761
763
|
}
|
|
@@ -768,8 +770,8 @@ function seoPlugin(options = {}) {
|
|
|
768
770
|
const indexNow = options.indexNow ? createIndexNow(options.indexNow) : void 0;
|
|
769
771
|
const urlsOf = async (doc, target, cms) => {
|
|
770
772
|
if (!generators.url) return [];
|
|
771
|
-
const site = config.admin?.
|
|
772
|
-
const locales = config.localization?.locales ?? [null];
|
|
773
|
+
const site = config.admin?.siteURL || config.serverURL;
|
|
774
|
+
const locales = (config.localization || void 0)?.locales ?? [null];
|
|
773
775
|
const urls = /* @__PURE__ */ new Set();
|
|
774
776
|
for (const locale of locales) {
|
|
775
777
|
const id = doc.id ?? null;
|
|
@@ -786,12 +788,12 @@ function seoPlugin(options = {}) {
|
|
|
786
788
|
const indexNowBefore = async ({
|
|
787
789
|
data,
|
|
788
790
|
operation,
|
|
789
|
-
|
|
791
|
+
previousDoc,
|
|
790
792
|
cms,
|
|
791
793
|
slug
|
|
792
794
|
}) => {
|
|
793
|
-
if (operation === "update" &&
|
|
794
|
-
wasLive.set(`${slug}:${
|
|
795
|
+
if (operation === "update" && previousDoc?.id !== void 0 && !globals.includes(slug))
|
|
796
|
+
wasLive.set(`${slug}:${previousDoc.id}`, await liveNow(cms, slug, previousDoc.id));
|
|
795
797
|
return data;
|
|
796
798
|
};
|
|
797
799
|
const indexNowChange = async ({ doc, previousDoc, cms, slug }) => {
|
|
@@ -883,10 +885,10 @@ function seoPlugin(options = {}) {
|
|
|
883
885
|
const api = config.routes?.api ?? "/api/cms";
|
|
884
886
|
const sitemapHandler = (base) => Object.assign(
|
|
885
887
|
async ({ url, cms, context }) => {
|
|
886
|
-
const site = config.admin?.
|
|
888
|
+
const site = config.admin?.siteURL || config.serverURL || url.origin;
|
|
887
889
|
return xmlResponse(
|
|
888
890
|
await sitemapXml(cms, {
|
|
889
|
-
|
|
891
|
+
siteURL: site,
|
|
890
892
|
context,
|
|
891
893
|
page: url.searchParams.get("page"),
|
|
892
894
|
base: base(url.origin)
|
|
@@ -927,14 +929,14 @@ function seoPlugin(options = {}) {
|
|
|
927
929
|
}
|
|
928
930
|
});
|
|
929
931
|
if (options.llms !== false) {
|
|
930
|
-
const site = (origin) => config.admin?.
|
|
932
|
+
const site = (origin) => config.admin?.siteURL || config.serverURL || origin;
|
|
931
933
|
siteEndpoints.push(
|
|
932
934
|
{
|
|
933
935
|
path: "/llms.txt",
|
|
934
936
|
method: "get",
|
|
935
937
|
root: true,
|
|
936
938
|
handler: async ({ url, cms, context }) => textResponse(
|
|
937
|
-
await llmsTxt(cms, {
|
|
939
|
+
await llmsTxt(cms, { siteURL: site(url.origin), context }),
|
|
938
940
|
"text/markdown"
|
|
939
941
|
)
|
|
940
942
|
},
|
|
@@ -943,7 +945,7 @@ function seoPlugin(options = {}) {
|
|
|
943
945
|
method: "get",
|
|
944
946
|
root: true,
|
|
945
947
|
handler: async ({ url, cms, context }) => textResponse(
|
|
946
|
-
await llmsFullTxt(cms, {
|
|
948
|
+
await llmsFullTxt(cms, { siteURL: site(url.origin), context }),
|
|
947
949
|
"text/markdown"
|
|
948
950
|
)
|
|
949
951
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@easy-cms/plugin-seo",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.49.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
|
+
"@easy-cms/richtext": "^0.49.0"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
23
|
-
"@easy-cms/core": "^0.
|
|
23
|
+
"@easy-cms/core": "^0.49.0"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"happy-dom": "^20.14.5",
|
|
27
|
-
"@easy-cms/core": "^0.
|
|
28
|
-
"@easy-cms/db-sqlite": "^0.
|
|
27
|
+
"@easy-cms/core": "^0.49.0",
|
|
28
|
+
"@easy-cms/db-sqlite": "^0.49.0"
|
|
29
29
|
},
|
|
30
30
|
"engines": {
|
|
31
31
|
"node": ">=22.12"
|