@easy-cms/plugin-seo 0.16.0 → 0.17.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 CHANGED
@@ -1,4 +1,4 @@
1
- var f="/seo/generate";var v=["value","path","doc","collection","global","id","locale","uiLocale","readOnly","options","api"],b={en:{characters:"{n} / {max} characters",empty:"Empty: search engines pick text from the page",short:"Short: aim for {min}\u2013{max}",good:"Good length",long:"Too long: may be cut off after {max}",generate:"Generate",generating:"Generating\u2026",generateImage:"Use image from content",noValue:"Nothing to generate from yet",failed:"Could not generate: {message}",preview:"Search result preview",noTitle:"Page title",noDescription:"Add a description to control the text under the title."},th:{characters:"{n} / {max} \u0E15\u0E31\u0E27\u0E2D\u0E31\u0E01\u0E29\u0E23",empty:"\u0E27\u0E48\u0E32\u0E07: \u0E40\u0E04\u0E23\u0E37\u0E48\u0E2D\u0E07\u0E21\u0E37\u0E2D\u0E04\u0E49\u0E19\u0E2B\u0E32\u0E08\u0E30\u0E40\u0E25\u0E37\u0E2D\u0E01\u0E02\u0E49\u0E2D\u0E04\u0E27\u0E32\u0E21\u0E08\u0E32\u0E01\u0E2B\u0E19\u0E49\u0E32\u0E40\u0E2D\u0E07",short:"\u0E2A\u0E31\u0E49\u0E19\u0E44\u0E1B: \u0E04\u0E27\u0E23\u0E22\u0E32\u0E27 {min}\u2013{max}",good:"\u0E04\u0E27\u0E32\u0E21\u0E22\u0E32\u0E27\u0E1E\u0E2D\u0E14\u0E35",long:"\u0E22\u0E32\u0E27\u0E44\u0E1B: \u0E2D\u0E32\u0E08\u0E16\u0E39\u0E01\u0E15\u0E31\u0E14\u0E2B\u0E25\u0E31\u0E07 {max}",generate:"\u0E2A\u0E23\u0E49\u0E32\u0E07\u0E43\u0E2B\u0E49",generating:"\u0E01\u0E33\u0E25\u0E31\u0E07\u0E2A\u0E23\u0E49\u0E32\u0E07\u2026",generateImage:"\u0E43\u0E0A\u0E49\u0E23\u0E39\u0E1B\u0E08\u0E32\u0E01\u0E40\u0E19\u0E37\u0E49\u0E2D\u0E2B\u0E32",noValue:"\u0E22\u0E31\u0E07\u0E44\u0E21\u0E48\u0E21\u0E35\u0E02\u0E49\u0E2D\u0E21\u0E39\u0E25\u0E43\u0E2B\u0E49\u0E2A\u0E23\u0E49\u0E32\u0E07",failed:"\u0E2A\u0E23\u0E49\u0E32\u0E07\u0E44\u0E21\u0E48\u0E2A\u0E33\u0E40\u0E23\u0E47\u0E08: {message}",preview:"\u0E15\u0E31\u0E27\u0E2D\u0E22\u0E48\u0E32\u0E07\u0E1C\u0E25\u0E01\u0E32\u0E23\u0E04\u0E49\u0E19\u0E2B\u0E32",noTitle:"\u0E0A\u0E37\u0E48\u0E2D\u0E2B\u0E19\u0E49\u0E32",noDescription:"\u0E40\u0E1E\u0E34\u0E48\u0E21\u0E04\u0E33\u0E2D\u0E18\u0E34\u0E1A\u0E32\u0E22\u0E40\u0E1E\u0E37\u0E48\u0E2D\u0E01\u0E33\u0E2B\u0E19\u0E14\u0E02\u0E49\u0E2D\u0E04\u0E27\u0E32\u0E21\u0E43\u0E15\u0E49\u0E0A\u0E37\u0E48\u0E2D\u0E2B\u0E19\u0E49\u0E32"}},i=r=>r.replace(/[&<>"']/g,e=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"})[e]);function y(r){if(typeof Intl.Segmenter!="function")return[...r].length;let e=0;for(let t of new Intl.Segmenter(void 0,{granularity:"grapheme"}).segment(r))e++;return e}function x(r,e){let t=[...r];return t.length>e?`${t.slice(0,e-1).join("").trimEnd()}\u2026`:r}var w=`
1
+ var f="/seo/generate";var v=["value","path","doc","collection","global","id","locale","uiLocale","readOnly","options","api"],x={en:{characters:"{n} / {max} characters",empty:"Empty: search engines pick text from the page",short:"Short: aim for {min}\u2013{max}",good:"Good length",long:"Too long: may be cut off after {max}",generate:"Generate",generating:"Generating\u2026",generateImage:"Use image from content",noValue:"Nothing to generate from yet",failed:"Could not generate: {message}",preview:"Search result preview",noTitle:"Page title",noDescription:"Add a description to control the text under the title.",hidden:'Hidden from search engines: the page gets "noindex" and is left out of the sitemap.'},th:{characters:"{n} / {max} \u0E15\u0E31\u0E27\u0E2D\u0E31\u0E01\u0E29\u0E23",empty:"\u0E27\u0E48\u0E32\u0E07: \u0E40\u0E04\u0E23\u0E37\u0E48\u0E2D\u0E07\u0E21\u0E37\u0E2D\u0E04\u0E49\u0E19\u0E2B\u0E32\u0E08\u0E30\u0E40\u0E25\u0E37\u0E2D\u0E01\u0E02\u0E49\u0E2D\u0E04\u0E27\u0E32\u0E21\u0E08\u0E32\u0E01\u0E2B\u0E19\u0E49\u0E32\u0E40\u0E2D\u0E07",short:"\u0E2A\u0E31\u0E49\u0E19\u0E44\u0E1B: \u0E04\u0E27\u0E23\u0E22\u0E32\u0E27 {min}\u2013{max}",good:"\u0E04\u0E27\u0E32\u0E21\u0E22\u0E32\u0E27\u0E1E\u0E2D\u0E14\u0E35",long:"\u0E22\u0E32\u0E27\u0E44\u0E1B: \u0E2D\u0E32\u0E08\u0E16\u0E39\u0E01\u0E15\u0E31\u0E14\u0E2B\u0E25\u0E31\u0E07 {max}",generate:"\u0E2A\u0E23\u0E49\u0E32\u0E07\u0E43\u0E2B\u0E49",generating:"\u0E01\u0E33\u0E25\u0E31\u0E07\u0E2A\u0E23\u0E49\u0E32\u0E07\u2026",generateImage:"\u0E43\u0E0A\u0E49\u0E23\u0E39\u0E1B\u0E08\u0E32\u0E01\u0E40\u0E19\u0E37\u0E49\u0E2D\u0E2B\u0E32",noValue:"\u0E22\u0E31\u0E07\u0E44\u0E21\u0E48\u0E21\u0E35\u0E02\u0E49\u0E2D\u0E21\u0E39\u0E25\u0E43\u0E2B\u0E49\u0E2A\u0E23\u0E49\u0E32\u0E07",failed:"\u0E2A\u0E23\u0E49\u0E32\u0E07\u0E44\u0E21\u0E48\u0E2A\u0E33\u0E40\u0E23\u0E47\u0E08: {message}",preview:"\u0E15\u0E31\u0E27\u0E2D\u0E22\u0E48\u0E32\u0E07\u0E1C\u0E25\u0E01\u0E32\u0E23\u0E04\u0E49\u0E19\u0E2B\u0E32",noTitle:"\u0E0A\u0E37\u0E48\u0E2D\u0E2B\u0E19\u0E49\u0E32",noDescription:"\u0E40\u0E1E\u0E34\u0E48\u0E21\u0E04\u0E33\u0E2D\u0E18\u0E34\u0E1A\u0E32\u0E22\u0E40\u0E1E\u0E37\u0E48\u0E2D\u0E01\u0E33\u0E2B\u0E19\u0E14\u0E02\u0E49\u0E2D\u0E04\u0E27\u0E32\u0E21\u0E43\u0E15\u0E49\u0E0A\u0E37\u0E48\u0E2D\u0E2B\u0E19\u0E49\u0E32",hidden:'\u0E0B\u0E48\u0E2D\u0E19\u0E08\u0E32\u0E01\u0E40\u0E04\u0E23\u0E37\u0E48\u0E2D\u0E07\u0E21\u0E37\u0E2D\u0E04\u0E49\u0E19\u0E2B\u0E32\u0E2D\u0E22\u0E39\u0E48: \u0E2B\u0E19\u0E49\u0E32\u0E19\u0E35\u0E49\u0E21\u0E35 "noindex" \u0E41\u0E25\u0E30\u0E44\u0E21\u0E48\u0E2D\u0E22\u0E39\u0E48\u0E43\u0E19 sitemap'}},i=r=>r.replace(/[&<>"']/g,e=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"})[e]);function y(r){if(typeof Intl.Segmenter!="function")return[...r].length;let e=0;for(let t of new Intl.Segmenter(void 0,{granularity:"grapheme"}).segment(r))e++;return e}function b(r,e){let t=[...r];return t.length>e?`${t.slice(0,e-1).join("").trimEnd()}\u2026`:r}var w=`
2
2
  :host { display: block; font: inherit; color: var(--text); }
3
3
  .row { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
4
4
  .hint { margin: 0; font-size: 0.8rem; color: var(--text-muted); }
@@ -13,7 +13,7 @@ var f="/seo/generate";var v=["value","path","doc","collection","global","id","lo
13
13
  button:hover:not(:disabled) { background: var(--surface-2); }
14
14
  button:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
15
15
  button:disabled { opacity: 0.6; cursor: default; }
16
- `,d=class r extends HTMLElement{ctx={value:void 0,path:void 0,doc:{},collection:void 0,global:void 0,id:null,locale:null,uiLocale:"en",readOnly:!1,options:{},api:void 0};busy=!1;notice=null;queued=!1;html="";constructor(){super(),this.attachShadow({mode:"open"}).addEventListener("click",t=>{let n=t.target.closest("[data-action]")?.getAttribute("data-action");n&&this.onAction(n)})}static{for(let e of v)Object.defineProperty(r.prototype,e,{get(){return this.ctx[e]},set(t){this.ctx[e]=t,this.update()}})}connectedCallback(){this.update()}t(e,t={}){return(this.ctx.uiLocale==="th"?b.th:b.en)[e].replace(/\{(\w+)\}/g,(o,c)=>String(t[c]??""))}update(){this.queued||(this.queued=!0,queueMicrotask(()=>{this.queued=!1;let e=this.shadowRoot;if(!e)return;let t=`<style>${w}${this.css()}</style>${this.render()}`;if(t===this.html)return;let n=e.activeElement?.getAttribute("data-action");this.html=t,e.innerHTML=t,n&&e.querySelector(`[data-action="${n}"]`)?.focus()}))}async generate(e){let{api:t,collection:n,global:o,id:c,doc:s,locale:a}=this.ctx;return t?(await t("POST",f,{kind:e,...n?{collection:n}:{},...o?{global:o}:{},id:c,doc:s,locale:a})).value??null:null}async generateInto(e,t){if(!(!t||this.busy)){this.busy=!0,this.notice=null,this.update();try{let n=await this.generate(e);n===null||n===""?this.notice={text:this.t("noValue"),error:!1}:this.dispatchEvent(new CustomEvent("set-field",{detail:{path:t,value:n}}))}catch(n){this.notice={text:this.t("failed",{message:n.message}),error:!0}}finally{this.busy=!1,this.update()}}}renderNotice(){if(!this.notice)return"";let{text:e,error:t}=this.notice;return t?`<p class="error" role="alert">${i(e)}</p>`:`<p class="hint" role="status">${i(e)}</p>`}onAction(e){}css(){return""}},p=class extends d{css(){return`
16
+ `,d=class r extends HTMLElement{ctx={value:void 0,path:void 0,doc:{},collection:void 0,global:void 0,id:null,locale:null,uiLocale:"en",readOnly:!1,options:{},api:void 0};busy=!1;notice=null;queued=!1;html="";constructor(){super(),this.attachShadow({mode:"open"}).addEventListener("click",t=>{let n=t.target.closest("[data-action]")?.getAttribute("data-action");n&&this.onAction(n)})}static{for(let e of v)Object.defineProperty(r.prototype,e,{get(){return this.ctx[e]},set(t){this.ctx[e]=t,this.update()}})}connectedCallback(){this.update()}t(e,t={}){return(this.ctx.uiLocale==="th"?x.th:x.en)[e].replace(/\{(\w+)\}/g,(o,c)=>String(t[c]??""))}update(){this.queued||(this.queued=!0,queueMicrotask(()=>{this.queued=!1;let e=this.shadowRoot;if(!e)return;let t=`<style>${w}${this.css()}</style>${this.render()}`;if(t===this.html)return;let n=e.activeElement?.getAttribute("data-action");this.html=t,e.innerHTML=t,n&&e.querySelector(`[data-action="${n}"]`)?.focus()}))}async generate(e){let{api:t,collection:n,global:o,id:c,doc:s,locale:a}=this.ctx;return t?(await t("POST",f,{kind:e,...n?{collection:n}:{},...o?{global:o}:{},id:c,doc:s,locale:a})).value??null:null}async generateInto(e,t){if(!(!t||this.busy)){this.busy=!0,this.notice=null,this.update();try{let n=await this.generate(e);n===null||n===""?this.notice={text:this.t("noValue"),error:!1}:this.dispatchEvent(new CustomEvent("set-field",{detail:{path:t,value:n}}))}catch(n){this.notice={text:this.t("failed",{message:n.message}),error:!0}}finally{this.busy=!1,this.update()}}}renderNotice(){if(!this.notice)return"";let{text:e,error:t}=this.notice;return t?`<p class="error" role="alert">${i(e)}</p>`:`<p class="hint" role="status">${i(e)}</p>`}onAction(e){}css(){return""}},p=class extends d{css(){return`
17
17
  .bar { flex: 1 1 8rem; height: 4px; border-radius: 2px; background: var(--surface-2); overflow: hidden; }
18
18
  .fill { height: 100%; border-radius: 2px; }
19
19
  .empty .fill { background: var(--border-strong); }
@@ -42,11 +42,13 @@ var f="/seo/generate";var v=["value","path","doc","collection","global","id","lo
42
42
  .title { margin: 0.15rem 0; font-size: 1.15rem; line-height: 1.3; color: var(--info); }
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
+ .noindex { margin: 0.6rem 0 0; font-size: 0.8rem; color: var(--warning, var(--text-muted)); }
45
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`
46
47
  <section class="card" aria-label="${i(this.t("preview"))}">
47
48
  <p class="label">${i(this.t("preview"))}</p>
48
49
  ${l?`<p class="url">${i(l)}</p>`:""}
49
- <p class="title ${s?"":"placeholder"}">${i(x(s??this.t("noTitle"),60))}</p>
50
- <p class="description ${a?"":"placeholder"}">${i(a?x(a,160):this.t("noDescription"))}</p>
50
+ <p class="title ${s?"":"placeholder"}">${i(b(s??this.t("noTitle"),60))}</p>
51
+ <p class="description ${a?"":"placeholder"}">${i(a?b(a,160):this.t("noDescription"))}</p>
52
+ ${o.noindex===!0?`<p class="noindex">${i(this.t("hidden"))}</p>`:""}
51
53
  </section>
52
54
  `}refreshUrl(){let e=JSON.stringify([this.ctx.doc,this.ctx.locale]);e!==this.urlFor&&(this.urlFor=e,clearTimeout(this.timer),this.timer=setTimeout(async()=>{try{let t=await this.generate("url"),n=typeof t=="string"?t:"";n!==this.url&&(this.url=n,this.update())}catch{}},400))}};function k(r,e){if(e)return e.split(".").reduce((t,n)=>typeof t=="object"&&t!==null?t[n]:void 0,r)}function E(r){if(!r)return"";try{let{host:e,pathname:t}=new URL(r,"https://site.invalid"),n=t.split("/").filter(Boolean).map(decodeURIComponent);return[e==="site.invalid"?"":e,...n].filter(Boolean).join(" \u203A ")}catch{return r}}var m=(r,e)=>{customElements.get(r)||customElements.define(r,e)};m("ecms-seo-meter",p);m("ecms-seo-image",g);m("ecms-seo-preview",h);
package/dist/index.d.ts CHANGED
@@ -1,27 +1,40 @@
1
1
  import { EasyCMS, AuthUser, Field, Label, Plugin } from '@easy-cms/core';
2
2
 
3
- type Doc = Record<string, unknown>;
3
+ type Doc$1 = Record<string, unknown>;
4
+ type Value = string | null | undefined;
4
5
  interface SeoMetaOptions {
5
6
  /**
6
7
  * The site's public address, to make the canonical and image URLs absolute, e.g.
7
8
  * `https://example.com`. Default: `config.admin.siteUrl`, then `config.serverURL`.
8
9
  */
9
10
  readonly siteUrl?: string;
10
- /** Your Easy CMS config, to read `admin.siteUrl` (and `serverURL`) from. */
11
- readonly config?: {
12
- readonly admin?: {
13
- readonly siteUrl?: string;
14
- };
15
- readonly serverURL?: string;
16
- };
17
- /** The page's canonical address: absolute, or a path on the site. */
18
- readonly url?: string | ((doc: Doc) => string | null | undefined);
11
+ /** Your Easy CMS config, to read `admin.siteUrl`, `serverURL` and `localization` from. */
12
+ readonly config?: object;
13
+ /**
14
+ * The page's canonical address: absolute, or a path on the site. As a function it gets the
15
+ * locale too, which adds `hreflang` links to the page in every locale.
16
+ */
17
+ readonly url?: string | ((doc: Doc$1, locale?: string) => Value);
18
+ /** The page's content locale, e.g. `en`. Shown as `og:locale`. */
19
+ readonly locale?: string;
20
+ /** All content locales, for `hreflang`. Default: `config.localization.locales`. */
21
+ readonly locales?: readonly string[];
22
+ /** The locale for `x-default`. Default: `config.localization.defaultLocale`, then the first. */
23
+ readonly defaultLocale?: string;
19
24
  /** The title when `meta.title` is empty. Default: the document's `title`. */
20
- readonly title?: (doc: Doc) => string | null | undefined;
25
+ readonly title?: (doc: Doc$1) => Value;
21
26
  /** The description when `meta.description` is empty. Default: `excerpt`, then `description`. */
22
- readonly description?: (doc: Doc) => string | null | undefined;
27
+ readonly description?: (doc: Doc$1) => Value;
23
28
  /** Shown as `og:site_name`. */
24
29
  readonly siteName?: string;
30
+ /** `article` for posts: adds the published and modified times, and BlogPosting JSON-LD. */
31
+ readonly type?: 'website' | 'article';
32
+ /** When the article was published. Default: `publishedAt`, then `createdAt`. */
33
+ readonly publishedTime?: (doc: Doc$1) => Value;
34
+ /** The article's author, e.g. `(post) => post.author?.name`. */
35
+ readonly author?: string | ((doc: Doc$1) => Value);
36
+ /** Schema.org type of an article's JSON-LD. Default `BlogPosting`. */
37
+ readonly articleType?: 'Article' | 'BlogPosting' | 'NewsArticle';
25
38
  }
26
39
  interface SeoImage {
27
40
  readonly url: string;
@@ -33,34 +46,61 @@ interface SeoImage {
33
46
  interface NuxtSeoMeta {
34
47
  title?: string;
35
48
  description?: string;
49
+ robots?: string;
36
50
  ogTitle?: string;
37
51
  ogDescription?: string;
38
52
  ogUrl?: string;
39
- ogType?: 'website';
53
+ ogType?: 'website' | 'article';
40
54
  ogSiteName?: string;
55
+ ogLocale?: string;
56
+ ogLocaleAlternate?: string[];
41
57
  ogImage?: string;
42
58
  ogImageAlt?: string;
43
59
  ogImageWidth?: number;
44
60
  ogImageHeight?: number;
61
+ articlePublishedTime?: string;
62
+ articleModifiedTime?: string;
63
+ articleAuthor?: string[];
45
64
  twitterCard?: 'summary' | 'summary_large_image';
46
65
  twitterTitle?: string;
47
66
  twitterDescription?: string;
48
67
  twitterImage?: string;
49
68
  }
69
+ /** Input for Nuxt's `useHead()`: the canonical and hreflang links, and the JSON-LD script. */
70
+ interface NuxtSeoHead {
71
+ link: {
72
+ rel: 'canonical' | 'alternate';
73
+ href: string;
74
+ hreflang?: string;
75
+ }[];
76
+ script: {
77
+ type: 'application/ld+json';
78
+ innerHTML: string;
79
+ }[];
80
+ }
50
81
  /** The part of Next.js `Metadata` that `seoMeta` fills. */
51
82
  interface NextSeoMetadata {
52
83
  title?: string;
53
84
  description?: string;
85
+ robots?: {
86
+ index: false;
87
+ };
54
88
  alternates?: {
55
- canonical: string;
89
+ canonical?: string;
90
+ languages?: Record<string, string>;
56
91
  };
57
92
  openGraph: {
58
- type: 'website';
93
+ type: 'website' | 'article';
59
94
  title?: string;
60
95
  description?: string;
61
96
  url?: string;
62
97
  siteName?: string;
98
+ locale?: string;
99
+ alternateLocale?: string[];
63
100
  images?: SeoImage[];
101
+ publishedTime?: string;
102
+ modifiedTime?: string;
103
+ authors?: string[];
64
104
  };
65
105
  twitter: {
66
106
  card: 'summary' | 'summary_large_image';
@@ -69,14 +109,23 @@ interface NextSeoMetadata {
69
109
  images?: string[];
70
110
  };
71
111
  }
112
+ type JsonLd = Record<string, unknown>;
72
113
  interface SeoMeta {
73
114
  readonly title: string | undefined;
74
115
  readonly description: string | undefined;
75
116
  readonly canonical: string | undefined;
76
117
  readonly image: SeoImage | undefined;
77
- /** For Nuxt's `useSeoMeta()`. Add the canonical link with `useHead()`. */
118
+ /** The editor ticked "Hide from search engines". */
119
+ readonly noindex: boolean;
120
+ /** The page in each locale, and `x-default`; `undefined` without locales. */
121
+ readonly alternates: Readonly<Record<string, string>> | undefined;
122
+ /** Schema.org data for the page: BlogPosting (or `articleType`) for articles, else WebPage. */
123
+ readonly jsonLd: JsonLd;
124
+ /** For Nuxt's `useSeoMeta()`. */
78
125
  readonly nuxt: NuxtSeoMeta;
79
- /** For Next.js `generateMetadata()`. */
126
+ /** For Nuxt's `useHead()`: canonical and hreflang links, and the JSON-LD script. */
127
+ readonly head: NuxtSeoHead;
128
+ /** For Next.js `generateMetadata()`. Render `jsonLd` with `jsonLdScript()` in the page. */
80
129
  readonly next: NextSeoMetadata;
81
130
  }
82
131
  /**
@@ -84,12 +133,52 @@ interface SeoMeta {
84
133
  * document. Fetch the document with `depth` 1 or more so the share image has its URL.
85
134
  *
86
135
  * ```ts
87
- * const meta = seoMeta(post, { config, url: `/posts/${post.slug}` })
88
- * useSeoMeta(meta.nuxt) // Nuxt
89
- * return meta.next // Next.js generateMetadata()
136
+ * const meta = seoMeta(post, { config, locale, url: (p, l) => `/${l}/posts/${p.slug}`, type: 'article' })
137
+ * useSeoMeta(meta.nuxt); useHead(meta.head) // Nuxt
138
+ * return meta.next // Next.js generateMetadata()
90
139
  * ```
91
140
  */
92
- declare function seoMeta(doc: Doc, options?: SeoMetaOptions): SeoMeta;
141
+ declare function seoMeta(doc: Doc$1, options?: SeoMetaOptions): SeoMeta;
142
+ interface SiteJsonLdOptions {
143
+ /** The organization or site name. */
144
+ readonly name: string;
145
+ /** The site's address, e.g. `https://example.com`. */
146
+ readonly url: string;
147
+ /** Address of the logo image. */
148
+ readonly logo?: string;
149
+ /** Profiles elsewhere, e.g. Facebook or LinkedIn pages. */
150
+ readonly sameAs?: readonly string[];
151
+ /** The site's main language, e.g. `th`. */
152
+ readonly inLanguage?: string;
153
+ }
154
+ /** Organization and WebSite JSON-LD for the site's layout, once per page. */
155
+ declare function siteJsonLd(options: SiteJsonLdOptions): JsonLd;
156
+ /**
157
+ * JSON-LD as text for a `<script type="application/ld+json">`, safe to put in HTML: `<` and
158
+ * line separators are escaped, so content can't close the script tag.
159
+ */
160
+ declare function jsonLdScript(value: JsonLd): string;
161
+
162
+ interface RobotsTxtOptions {
163
+ /** Your Easy CMS config, for the admin and API paths and `admin.siteUrl`. */
164
+ readonly config?: object;
165
+ /** The site's public address, for the `Sitemap:` line. Default `admin.siteUrl`, then `serverURL`. */
166
+ readonly siteUrl?: string;
167
+ /** The sitemap's address, or `false` for none. Default `<siteUrl>/sitemap.xml`. */
168
+ readonly sitemap?: string | false;
169
+ /**
170
+ * Ask search engines to stay out of the whole site, e.g. on a staging copy. Not turned on by
171
+ * `NODE_ENV`: staging servers usually run in production mode too, so set it yourself.
172
+ */
173
+ readonly disallowAll?: boolean;
174
+ /** More paths to keep out of search, e.g. `['/search']`. */
175
+ readonly disallow?: readonly string[];
176
+ }
177
+ /**
178
+ * A `robots.txt` that keeps search engines out of the admin and the API (except uploaded
179
+ * files, so share images still work) and points them to the sitemap.
180
+ */
181
+ declare function robotsTxt(options?: RobotsTxtOptions): string;
93
182
 
94
183
  type MaybePromise<T> = T | Promise<T>;
95
184
  interface GenerateArgs {
@@ -140,6 +229,11 @@ interface SeoPluginOptions {
140
229
  readonly localized?: boolean;
141
230
  /** Label of the group. Default "SEO". */
142
231
  readonly label?: Label;
232
+ /**
233
+ * `robots.txt` for the standalone server (`easy-cms serve`), or `false` for none. Nuxt and
234
+ * Next.js apps serve their own with `robotsTxt()`.
235
+ */
236
+ readonly robots?: Omit<RobotsTxtOptions, 'config'> | false;
143
237
  }
144
238
  /**
145
239
  * Adds a `meta` group (title, description, image) to the chosen collections and globals,
@@ -158,4 +252,63 @@ declare const DEFAULT_DESCRIPTION_LENGTH: {
158
252
  readonly max: 150;
159
253
  };
160
254
 
161
- export { DEFAULT_DESCRIPTION_LENGTH, DEFAULT_TITLE_LENGTH, type Generate, type GenerateArgs, type NextSeoMetadata, type NuxtSeoMeta, type SeoImage, type SeoMeta, type SeoMetaOptions, type SeoPluginOptions, seoMeta, seoPlugin };
255
+ type Doc = Record<string, unknown>;
256
+ /** The part of the Local API `sitemap()` uses; a structural type, so core isn't imported. */
257
+ interface SitemapCMS {
258
+ readonly config: {
259
+ readonly admin: {
260
+ readonly siteUrl?: string;
261
+ };
262
+ readonly serverURL?: string;
263
+ readonly localization: {
264
+ readonly locales: readonly string[];
265
+ readonly defaultLocale: string;
266
+ } | null;
267
+ readonly endpoints: readonly {
268
+ readonly handler: unknown;
269
+ }[];
270
+ };
271
+ find(collection: string, options: Record<string, unknown>): Promise<{
272
+ docs: Doc[];
273
+ hasNextPage: boolean;
274
+ }>;
275
+ findGlobal(global: string, options: Record<string, unknown>): Promise<Doc>;
276
+ }
277
+ /** One page in the sitemap, in the shape of Next.js `MetadataRoute.Sitemap`. */
278
+ interface SitemapEntry {
279
+ readonly url: string;
280
+ /** ISO date of the last change (`updatedAt`). */
281
+ readonly lastModified?: string;
282
+ /** The page in each content locale, and `x-default`. */
283
+ readonly alternates?: {
284
+ readonly languages: Readonly<Record<string, string>>;
285
+ };
286
+ }
287
+ interface SitemapOptions {
288
+ /**
289
+ * The site's public address, to make relative URLs from `generateURL` absolute. Default:
290
+ * `admin.siteUrl`, then `serverURL`.
291
+ */
292
+ readonly siteUrl?: string;
293
+ }
294
+ interface SitemapXmlOptions extends SitemapOptions {
295
+ /** Which part of a large sitemap (over 50,000 URLs) to render, from 1. */
296
+ readonly page?: number | string | null;
297
+ /** Address of this sitemap, for the index of a large one. Default `<siteUrl>/sitemap.xml`. */
298
+ readonly base?: string;
299
+ }
300
+ /** Google's limit of URLs in one sitemap file. */
301
+ declare const SITEMAP_LIMIT = 50000;
302
+ /**
303
+ * Every page with SEO fields that a visitor can see: documents read without a login (so only
304
+ * published ones, as the read access allows), with a URL from `generateURL` and not hidden with
305
+ * "noindex". Returns the shape Next.js `app/sitemap.ts` expects.
306
+ */
307
+ declare function sitemap(cms: SitemapCMS, options?: SitemapOptions): Promise<SitemapEntry[]>;
308
+ /**
309
+ * The sitemap as XML. Over 50,000 URLs, it is an index of pages `<base>?page=1`, `?page=2`…,
310
+ * and `page` renders one of them.
311
+ */
312
+ declare function sitemapXml(cms: SitemapCMS, options?: SitemapXmlOptions): Promise<string>;
313
+
314
+ export { DEFAULT_DESCRIPTION_LENGTH, DEFAULT_TITLE_LENGTH, type Generate, type GenerateArgs, type JsonLd, type NextSeoMetadata, type NuxtSeoHead, type NuxtSeoMeta, type RobotsTxtOptions, SITEMAP_LIMIT, type SeoImage, type SeoMeta, type SeoMetaOptions, type SeoPluginOptions, type SiteJsonLdOptions, type SitemapEntry, type SitemapOptions, type SitemapXmlOptions, jsonLdScript, robotsTxt, seoMeta, seoPlugin, siteJsonLd, sitemap, sitemapXml };
package/dist/index.js CHANGED
@@ -5,19 +5,182 @@ var META_FIELD = "meta";
5
5
  var GENERATE_PATH = "/seo/generate";
6
6
  var GENERATE_KINDS = ["title", "description", "image", "url"];
7
7
 
8
- // src/meta.ts
9
- var text = (value) => typeof value === "string" && value.trim() !== "" ? value.trim() : void 0;
8
+ // src/sitemap.ts
9
+ var SITEMAP_SOURCE = /* @__PURE__ */ Symbol.for("easy-cms.plugin-seo.sitemap");
10
+ var SITEMAP_LIMIT = 5e4;
11
+ var BATCH = 500;
12
+ async function sitemap(cms, options = {}) {
13
+ const source = findSource(cms);
14
+ const site = options.siteUrl ?? (cms.config.admin.siteUrl || cms.config.serverURL);
15
+ const localization = cms.config.localization;
16
+ const locales = localization ? [...localization.locales] : [null];
17
+ const generateURL = source.generateURL;
18
+ if (!generateURL) return [];
19
+ const pages = /* @__PURE__ */ new Map();
20
+ const add = async (key, doc, locale, target) => {
21
+ if (doc[META_FIELD]?.noindex === true) return;
22
+ const id = doc.id ?? null;
23
+ const url = await generateURL({
24
+ doc,
25
+ id,
26
+ locale,
27
+ cms,
28
+ user: null,
29
+ ...target
30
+ });
31
+ if (typeof url !== "string" || url.trim() === "") return;
32
+ const page = pages.get(key) ?? { urls: /* @__PURE__ */ new Map() };
33
+ page.urls.set(locale, absolute(url.trim(), site));
34
+ if (typeof doc.updatedAt === "string") page.lastModified = doc.updatedAt;
35
+ pages.set(key, page);
36
+ };
37
+ for (const collection of source.collections) {
38
+ for (const locale of locales) {
39
+ for (let page = 1; ; page++) {
40
+ const result = await visitor(
41
+ () => cms.find(collection, {
42
+ overrideAccess: false,
43
+ user: null,
44
+ depth: 0,
45
+ sort: "id",
46
+ limit: BATCH,
47
+ page,
48
+ ...locale ? { locale } : {}
49
+ })
50
+ );
51
+ if (!result) break;
52
+ for (const doc of result.docs)
53
+ await add(`c:${collection}:${doc.id}`, doc, locale, { collection });
54
+ if (!result.hasNextPage) break;
55
+ }
56
+ }
57
+ }
58
+ for (const global of source.globals) {
59
+ for (const locale of locales) {
60
+ const doc = await visitor(
61
+ () => cms.findGlobal(global, {
62
+ overrideAccess: false,
63
+ user: null,
64
+ depth: 0,
65
+ ...locale ? { locale } : {}
66
+ })
67
+ );
68
+ if (doc && doc.status !== "draft") await add(`g:${global}`, doc, locale, { global });
69
+ }
70
+ }
71
+ const entries = [];
72
+ for (const { urls, lastModified } of pages.values()) {
73
+ const distinct = new Set(urls.values());
74
+ const languages = {};
75
+ if (localization && distinct.size > 1) {
76
+ for (const [locale, url] of urls) languages[locale] = url;
77
+ const fallback = urls.get(localization.defaultLocale);
78
+ if (fallback) languages["x-default"] = fallback;
79
+ }
80
+ for (const url of distinct) {
81
+ if (!/^https?:\/\//.test(url))
82
+ throw new Error(
83
+ `sitemap: "${url}" is not an absolute URL. Set admin.siteUrl in the config, or pass siteUrl.`
84
+ );
85
+ entries.push({
86
+ url,
87
+ ...lastModified ? { lastModified } : {},
88
+ ...Object.keys(languages).length > 0 ? { alternates: { languages } } : {}
89
+ });
90
+ }
91
+ }
92
+ return entries;
93
+ }
94
+ async function sitemapXml(cms, options = {}) {
95
+ const entries = await sitemap(cms, options);
96
+ const page = Number(options.page ?? 0);
97
+ if (entries.length > SITEMAP_LIMIT && !(page >= 1)) {
98
+ const site = options.siteUrl ?? (cms.config.admin.siteUrl || cms.config.serverURL) ?? "";
99
+ const base = options.base ?? `${site.replace(/\/+$/, "")}/sitemap.xml`;
100
+ const pages = Math.ceil(entries.length / SITEMAP_LIMIT);
101
+ const items = Array.from(
102
+ { length: pages },
103
+ (_, i) => ` <sitemap><loc>${xml(`${base}?page=${i + 1}`)}</loc></sitemap>`
104
+ );
105
+ return `<?xml version="1.0" encoding="UTF-8"?>
106
+ <sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
107
+ ${items.join("\n")}
108
+ </sitemapindex>
109
+ `;
110
+ }
111
+ const slice = entries.length > SITEMAP_LIMIT ? entries.slice((page - 1) * SITEMAP_LIMIT, page * SITEMAP_LIMIT) : entries;
112
+ const localized = slice.some((e) => e.alternates);
113
+ const urls = slice.map((entry) => {
114
+ const lines = [` <loc>${xml(entry.url)}</loc>`];
115
+ if (entry.lastModified) lines.push(` <lastmod>${xml(entry.lastModified)}</lastmod>`);
116
+ for (const [lang, href] of Object.entries(entry.alternates?.languages ?? {}))
117
+ lines.push(` <xhtml:link rel="alternate" hreflang="${xml(lang)}" href="${xml(href)}"/>`);
118
+ return ` <url>
119
+ ${lines.join("\n")}
120
+ </url>`;
121
+ });
122
+ const namespaces = `xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"${localized ? ' xmlns:xhtml="http://www.w3.org/1999/xhtml"' : ""}`;
123
+ return `<?xml version="1.0" encoding="UTF-8"?>
124
+ <urlset ${namespaces}>
125
+ ${urls.join("\n")}
126
+ </urlset>
127
+ `;
128
+ }
129
+ function findSource(cms) {
130
+ for (const endpoint of cms.config.endpoints) {
131
+ const source = endpoint.handler[SITEMAP_SOURCE];
132
+ if (source) return source;
133
+ }
134
+ throw new Error("sitemap: add seoPlugin() to the plugins in your Easy CMS config");
135
+ }
136
+ async function visitor(read) {
137
+ try {
138
+ return await read();
139
+ } catch (error2) {
140
+ const status = error2.status;
141
+ if (status === 401 || status === 403 || status === 404) return void 0;
142
+ throw error2;
143
+ }
144
+ }
10
145
  function absolute(url, site) {
11
146
  if (/^https?:\/\//.test(url) || !site || !/^https?:\/\//.test(site)) return url;
12
147
  return `${site.replace(/\/+$/, "")}/${url.replace(/^\/+/, "")}`;
13
148
  }
149
+ var xml = (value) => value.replace(
150
+ /[&<>"']/g,
151
+ (c) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&apos;" })[c]
152
+ );
153
+
154
+ // src/meta.ts
155
+ var text = (value) => typeof value === "string" && value.trim() !== "" ? value.trim() : void 0;
156
+ var ogLocale = (locale) => locale.replace("-", "_");
157
+ var defined = (record) => Object.fromEntries(Object.entries(record).filter(([, v]) => v !== void 0));
14
158
  function seoMeta(doc, options = {}) {
159
+ const config = options.config;
15
160
  const meta = doc[META_FIELD] ?? {};
16
- const site = options.siteUrl ?? options.config?.admin?.siteUrl ?? options.config?.serverURL;
161
+ const site = options.siteUrl ?? (config?.admin?.siteUrl || config?.serverURL);
17
162
  const title = text(meta.title) ?? text((options.title ?? ((d) => d.title))(doc));
18
163
  const description = text(meta.description) ?? text((options.description ?? ((d) => d.excerpt ?? d.description))(doc));
19
- const url = typeof options.url === "function" ? options.url(doc) : options.url;
20
- const canonical = text(url) ? absolute(text(url), site) : void 0;
164
+ const noindex = meta.noindex === true;
165
+ const article = options.type === "article";
166
+ const locale = options.locale;
167
+ const locales = options.locales ?? config?.localization?.locales ?? [];
168
+ const urlFor = (l) => {
169
+ const url = typeof options.url === "function" ? options.url(doc, l) : options.url;
170
+ return text(url) ? absolute(text(url), site) : void 0;
171
+ };
172
+ const canonical = urlFor(locale);
173
+ let alternates;
174
+ if (typeof options.url === "function" && locales.length > 1) {
175
+ alternates = {};
176
+ for (const l of locales) {
177
+ const url = urlFor(l);
178
+ if (url) alternates[l] = url;
179
+ }
180
+ const fallback = options.defaultLocale ?? config?.localization?.defaultLocale ?? locales[0];
181
+ if (fallback && alternates[fallback]) alternates["x-default"] = alternates[fallback];
182
+ if (Object.keys(alternates).length === 0) alternates = void 0;
183
+ }
21
184
  const media = meta.image;
22
185
  const image = typeof media === "object" && media !== null && text(media.url) ? {
23
186
  url: absolute(text(media.url), site),
@@ -25,25 +188,67 @@ function seoMeta(doc, options = {}) {
25
188
  ...typeof media.width === "number" ? { width: media.width } : {},
26
189
  ...typeof media.height === "number" ? { height: media.height } : {}
27
190
  } : void 0;
28
- const defined = (record) => Object.fromEntries(Object.entries(record).filter(([, v]) => v !== void 0));
191
+ const publishedTime = article ? text((options.publishedTime ?? ((d) => d.publishedAt ?? d.createdAt))(doc)) : void 0;
192
+ const modifiedTime = article ? text(doc.updatedAt) : void 0;
193
+ const author = article ? text(typeof options.author === "function" ? options.author(doc) : options.author) : void 0;
194
+ const otherLocales = locale ? locales.filter((l) => l !== locale).map(ogLocale) : [];
29
195
  const card = image ? "summary_large_image" : "summary";
196
+ const type = article ? "article" : "website";
197
+ const jsonLd = article ? defined({
198
+ "@context": "https://schema.org",
199
+ "@type": options.articleType ?? "BlogPosting",
200
+ headline: title,
201
+ description,
202
+ image: image ? [image.url] : void 0,
203
+ datePublished: publishedTime,
204
+ dateModified: modifiedTime,
205
+ author: author ? { "@type": "Person", name: author } : void 0,
206
+ mainEntityOfPage: canonical,
207
+ url: canonical,
208
+ inLanguage: locale
209
+ }) : defined({
210
+ "@context": "https://schema.org",
211
+ "@type": "WebPage",
212
+ name: title,
213
+ description,
214
+ url: canonical,
215
+ primaryImageOfPage: image ? image.url : void 0,
216
+ inLanguage: locale
217
+ });
218
+ const link = [];
219
+ if (canonical) link.push({ rel: "canonical", href: canonical });
220
+ for (const [hreflang, href] of Object.entries(alternates ?? {}))
221
+ link.push({ rel: "alternate", hreflang, href });
30
222
  return {
31
223
  title,
32
224
  description,
33
225
  canonical,
34
226
  image,
227
+ noindex,
228
+ alternates,
229
+ jsonLd,
230
+ head: {
231
+ link,
232
+ script: [{ type: "application/ld+json", innerHTML: jsonLdScript(jsonLd) }]
233
+ },
35
234
  nuxt: defined({
36
235
  title,
37
236
  description,
237
+ robots: noindex ? "noindex" : void 0,
38
238
  ogTitle: title,
39
239
  ogDescription: description,
40
240
  ogUrl: canonical,
41
- ogType: "website",
241
+ ogType: type,
42
242
  ogSiteName: options.siteName,
243
+ ogLocale: locale ? ogLocale(locale) : void 0,
244
+ ogLocaleAlternate: otherLocales.length > 0 ? otherLocales : void 0,
43
245
  ogImage: image?.url,
44
246
  ogImageAlt: image?.alt,
45
247
  ogImageWidth: image?.width,
46
248
  ogImageHeight: image?.height,
249
+ articlePublishedTime: publishedTime,
250
+ articleModifiedTime: modifiedTime,
251
+ articleAuthor: author ? [author] : void 0,
47
252
  twitterCard: card,
48
253
  twitterTitle: title,
49
254
  twitterDescription: description,
@@ -52,14 +257,20 @@ function seoMeta(doc, options = {}) {
52
257
  next: defined({
53
258
  title,
54
259
  description,
55
- alternates: canonical ? { canonical } : void 0,
260
+ robots: noindex ? { index: false } : void 0,
261
+ alternates: canonical || alternates ? defined({ canonical, languages: alternates ? { ...alternates } : void 0 }) : void 0,
56
262
  openGraph: defined({
57
263
  title,
58
264
  description,
59
265
  url: canonical,
60
266
  siteName: options.siteName,
61
- type: "website",
62
- images: image ? [image] : void 0
267
+ locale: locale ? ogLocale(locale) : void 0,
268
+ alternateLocale: otherLocales.length > 0 ? otherLocales : void 0,
269
+ type,
270
+ images: image ? [image] : void 0,
271
+ publishedTime,
272
+ modifiedTime,
273
+ authors: author ? [author] : void 0
63
274
  }),
64
275
  twitter: defined({
65
276
  card,
@@ -70,6 +281,53 @@ function seoMeta(doc, options = {}) {
70
281
  })
71
282
  };
72
283
  }
284
+ function siteJsonLd(options) {
285
+ const url = options.url.replace(/\/+$/, "");
286
+ return {
287
+ "@context": "https://schema.org",
288
+ "@graph": [
289
+ defined({
290
+ "@type": "Organization",
291
+ "@id": `${url}/#organization`,
292
+ name: options.name,
293
+ url: `${url}/`,
294
+ logo: options.logo,
295
+ sameAs: options.sameAs && options.sameAs.length > 0 ? [...options.sameAs] : void 0
296
+ }),
297
+ defined({
298
+ "@type": "WebSite",
299
+ "@id": `${url}/#website`,
300
+ name: options.name,
301
+ url: `${url}/`,
302
+ inLanguage: options.inLanguage,
303
+ publisher: { "@id": `${url}/#organization` }
304
+ })
305
+ ]
306
+ };
307
+ }
308
+ function jsonLdScript(value) {
309
+ return JSON.stringify(value).replace(/</g, "\\u003c").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
310
+ }
311
+
312
+ // src/robots.ts
313
+ function robotsTxt(options = {}) {
314
+ const config = options.config;
315
+ const trim = (path) => `/${path.replace(/^\/+|\/+$/g, "")}`;
316
+ const admin = trim(config?.admin?.path ?? "/admin");
317
+ const api = trim(config?.routes?.api ?? "/api/cms");
318
+ const site = options.siteUrl ?? (config?.admin?.siteUrl || config?.serverURL);
319
+ const lines = ["User-agent: *"];
320
+ if (options.disallowAll) {
321
+ lines.push("Disallow: /");
322
+ } else {
323
+ lines.push(`Allow: ${api}/media/file/`, `Disallow: ${admin}/`, `Disallow: ${api}/`);
324
+ for (const path of options.disallow ?? []) lines.push(`Disallow: ${path}`);
325
+ }
326
+ const sitemap2 = options.sitemap === false ? void 0 : options.sitemap ?? (site ? `${site.replace(/\/+$/, "")}/sitemap.xml` : void 0);
327
+ if (sitemap2) lines.push("", `Sitemap: ${sitemap2}`);
328
+ return `${lines.join("\n")}
329
+ `;
330
+ }
73
331
 
74
332
  // src/plugin.ts
75
333
  var ADMIN_MODULE = "@easy-cms/plugin-seo/admin";
@@ -130,6 +388,11 @@ function seoPlugin(options = {}) {
130
388
  ]
131
389
  }
132
390
  } : {}
391
+ },
392
+ {
393
+ name: "noindex",
394
+ type: "boolean",
395
+ label: { en: "Hide from search engines", th: "\u0E0B\u0E48\u0E2D\u0E19\u0E08\u0E32\u0E01\u0E40\u0E04\u0E23\u0E37\u0E48\u0E2D\u0E07\u0E21\u0E37\u0E2D\u0E04\u0E49\u0E19\u0E2B\u0E32" }
133
396
  }
134
397
  ];
135
398
  return {
@@ -210,6 +473,56 @@ function seoPlugin(options = {}) {
210
473
  return { value: value ?? null };
211
474
  }
212
475
  };
476
+ const source = {
477
+ collections,
478
+ globals,
479
+ generateURL: generators.url
480
+ };
481
+ const xmlResponse = (body) => new Response(body, {
482
+ headers: {
483
+ "content-type": "application/xml; charset=utf-8",
484
+ "cache-control": "public, max-age=600"
485
+ }
486
+ });
487
+ const api = config.routes?.api ?? "/api/cms";
488
+ const sitemapHandler = (base) => Object.assign(
489
+ async ({ url, cms }) => {
490
+ const site = config.admin?.siteUrl || config.serverURL || url.origin;
491
+ return xmlResponse(
492
+ await sitemapXml(cms, {
493
+ siteUrl: site,
494
+ page: url.searchParams.get("page"),
495
+ base: base(url.origin)
496
+ })
497
+ );
498
+ },
499
+ // Lets `sitemap(cms)` find these options from the resolved config.
500
+ { [SITEMAP_SOURCE]: source }
501
+ );
502
+ const siteEndpoints = [
503
+ {
504
+ path: "/seo/sitemap.xml",
505
+ method: "get",
506
+ handler: sitemapHandler((origin) => `${origin}${api}/seo/sitemap.xml`)
507
+ },
508
+ {
509
+ path: "/sitemap.xml",
510
+ method: "get",
511
+ root: true,
512
+ handler: sitemapHandler((origin) => `${origin}/sitemap.xml`)
513
+ }
514
+ ];
515
+ if (options.robots !== false) {
516
+ const robots = options.robots ?? {};
517
+ siteEndpoints.push({
518
+ path: "/robots.txt",
519
+ method: "get",
520
+ root: true,
521
+ handler: ({ url }) => new Response(robotsTxt({ sitemap: `${url.origin}/sitemap.xml`, ...robots, config }), {
522
+ headers: { "content-type": "text/plain; charset=utf-8" }
523
+ })
524
+ });
525
+ }
213
526
  return {
214
527
  ...config,
215
528
  collections: (config.collections ?? []).map(
@@ -220,7 +533,7 @@ function seoPlugin(options = {}) {
220
533
  ...config.admin,
221
534
  modules: [.../* @__PURE__ */ new Set([...config.admin?.modules ?? [], ADMIN_MODULE])]
222
535
  },
223
- endpoints: [...config.endpoints ?? [], endpoint]
536
+ endpoints: [...config.endpoints ?? [], endpoint, ...siteEndpoints]
224
537
  };
225
538
  };
226
539
  }
@@ -231,6 +544,12 @@ function error(status, message) {
231
544
  export {
232
545
  DEFAULT_DESCRIPTION_LENGTH,
233
546
  DEFAULT_TITLE_LENGTH,
547
+ SITEMAP_LIMIT,
548
+ jsonLdScript,
549
+ robotsTxt,
234
550
  seoMeta,
235
- seoPlugin
551
+ seoPlugin,
552
+ siteJsonLd,
553
+ sitemap,
554
+ sitemapXml
236
555
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easy-cms/plugin-seo",
3
- "version": "0.16.0",
3
+ "version": "0.17.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,12 +17,12 @@
17
17
  "dist"
18
18
  ],
19
19
  "peerDependencies": {
20
- "@easy-cms/core": "^0.16.0"
20
+ "@easy-cms/core": "^0.17.0"
21
21
  },
22
22
  "devDependencies": {
23
23
  "happy-dom": "^20.14.5",
24
- "@easy-cms/core": "^0.16.0",
25
- "@easy-cms/db-sqlite": "^0.16.0"
24
+ "@easy-cms/core": "^0.17.0",
25
+ "@easy-cms/db-sqlite": "^0.17.0"
26
26
  },
27
27
  "engines": {
28
28
  "node": ">=22.12"