@moorage/plugin-seo 0.1.7 → 0.1.8

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/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # @moorage/plugin-seo
2
2
 
3
+ ## 0.1.8
4
+
5
+ ### Patch Changes
6
+
7
+ - 961b4b9: Your SEO settings now stay put when your site moves the plugin between running in-process (`plugins: []`) and sandboxed (`sandboxed: []`). EmDash keeps most plugin data in a different place in each mode, so before this the Settings tab came back empty after a switch, and the old values only returned when you switched back. Settings are now kept where EmDash finds them in both modes.
8
+
9
+ Nothing to do on your side: the first page view or visit to the SEO page after updating copies your settings to the new place. Update first, open the SEO page once, and only then switch modes. Each save also keeps a copy where earlier versions look, so going back to 0.1.7 still shows your latest settings. If you go back, change settings there and then update again, the update shows the settings from before you went back; save them again.
10
+
11
+ - a9004ee: The warning that two pages share a title no longer disappears by itself. When a page was saved while "Check my pages" was running, or two pages with the same title were saved at the same moment, one of them could lose the warning (or keep it after a rename) until the next check. A save now reads the pages with its title after writing, and a check no longer writes over a page saved after it read that page, so the warning ends up on exactly the pages that share a title.
12
+
13
+ - A page deleted while "Check my pages" was running no longer lingers in the SEO page's counts, and no longer keeps another page flagged for sharing its title. At the end of each full check, the plugin now removes what it kept about pages the check did not find, then settles the title warnings; pages created or saved during the check are left alone. This only ever showed in the admin, never on the public site.
14
+ - The Google preview panel no longer risks hitting Cloudflare's limit of 10 operations per request when a page's title and its page type are changed together. The panel now leaves moving the "same title" warning between pages to the save itself (or the next check), as it already did in the usual case.
15
+ - The end-of-check cleanup above now asks EmDash about each page before removing what the plugin kept about it. A page that was unpublished, or whose record a page view wrote back, while the check ran keeps its record and the page type an admin picked; an unpublished one is simply counted as a draft.
16
+ - Saving a page that moves it from one shared title to another could take 11 operations on a site whose SEO settings were never saved, over Cloudflare's limit of 10 per request, so the "same title" warnings were not updated for that save. Such a save now reads both titles at once and stays at 9 at most.
17
+
3
18
  ## 0.1.7
4
19
 
5
20
  ### Patch Changes
package/README.md CHANGED
@@ -30,7 +30,7 @@ export default defineConfig({
30
30
  });
31
31
  ```
32
32
 
33
- `sandboxed` needs a sandbox runner: on Cloudflare it is the Worker Loader binding from `@emdash-cms/cloudflare`; on Node add `@emdash-cms/sandbox-workerd` and set `sandboxRunner: "@emdash-cms/sandbox-workerd/sandbox"`. Without a runner, list the plugin under `plugins: [seo]` instead, which runs it in-process. Requires EmDash 1.2.0 or newer.
33
+ `sandboxed` needs a sandbox runner: on Cloudflare it is the Worker Loader binding from `@emdash-cms/cloudflare`; on Node add `@emdash-cms/sandbox-workerd` and set `sandboxRunner: "@emdash-cms/sandbox-workerd/sandbox"`. Without a runner, list the plugin under `plugins: [seo]` instead, which runs it in-process. Requires EmDash 1.2.0 or newer. Since 0.1.8 your settings survive moving the plugin from one list to the other; when updating from an earlier version, update first, open the SEO page once, then move it.
34
34
 
35
35
  **On Cloudflare's Workers free plan** each request gets about 10 ms of CPU. EmDash's own saving and publishing already comes close to that, and every plugin run in the site's process adds a little, so a save or publish can now and then fail with "Worker exceeded resource limits"; trying again works. Workers Paid (30 seconds per request) does not have this problem.
36
36
 
package/dist/index.mjs CHANGED
@@ -7,7 +7,7 @@
7
7
  /** @type {import("emdash").PluginDescriptor} */
8
8
  const descriptor = Object.freeze({
9
9
  "id": "seo",
10
- "version": "0.1.7",
10
+ "version": "0.1.8",
11
11
  "format": "standard",
12
12
  "entrypoint": "@moorage/plugin-seo/sandbox",
13
13
  "capabilities": [
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "id": "seo",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "declaredAccess": {
5
5
  "content": {
6
6
  "read": {}
package/dist/plugin.mjs CHANGED
@@ -1,6 +1,6 @@
1
- function e(e,t){try{return new URL(e,t)}catch{return null}}const t=`config`,n=[`WebPage`,`AboutPage`,`ContactPage`,`CollectionPage`,`ProfilePage`],r=[`Article`,`BlogPosting`,`NewsArticle`],i=[`Service`];function a(e){let t=e.toLowerCase();return[`posts`,`post`,`blog`].includes(t)?`BlogPosting`:[`news`,`articles`,`article`].includes(t)?`Article`:[`services`,`service`].includes(t)?`Service`:[`team`,`people`,`staff`,`authors`].includes(t)?`ProfilePage`:`WebPage`}const o={site:{type:`Organization`,sameAs:[],openingHours:[],areaServed:[]},collections:{},robots:{maxSnippet:-1,maxImagePreview:`large`,maxVideoPreview:-1,nosnippet:!1},jsonLdField:`json_ld`,breadcrumbs:!0,steps:{identity:!1,types:!1}};function s(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function c(e){if(typeof e!=`string`)return;let t=e.trim();return t===``?void 0:t}function l(t){let n=c(t),r=n?e(n)?.protocol:void 0;return r===`https:`||r===`http:`?n:void 0}function u(e,t){return typeof e==`number`&&Number.isInteger(e)&&e>=-1?e:t}function d(e){let t=[...n,...r,...i];return typeof e==`string`&&t.includes(e)?e:void 0}function f(e){if(!s(e))return;let t={};for(let n of[`streetAddress`,`addressLocality`,`addressRegion`,`postalCode`,`addressCountry`]){let r=c(e[n]);r&&(t[n]=r)}return Object.keys(t).length>0?t:void 0}function p(e){if(!Array.isArray(e))return[];let t=[];for(let n of e){if(!s(n)||!Array.isArray(n.days))continue;let e=n.days.filter(e=>typeof e==`string`&&e!==``),r=c(n.opens),i=c(n.closes);e.length>0&&r&&i&&t.push({days:e,opens:r,closes:i})}return t}function m(e){if(!s(e))return{...o.site};let t=s(e.geo)?e.geo:void 0,n=t?.latitude,r=t?.longitude;return{type:c(e.type)??`Organization`,name:c(e.name),alternateName:c(e.alternateName),legalName:c(e.legalName),description:c(e.description),logo:l(e.logo),sameAs:Array.isArray(e.sameAs)?e.sameAs.map(l).filter(e=>e!==void 0):[],email:c(e.email),telephone:c(e.telephone),address:f(e.address),geo:typeof n==`number`&&typeof r==`number`?{latitude:n,longitude:r}:void 0,openingHours:p(e.openingHours),priceRange:c(e.priceRange),areaServed:Array.isArray(e.areaServed)?e.areaServed.map(c).filter(e=>e!==void 0):[],foundingDate:c(e.foundingDate),vatID:c(e.vatID),taxID:c(e.taxID),numberOfEmployees:typeof e.numberOfEmployees==`number`&&e.numberOfEmployees>0?Math.round(e.numberOfEmployees):void 0}}function h(e){if(!s(e))return o;let t={};if(s(e.collections))for(let[n,r]of Object.entries(e.collections))s(r)&&(t[n]={type:d(r.type),noindex:r.noindex===!0,...r.hiddenOk===!0?{hiddenOk:!0}:{}});let n=s(e.robots)?e.robots:{},r=n.maxImagePreview;return{site:m(e.site),collections:t,robots:{maxSnippet:u(n.maxSnippet,o.robots.maxSnippet),maxImagePreview:r===`none`||r===`standard`||r===`large`?r:o.robots.maxImagePreview,maxVideoPreview:u(n.maxVideoPreview,o.robots.maxVideoPreview),nosnippet:n.nosnippet===!0},jsonLdField:c(e.jsonLdField)??o.jsonLdField,breadcrumbs:e.breadcrumbs!==!1,steps:{identity:s(e.steps)&&e.steps.identity===!0,types:s(e.steps)&&e.steps.types===!0}}}const g=[`Monday`,`Tuesday`,`Wednesday`,`Thursday`,`Friday`,`Saturday`,`Sunday`],_=/^(\d{1,2})(?:[:.](\d{2}))?\s*[-–—]\s*(\d{1,2})(?:[:.](\d{2}))?$/;function v(e,t){let n=Number(e),r=Number(t??`0`);return n>24||r>59||n===24&&r!==0?null:`${String(n).padStart(2,`0`)}:${String(r).padStart(2,`0`)}`}function y(e,t){let n=t.trim();if(n===``||n.toLowerCase()===`closed`)return[];let r=n.split(/\s*[,;]\s*|\s+and\s+/i).filter(e=>e!==``);if(r.length>2)return null;let i=[];for(let t of r){let n=_.exec(t);if(!n)return null;let r=v(n[1]??``,n[2]),a=v(n[3]??``,n[4]);if(!r||!a)return null;i.push({days:[e],opens:r,closes:a})}return i}function b(e,t){return t.filter(t=>t.days.includes(e)).map(e=>`${e.opens}-${e.closes}`).join(`, `)}const x=[{value:`WebPage`,label:`Web page`,short:`Web page`},{value:`AboutPage`,label:`About page`,short:`About page`},{value:`ContactPage`,label:`Contact page`,short:`Contact page`},{value:`BlogPosting`,label:`Blog post`,short:`Blog post`},{value:`Article`,label:`Article`,short:`Article`},{value:`Service`,label:`Service`,short:`Service`},{value:`ProfilePage`,label:`Person or team member`,short:`Person`}];function S(e){return x.find(t=>t.value===e)?.short??e}const C=[301,302,307,308,410,451],w=2e3,T={empty:`No old address`,query:`Addresses with a ? are not supported`,external:`Points to another website`,noTarget:`No new address`,same:`Old and new address are the same`,code:`Unknown redirect type`,pattern:`Uses a pattern. Add it by hand under Manage > Redirects`,inactive:`Switched off in the export`,repeated:`Listed twice`,exists:`Already exists`,conflict:`Conflicts with an existing redirect`,loop:`Would send visitors in a circle`,tooMany:`Only the first ${w} rows are imported at once`};function E(e,t){let n=[],r=``,i=!1;for(let a=0;a<e.length;a+=1){let o=e[a];i?o===`"`&&e[a+1]===`"`?(r+=`"`,a+=1):o===`"`?i=!1:r+=o:o===`"`?i=!0:o===t?(n.push(r.trim()),r=``):r+=o}n.push(r.trim());let a=n[0]??``;return n.length===1&&/\S\s+\S/.test(a)?a.split(/\s+/):n}const D={source:`source`,origin:`source`,from:`source`,"old url":`source`,old:`source`,sources:`source`,target:`target`,destination:`target`,to:`target`,"new url":`target`,new:`target`,url_to:`target`,regex:`regex`,code:`code`,"http code":`code`,type:`code`,header_code:`code`,format:`format`,matching:`matching`,status:`status`,ignore:`ignore`,id:`id`};function O(e,t){let n=e.map(e=>D[e.toLowerCase()]),r=n.includes(`source`)&&n.includes(`target`);if(r){let e={};return n.forEach((t,n)=>{t&&e[t]===void 0&&(e[t]=n)}),{format:e.matching===void 0?e.format===void 0?e.regex===void 0?`plain`:`redirection`:`yoast`:`rankmath`,hasHeader:r,index:e}}let i=t.slice(0,20),a=i.map(e=>e[2]??``),o=i.map(e=>(e[3]??``).toLowerCase());return o.length>0&&o.every(e=>e===`plain`||e===`regex`)?{format:`yoast`,hasHeader:r,index:{source:0,target:1,code:2,format:3}}:a.length>0&&a.every(e=>e===`0`||e===`1`)?{format:`redirection`,hasHeader:r,index:{source:0,target:1,regex:2,code:3}}:{format:`plain`,hasHeader:r,index:{source:0,target:1,code:2}}}function k(t){let n=t.trim();if(n===``)return{reason:T.empty};if(/^https?:\/\//i.test(n)){let t=e(n);if(!t)return{reason:T.empty};n=`${t.pathname}${t.search}`}return n.includes(`?`)?{reason:T.query}:(n.startsWith(`/`)||(n=`/${n}`),n.length>1&&(n=n.replace(/\/+$/,``)),{path:n===``?`/`:n})}const ee=/[\\^$.*+?()[\]{}|]/;function te(e,t){let n=e.trim();if(n.startsWith(`^`)&&(n=n.slice(1)),n.endsWith(`$`)&&(n=n.slice(0,-1)),n.endsWith(`/?`)&&(n=n.slice(0,-2)),!ee.test(n))return{source:n,target:t};let r=/^(\/[^\\^$.*+?()[\]{}|]*\/)\(\.\*\)$/.exec(n);return r&&!/\$[2-9]/.test(t)?{source:`${r[1]}[...rest]`,target:t.replace(/\$1/g,`[...rest]`)}:null}function ne(e){if(e===void 0||e.trim()===``)return 301;let t=Number(e.trim());return C.includes(t)?t:null}function A(t,n){let r=t.split(/\r?\n/),i=r.some(e=>e.includes(` `))?` `:`,`,a=r.map((e,t)=>({line:t+1,cells:E(e,i)})).filter(e=>e.cells.some(e=>e!==``)),o=a[0];if(!o)return{format:`plain`,ready:[],skipped:[]};let s=O(o.cells,a.map(e=>e.cells)),c=s.hasHeader?a.slice(1):a,l=(e,t)=>{let n=s.index[t];return n===void 0?void 0:e[n]},u=[],d=[],f=new Map(n.map(e=>[e.source,e.destination])),p=new Set;for(let{line:t,cells:n}of c){let r=l(n,`source`)??``,i=e=>d.push({line:t,source:r,reason:e});if(u.length>=w){i(T.tooMany);continue}if([`inactive`,`disabled`].includes((l(n,`status`)??`active`).toLowerCase())){i(T.inactive);continue}let a=ne(l(n,`code`));if(a===null){i(T.code);continue}let o=r,s=l(n,`target`)??``,c=(l(n,`matching`)??`exact`).toLowerCase();if(l(n,`regex`)===`1`||(l(n,`format`)??``).toLowerCase()===`regex`||c===`regex`){let e=te(o,s);if(!e){i(T.pattern);continue}o=e.source,s=e.target}else if(c===`start`&&o.trim().endsWith(`/`))o=`${o.trim()}[...rest]`;else if(c!==`exact`){i(T.pattern);continue}let m=k(o);if(`reason`in m){i(m.reason);continue}let h=a===410||a===451,g=``;if(!h){if(s.trim()===``){i(T.noTarget);continue}let t=/^https?:\/\//i.test(s.trim()),n=/^https?:\/\//i.test(r.trim())?e(r.trim())?.host:void 0;if(t&&n!==e(s.trim())?.host){i(T.external);continue}let a=k(s);if(`reason`in a){i(a.reason===T.empty?T.noTarget:a.reason);continue}if(g=a.path,g===m.path){i(T.same);continue}}if(p.has(m.path)){i(T.repeated);continue}let _=f.get(m.path);if(_!==void 0){i(_===g?T.exists:T.conflict);continue}p.add(m.path),u.push({line:t,source:m.path,destination:g,type:a})}let m=new Map(f);for(let e of u)m.set(e.source,e.destination);let h=[];for(let e of u){let t=e.destination,n=!1;for(let r=0;r<20&&t!==``&&m.has(t);r+=1)if(t=m.get(t)??``,t===e.source){n=!0;break}n?d.push({line:e.line,source:e.source,reason:T.loop}):h.push({source:e.source,destination:e.destination,type:e.type})}return{format:s.format,ready:h,skipped:d}}function re(e){let t=e=>/[",\n]/.test(e)?`"${e.replace(/"/g,`""`)}"`:e;return[`source,target,code`,...e.map(e=>`${t(e.source)},${t(e.destination)},${e.type}`)].join(`
2
- `)}const j=`redirects`,M=`redirects-import`,ie={redirection:`Redirection`,yoast:`Yoast SEO Premium`,rankmath:`Rank Math`,plain:`a plain list`};async function ae(e){let t=await e.kv.get(j);return t&&Array.isArray(t.rows)?t:null}async function oe(e){let t=[],n;for(let r=0;r<5;r+=1){let r=await e.redirects?.list({limit:100,cursor:n});if(!r||(t.push(...r.items),n=r.hasMore?r.cursor:void 0,!n))break}return t}async function se(e,t){let n=A(t,await oe(e)),r={status:`checked`,format:n.format,rows:n.ready,skipped:n.skipped,cursor:0,added:0,group:`Imported ${new Date().toISOString().slice(0,16).replace(`T`,` `)}`};return await e.kv.set(j,r),r}function ce(e){let t=e instanceof Error?e.message:String(e);return/already exists/i.test(t)?{kind:`exists`,message:t}:/invalid source pattern|must be different|destination|path traversal|loop/i.test(t)?{kind:`invalid`,message:t}:{kind:`stop`,message:t}}async function le(e,t){let n={...t,status:`adding`,skipped:[...t.skipped]},r=async()=>{try{return await e.kv.set(j,n),!0}catch{return!1}};if(t.status===`checked`)try{await e.cron?.schedule(M,{schedule:`* * * * *`})}catch(t){e.log.warn(`could not schedule background import`,{error:String(t)})}let i=0,a=n.cursor;for(;n.cursor<n.rows.length;){let t=n.rows[n.cursor];if(!t)break;try{await e.redirects?.create?.({source:t.source,destination:t.destination,type:t.type,groupName:n.group}),n.added+=1}catch(e){let{kind:r,message:i}=ce(e);if(r===`stop`){if(n.cursor!==a||(n.stalls=(n.stalls??0)+1,n.stalls<3))break;n.skipped.push({line:0,source:t.source,reason:`EmDash could not add it: ${i}`})}else r===`exists`?n.added+=1:n.skipped.push({line:0,source:t.source,reason:`EmDash refused it: ${i}`})}if(n.cursor+=1,n.stalls=0,i+=1,i>=4){if(!await r())return n;i=0}}if(n.cursor>=n.rows.length){n.status=`done`;try{await e.cron?.cancel(M)}catch{}}return await r(),n}async function ue(e,t){let n=await e.redirects?.list({limit:100,group:t.group}),r=n?.items??[],i=r.length;for(let t of r)try{let n=await e.redirects?.get(t.id);n&&await e.redirects?.delete?.(t.id,{_rev:n._rev}),--i}catch{break}if(i===0&&!n?.hasMore){try{await e.cron?.cancel(M)}catch{}return await e.kv.delete(j),0}return i}async function de(e){let t=[],n;for(let r=0;r<5;r+=1){let r=await e.redirects?.list({limit:100,cursor:n});if(!r||(t.push(...r.items),n=r.hasMore?r.cursor:void 0,!n))break}return{text:re(t),count:t.length}}function N(e,t){return`${e} ${t}${e===1?``:`s`}`}function fe(e){if(e.length===0)return[];let t=[{type:`header`,text:`Skipped (${e.length})`},{type:`context`,text:`Skipped rows are not added. Copy any you still need and add them by hand under Manage > Redirects, which also accepts patterns.`},{type:`table`,page_action_id:`skipped_table`,columns:[{key:`line`,label:`Row`},{key:`source`,label:`Old address`},{key:`reason`,label:`Why`}],rows:e.slice(0,50).map(e=>({line:e.line>0?String(e.line):``,source:e.source,reason:e.reason}))}];return e.length>50&&t.push({type:`context`,text:`And ${e.length-50} more.`}),t}const pe=[{value:`301`,label:`Permanent`},{value:`302`,label:`Temporary, the old address will come back`},{value:`410`,label:`Page removed on purpose, no new address`}];function me(e){return e===301||e===308?`Permanent`:e===302||e===307?`Temporary`:e===410?`Deleted on purpose`:String(e)}async function he(e){let t=await e.redirects?.list({limit:20});return{rows:(t?.items??[]).map(({id:e,source:t,destination:n,type:r,hits:i})=>({id:e,source:t,destination:n,type:r,hits:i})),more:t?.hasMore??!1}}function ge(e){let t=e instanceof Error?e.message:String(e);return/already exists/i.test(t)?`There is already a redirect from that old address. Use Change in the list below.`:/must be different/i.test(t)?`The old and new address are the same.`:/loop/i.test(t)?`That would send visitors in a circle.`:/changed since/i.test(t)?`That redirect was just changed elsewhere. Try again.`:`EmDash could not save that redirect. Check both addresses start with /.`}function _e(e,t,n){let r=A(re([{source:e,destination:t,type:Number(n)||301}]),[]);return r.ready[0]??r.skipped[0]?.reason??`Type the old address first.`}async function ve(e,t,n,r){let i=_e(t,n,r);if(typeof i==`string`)return`${i}.`;try{return await e.redirects?.create?.(i),null}catch(e){return ge(e)}}async function ye(e,t,n,r,i){let a=_e(n,r,i);if(typeof a==`string`)return`${a}.`;try{let n=await e.redirects?.get(t);return n?(await e.redirects?.update?.(t,{...a,_rev:n._rev}),null):`That redirect no longer exists.`}catch(e){return ge(e)}}async function be(e,t){try{let n=await e.redirects?.get(t);return n&&await e.redirects?.delete?.(t,{_rev:n._rev}),null}catch(e){return ge(e)}}function xe(e){if(!e)return[{type:`context`,text:`Paste a list exported from Redirection, Yoast SEO Premium or Rank Math, or any list of old address, new address. Nothing is added until you confirm.`},{type:`form`,block_id:`redirects`,fields:[{type:`text_input`,action_id:`list`,label:`Your list, one redirect per line`,multiline:!0,placeholder:`/old-page,/new-page`,initial_value:``}],submit:{label:`Check list`,action_id:`check_redirects`}}];if(e.status===`checked`){let t=e.rows.length;return[{type:`banner`,variant:t===0?`alert`:`default`,title:`${t} ready, ${e.skipped.length} skipped`,description:t===0?`Nothing in this list can be added. See why below.`:`Read as ${ie[e.format]}. Nothing has been added yet. Existing redirects are never changed.`},{type:`actions`,elements:[...t>0?[{type:`button`,action_id:`add_redirects`,label:`Add ${N(t,`redirect`)}`,style:`primary`,confirm:{title:`Add ${N(t,`redirect`)}?`,text:`Visitors to these old addresses will be sent to the new ones. You can remove them all again afterwards.`,confirm:`Add`,deny:`Cancel`}}]:[],{type:`button`,action_id:`reset_redirects`,label:`Start again`}]},...fe(e.skipped)]}return e.status===`adding`?[{type:`meter`,label:`${e.added} of ${e.rows.length} added`,value:e.cursor,max:e.rows.length},{type:`context`,text:`The rest are added in the background, a few each minute. You can leave this page.`},{type:`actions`,elements:[{type:`button`,action_id:`more_redirects`,label:`Add more now`,style:`primary`},{type:`button`,action_id:`stop_redirects`,label:`Stop here`}]}]:[{type:`banner`,title:`${N(e.added,`redirect`)} added from your list`,description:`They are labelled "${e.group}".`},{type:`actions`,elements:[{type:`button`,action_id:`reset_redirects`,label:`Import another list`},...e.added>0?[{type:`button`,action_id:`remove_redirects`,label:`Remove the ${e.added} just added`,confirm:{title:`Remove these redirects?`,text:`Only the redirects this import added are removed.`,confirm:`Remove`,deny:`Cancel`,style:`danger`}}]:[]]},...fe(e.skipped)]}function Se(e,t){let n=e?String(e.type):`301`;return{type:`form`,block_id:e?`edit_redirect_${e.id}`:`add_one_${t}`,fields:[{type:`text_input`,action_id:`source`,label:`Redirect from`,placeholder:`/old-page`,initial_value:e?.source??``},{type:`text_input`,action_id:`destination`,label:`Redirect to`,placeholder:`/new-page`,initial_value:e?.destination??``,condition:{field:`code`,neq:`410`}},{type:`select`,action_id:`code`,label:`Kind`,options:pe.some(e=>e.value===n)?pe:[...pe,{value:n,label:`${me(Number(n))} (${n})`}],initial_value:n}],submit:e?{label:`Save changes`,action_id:`save_redirect:${e.id}`}:{label:`Add redirect`,action_id:`add_redirect`}}}function Ce(e){let{state:t,rows:n,editing:r}=e,i=r?void 0:e.panel??(t?`import`:void 0),a=n[0]?.id??`first`,o=[{type:`context`,text:`Send visitors from an old address to a new one. Pages you rename in EmDash are redirected for you.`},{type:`actions`,elements:[{type:`button`,action_id:`open_add`,label:`Add a redirect`,...i===void 0&&!r?{style:`primary`}:{}},{type:`button`,action_id:`open_import`,label:`Import from WordPress`},{type:`button`,action_id:`export_redirects`,label:`Export`},...e.managerUrl?[{type:`link`,label:`Full Redirects screen`,target:{kind:`external`,url:e.managerUrl}}]:[]]}],s={type:`actions`,elements:[{type:`button`,action_id:`close_panel`,label:`Close`}]},c=e.problem?[{type:`banner`,variant:`error`,title:e.problem}]:[];return r?o.push({type:`header`,text:`Change a redirect`},...c,Se(r,a),s,{type:`divider`}):i===`add`?o.push({type:`header`,text:`Add a redirect`},...c,Se(void 0,a),s,{type:`divider`}):i===`import`?(o.push({type:`header`,text:`Import from WordPress`},...xe(t)),t||o.push(s),o.push({type:`divider`})):i===`export`&&o.push({type:`header`,text:`Export`},{type:`context`,text:`Copy this list to keep a backup or to paste into a spreadsheet. It can be imported again here.`},{type:`code`,code:e.exported??``,language:`bash`},s,{type:`divider`}),n.length===0?o.push({type:`empty`,title:`No redirects yet`,description:`Add one, or import a list from your old site.`,size:`sm`}):(o.push({type:`table`,page_action_id:`redirects_table`,columns:[{key:`source`,label:`Redirect from`},{key:`destination`,label:`Redirect to`},{key:`kind`,label:`Kind`},{key:`hits`,label:`Visits`,format:`number`},{key:`edit`,label:``,format:`element`},{key:`remove`,label:``,format:`element`}],rows:n.map(e=>({source:e.source,destination:e.destination||`(none)`,kind:me(e.type),hits:e.hits,edit:{type:`button`,action_id:`edit_redirect`,label:`Change`,value:e.id},remove:{type:`button`,action_id:`remove_redirect`,label:`Remove`,value:e.id,confirm:{title:`Remove this redirect?`,text:`Visitors to ${e.source} will see a not-found page.`,confirm:`Remove`,deny:`Keep`,style:`danger`}}}))}),e.more&&o.push({type:`context`,text:`Showing the newest ${n.length}. The rest are in the full Redirects screen.`})),o}async function we(e,t){let n={...t,status:`done`};try{await e.cron?.cancel(M)}catch{}return await e.kv.set(j,n),n}const Te=new Set("iIl.,:;|!'`jtfr ()[]".split(``)),Ee=new Set(`mwMWQO@%`.split(``));function De(e){let t=0;for(let n of e)Te.has(n)?t+=5:Ee.has(n)?t+=15:n>=`A`&&n<=`Z`?t+=12:t+=9.5;return Math.round(t)}function Oe(e){if(De(e)<=580)return e;let t=e;for(;t.length>1&&De(`${t}…`)>580;)t=t.slice(0,-1);return`${t.trimEnd()}…`}function ke(e){return e.toLowerCase().replace(/\s+/g,` `).trim()}const Ae=new Set([`home`,`homepage`,`home page`,`index`,`untitled`,`welcome`]),je=new Set([`_type`,`_key`,`id`,`slug`,`url`,`href`,`src`,`style`,`icon`]);function Me(e){let t={textLength:0,imagesWithoutAlt:0,hasImage:!1},n=(e,r,i)=>{if(i>12)return;if(typeof e==`string`){!je.has(r)&&!/^(https?:)?\//.test(e)&&(t.textLength+=e.trim().length);return}if(Array.isArray(e)){for(let t of e)n(t,r,i+1);return}if(typeof e!=`object`||!e)return;let a=e;(a._type===`image`||typeof a.src==`string`&&`alt`in a)&&(t.hasImage=!0,(typeof a.alt!=`string`||a.alt.trim()===``)&&(t.imagesWithoutAlt+=1));for(let[e,t]of Object.entries(a))n(t,e,i+1)};for(let[t,r]of Object.entries(e))t!==`json_ld`&&n(r,t,0);return t}const P={id:`no-social-image`,level:`look`,message:`This page has no picture for shared links, unless your site has a default sharing image.`,fix:`Add an image in the SEO panel. If your theme adds a picture itself, this clears once the page has been viewed.`};function Ne(e){return typeof e.excerpt==`string`?e.excerpt.trim():``}function Pe(t){let n=[],{seo:r}=t,i=Me(t.data),a=r?.title?.trim()||t.title.trim();if(a===``&&n.push({id:`no-title`,level:`fix`,message:`This page has no title.`,fix:`Give the page a title.`}),Ae.has(a.toLowerCase())&&n.push({id:`generic-title`,level:`fix`,message:`The title is just "${a}", which is what Google shows as the headline.`,fix:`Put your name and what you do in SEO Title, in the page's SEO panel.`}),r&&!r.description?.trim()&&Ne(t.data)===``&&n.push({id:`no-description`,level:`fix`,message:`No search description, so Google writes its own summary of this page.`,fix:`Fill in Meta Description in the page's SEO panel.`}),t.duplicateTitle&&a!==``&&n.push({id:`duplicate-title`,level:`fix`,message:`Another page has the same title, so Google cannot tell them apart.`,fix:`Give this page its own title in the SEO panel.`}),r?.canonical&&t.slug){let i=e(r.canonical,`${t.siteUrl.replace(/\/+$/,``)}/`),a=i?.pathname.replace(/\/+$/,``).split(`/`).pop(),o=[`home`,`index`].includes(t.slug)&&(a??``)===``;i&&a!==t.slug&&!o&&n.push({id:`canonical-elsewhere`,level:`fix`,message:`This page tells Google to show a different page instead (canonical).`,fix:`Clear the canonical address in the SEO panel unless that is intended.`})}if(a!==``&&De(a)>580&&n.push({id:`title-long`,level:`look`,message:`The end of this title may be cut off in Google.`,fix:`Shorten the title, or put the important words first.`}),r&&!r.image&&!i.hasImage&&n.push(P),t.isArticle&&t.authorCount===0&&n.push({id:`no-author`,level:`look`,message:`This article has no author.`,fix:`Add a byline to the article.`}),i.imagesWithoutAlt>0){let e=i.imagesWithoutAlt;n.push({id:`images-without-alt`,level:`look`,message:`${e} ${e===1?`picture has`:`pictures have`} no description for screen readers.`,fix:`Add alt text to each picture.`})}return i.textLength<80&&n.push({id:`nearly-empty`,level:`look`,message:`This page has almost no text.`,fix:`Add some content, or hide the page from search.`}),n}function Fe(e,t){return t?`hidden`:e.some(e=>e.level===`fix`)?`fix`:e.length>0?`look`:`ready`}const Ie=/^[0-9A-HJKMNP-TV-Z]{26}(\.[A-Za-z0-9]+)?$/i;function Le(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Re(e){return typeof e==`number`&&Number.isFinite(e)&&e>=1?Math.round(e):void 0}function ze(e){if(!e.startsWith(`/_emdash/api/media/file/`))return;let t=e.slice(24);try{t=decodeURIComponent(t)}catch{return}return t!==``&&!t.includes(`/`)?t:void 0}function Be(t,n){let r=e(t,`${n.replace(/\/+$/,``)}/`);if(!r||!/^https?:$/.test(r.protocol)||r.search!==``)return[];let{pathname:i}=r;if(i===`/_image`||i.includes(`/cdn-cgi/image/`))return[];let a=ze(i);if(a)return[`file:${a}`];let o=[`url:${r.origin}${i}`],s=i.slice(1);return Ie.test(s)&&o.push(`file:${s}`),o}function Ve(e){if(typeof e!=`string`||e===``)return[];if(e.startsWith(`/`)){let t=e.includes(`?`)?void 0:ze(e);return t?[`file:${t}`]:[]}return/^https?:\/\//i.test(e)?Be(e,`http://localhost`).filter(e=>e.startsWith(`url:`)):[]}function He(e){return typeof e==`string`&&e!==``&&!e.includes(`/`)?[`file:${e}`]:[]}function Ue(e){let t=Re(e.width),n=Re(e.height);if(t===void 0||n===void 0||typeof e.mimeType==`string`&&!e.mimeType.startsWith(`image/`))return;let r=[];if(e._type===`image`&&Le(e.asset))r.push(...He(e.asset._ref),...Ve(e.asset.url));else if(typeof e.id==`string`){if(e.provider===void 0||e.provider===`local`){let t=Le(e.meta)?e.meta:{};r.push(...He(t.storageKey),...He(e.id))}r.push(...Ve(e.src))}let i=[...new Set(r)];return i.length>0?{keys:i,width:t,height:n}:void 0}function We(e){let t=[],n=new Set,r=(e,i)=>{if(t.length>=10||i>12)return;if(Array.isArray(e)){for(let t of e)r(t,i+1);return}if(!Le(e))return;let a=Ue(e);if(a&&!a.keys.some(e=>n.has(e))){for(let e of a.keys)n.add(e);t.push(a)}for(let t of Object.values(e))r(t,i+1)};for(let[t,n]of Object.entries(e))t!==`json_ld`&&r(n,0);return t.slice(0,10)}function Ge(e,t,n){if(!e||e.length===0)return;let r=Be(t,n);if(r.length===0)return;let i=e.find(e=>e.keys.some(e=>r.includes(e)));return i?{width:i.width,height:i.height}:void 0}const Ke=16*1024;function F(e,t){return`${e}:${t}`}function I(e){return e.storage.entries}function qe(e){return typeof e==`object`&&!!e&&!Array.isArray(e)&&`@type`in e}function Je(e){let t=e;if(typeof e==`string`){if(e.trim()===``||e.length>Ke)return[];try{t=JSON.parse(e)}catch{return[]}}let n=(Array.isArray(t)?t:[t]).filter(qe);return JSON.stringify(n).length>Ke?[]:n}function Ye(e){let{title:t,name:n}=e.data;return typeof t==`string`?t:typeof n==`string`?n:``}function Xe(e){let{collection:t,entry:n,authors:i,previous:o,config:s,siteUrl:c}=e,l=s.collections[t],u=o?.type??l?.type??a(t),d=n.seo?.title?.trim()||Ye(n),f=n.status===`published`,p=f&&e.hasPages,m=e.hasPages?Pe({slug:n.slug,data:n.data,seo:n.seo,title:Ye(n),siteUrl:c,isArticle:r.includes(u),authorCount:i.length,duplicateTitle:e.duplicateTitle}):[],h=m.some(e=>e.id===P.id),g=h&&o?.imageSeen===!0,_=g?m.filter(e=>e.id!==P.id):m,v=e.hasPages?We(n.data):[];return{v:1,publishedAt:n.publishedAt,updatedAt:n.updatedAt,authors:i,...o?.type?{type:o.type}:{},custom:Je(n.data[s.jsonLdField]),...v.length>0?{images:v}:{},needsImage:h,...g?{imageSeen:g}:{},collection:t,entryId:n.id,title:d,status:e.hasPages?f?Fe(_,n.seo?.noIndex===!0||l?.noindex===!0):`draft`:`skip`,titleKey:p?ke(d):``,issues:_,checkedAt:new Date().toISOString()}}function Ze(e,t){return e.status===`hidden`||e.status===`draft`||e.status===`skip`?e.status:Fe(t,!1)}function Qe(e,t){let n=e.issues??[],r=n.some(e=>e.id===P.id);if(!(e.needsImage??r)||e.imageSeen===!0===t&&r!==t)return null;let i=n.filter(e=>e.id!==P.id),a=t?i:[...i,P],{imageSeen:o,...s}=e;return{...s,needsImage:!0,...t?{imageSeen:!0}:{},issues:a,status:Ze(e,a)}}async function $e(e,t,n){return t===``?[]:(await I(e).query({where:{titleKey:t},limit:5})).items.filter(e=>e.id!==n)}function L(e,t){let n=(e.issues??[]).filter(e=>e.id!==`duplicate-title`),r=t?[...n,{id:`duplicate-title`,level:`fix`,message:`Another page has the same title, so Google cannot tell them apart.`,fix:`Give this page its own title in the SEO panel.`}]:n;return{...e,issues:r,status:Ze(e,r)}}async function et(e,t,n,r){return(await tt(e,t,n,r))?.record??null}async function tt(e,t,n,r){let i=await e.content?.get(t,n);if(!i)return null;let a=I(e),o=F(t,n),[s,c,l]=await Promise.all([e.bylines?.getEntriesBylines(t,[n])??[],a.get(o),e.schema?.getCollection(t)]),u=Xe({collection:t,entry:i,authors:(s[0]?.bylines??[]).map(({byline:e})=>({name:e.displayName,...e.websiteUrl?{url:e.websiteUrl}:{}})),previous:c,config:r,siteUrl:e.site.url,duplicateTitle:!1,hasPages:l?l.routable&&!l.hidden:!0}),d=await $e(e,u.titleKey??``,o),f=L(u,d.length>0),p=[{id:o,data:f}];for(let e of d)e.data.issues?.some(e=>e.id===`duplicate-title`)||p.push({id:e.id,data:L(e.data,!0)});let m=c?.titleKey??``;if(m!==``&&m!==f.titleKey){let t=await $e(e,m,o),n=t.length===1?t[0]:void 0;n&&p.push({id:n.id,data:L(n.data,!1)})}return await a.putMany(p),{record:f,entry:i}}async function nt(e,t,n){let r=I(e),i=F(t,n),a=await r.get(i);await r.delete(i);let o=await $e(e,a?.titleKey??``,i),s=o.length===1?o[0]:void 0;s&&await r.put(s.id,L(s.data,!1))}const R=`scan`,rt=`stats`,z=`seo-scan`;async function it(e){return e.kv.get(R)}async function at(e,t,n){let r={status:`running`,collections:t,phase:`entries`,checked:0,tally:{checked:0,fix:0,hidden:0,rows:[],more:!1},startedAt:new Date().toISOString()};try{await e.cron?.schedule(z,{schedule:`* * * * *`})}catch(t){e.log.warn(`could not schedule background check`,{error:String(t)})}return H(e,r,n)}async function ot(e,t,n){let r=t.collections[0];if(r===void 0){t.phase=`titles`;return}let i=await e.content?.list(r,{limit:20,cursor:t.cursor,where:{status:`published`}}),a=i?.items??[];if(a.length>0){let o=I(e),s=a.map(e=>e.id),[c,l]=await Promise.all([e.bylines?.getEntriesBylines(r,s)??[],o.getMany(s.map(e=>F(r,e)))]),u=new Map(c.map(e=>[e.entryId,e.bylines])),d=a.map(t=>{let i=l.get(F(r,t.id))??null;return{id:F(r,t.id),data:Xe({hasPages:!0,collection:r,entry:t,authors:(u.get(t.id)??[]).map(({byline:e})=>({name:e.displayName,...e.websiteUrl?{url:e.websiteUrl}:{}})),previous:i,config:n,siteUrl:e.site.url,duplicateTitle:i?.issues?.some(e=>e.id===`duplicate-title`)??!1})}});if(t.cursor===void 0&&t.checked===0&&!i?.hasMore&&t.collections.length===1){let e=new Map;for(let{data:t}of d)t.titleKey&&e.set(t.titleKey,(e.get(t.titleKey)??0)+1);for(let t of d)t.data=L(t.data,(e.get(t.data.titleKey??``)??0)>1);t.status=`done`,t.finishedAt=new Date().toISOString()}await o.putMany(d);for(let{data:e}of d)V(t.tally,e,1);t.checked+=a.length}i?.hasMore&&i.cursor?t.cursor=i.cursor:(t.cursor=void 0,t.collections=t.collections.slice(1),t.collections.length===0&&t.status!==`done`&&(t.phase=`titles`))}async function st(e,t){let n=I(e),r=await n.query({orderBy:{titleKey:`asc`},limit:100,cursor:t.titleCursor}),i=r.items.filter(e=>(e.data.titleKey??``)!==``),a=new Map,o=(e,n,r)=>{if((n.issues?.some(e=>e.id===`duplicate-title`)??!1)===r)return;let i=L(n,r);a.set(e,i),V(t.tally,n,-1),V(t.tally,i,1)},s=t.lastTitle;for(let e=0;e<i.length;e+=1){let t=i[e];if(!t)continue;let r=t.data.titleKey??``,a=i[e+1],c=s?.key===r,l=a?.data.titleKey===r;if(c&&s&&!s.flagged&&e===0){let e=await n.get(s.id);e&&o(s.id,e,!0)}let u=c||l;o(t.id,t.data,u),s={key:r,id:t.id,flagged:u}}a.size>0&&await n.putMany([...a].map(([e,t])=>({id:e,data:t}))),t.lastTitle=s,r.hasMore&&r.cursor?t.titleCursor=r.cursor:(t.status=`done`,t.finishedAt=new Date().toISOString(),t.titleCursor=void 0,t.lastTitle=void 0)}function B(e,t=`fix`){return{collection:e.collection??``,id:e.entryId??``,title:e.title||`(no title)`,issues:(e.issues??[]).filter(e=>e.level===t).map(e=>e.message)}}function V(e,t,n){if(!(!t.status||t.status===`draft`||t.status===`skip`)){if(e.checked+=n,t.status===`hidden`){e.hidden+=n;let r=e.hiddenTitles??[],i=t.title||`(no title)`;e.hiddenTitles=n===1?[...r,i].slice(0,10):r.filter(e=>e!==i)}if(t.status===`look`){let r=e.look??[];e.look=n===1?[...r,B(t,`look`)].slice(0,10):r.filter(e=>e.id!==t.entryId)}t.status===`fix`&&(e.fix+=n,n===1?e.rows.length<10?e.rows.push(B(t)):e.more=!0:e.rows=e.rows.filter(e=>e.id!==t.entryId))}}async function H(e,t,n){let r={...t,collections:[...t.collections],tally:{...t.tally,rows:[...t.tally.rows]}};if(r.status===`done`)return r;if(r.phase===`entries`){for(let t=0;t<5&&r.phase===`entries`;t+=1){let t=r.checked;if(await ot(e,r,n),r.checked!==t||r.status===`done`)break}r.phase===`titles`&&r.checked===0&&(r.status=`done`,r.finishedAt=new Date().toISOString())}else await st(e,r);if(r.status===`done`)try{await e.cron?.cancel(z)}catch{}return await e.kv.set(R,r),r}async function ct(e){let t=I(e),[n,r,i,a,o]=await Promise.all([t.count({status:{in:[`ready`,`look`,`fix`,`hidden`]}}),t.count({status:`fix`}),t.query({where:{status:`fix`},limit:10}),t.query({where:{status:`look`},limit:10}),t.query({where:{status:`hidden`},limit:10})]);return{checked:n,fix:r,hidden:o.hasMore?11:o.items.length,rows:i.items.map(({data:e})=>B(e)),more:i.hasMore,look:a.items.map(({data:e})=>B(e,`look`)),hiddenTitles:o.items.map(({data:e})=>e.title||`(no title)`)}}const U=new Map;async function lt(e,t,{fresh:n=!1,now:r=Date.now()}={}){let i=e.site?.url??``,a=U.get(e.plugin.id);a||U.set(e.plugin.id,a=new Map);let o=a.get(i);if(n||!o||r>=o.until){let e=t(),n={value:e,until:r+3e4};a.set(i,n),e.catch(()=>{a.get(i)===n&&a.delete(i)}),o=n}return structuredClone(await o.value)}function ut(e){U.delete(e)}const W={overview:0,redirects:1,identity:2,types:2},G=[{value:`FoodEstablishment`,label:`Restaurant, cafe or bakery`},{value:`Store`,label:`Shop`},{value:`MedicalBusiness`,label:`Health and medical`},{value:`Dentist`,label:`Dentist`},{value:`LegalService`,label:`Legal`},{value:`FinancialService`,label:`Financial`},{value:`HomeAndConstructionBusiness`,label:`Home services (plumber, electrician, builder)`},{value:`HealthAndBeautyBusiness`,label:`Beauty and hair`},{value:`SportsActivityLocation`,label:`Fitness`},{value:`LodgingBusiness`,label:`Hotel or lodging`},{value:`AutomotiveBusiness`,label:`Automotive`},{value:`ProfessionalService`,label:`Professional service`},{value:`LocalBusiness`,label:`Other`}],dt=[``,`$`,`$$`,`$$$`,`$$$$`],ft=[{id:`facebook`,label:`Facebook`,hosts:[`www.facebook.com`,`facebook.com`,`fb.com`]},{id:`instagram`,label:`Instagram`,hosts:[`www.instagram.com`,`instagram.com`]},{id:`linkedin`,label:`LinkedIn`,hosts:[`www.linkedin.com`,`linkedin.com`]},{id:`x`,label:`X (Twitter)`,hosts:[`x.com`,`www.x.com`,`twitter.com`,`www.twitter.com`]},{id:`youtube`,label:`YouTube`,hosts:[`www.youtube.com`,`youtube.com`]}];function pt(t){let n={},r=[];for(let i of t){let t=e(i)?.host??``,a=ft.find(e=>e.hosts.includes(t));a&&!(a.id in n)?n[a.id]=i:r.push(i)}return{named:n,other:r}}const mt={needed:`needed`,worth:`worth adding`,optional:`optional`};function K(e,t,n){let r=n.filter(e=>!!e);return r.length>0?`${e}: ${r.join(`, `)}`:`${e} (${mt[t]}, not added yet)`}function ht(e){return g.map(t=>{let n=b(t,e.openingHours).replace(`, `,` and `);return n===``?void 0:`${t.slice(0,3)} ${n}`}).filter(e=>e!==void 0)}function gt(e){let{site:t}=e.config,n=q(t),r=[];return n===`local`?((!t.address?.streetAddress||!t.address.addressLocality)&&r.push({what:`Address`,why:`Without it Google cannot treat you as a local business.`}),t.openingHours.length===0&&r.push({what:`Opening hours`,why:`Google cannot show when you are open.`}),t.telephone||r.push({what:`Phone number`,why:`Customers cannot call you from Google.`})):(n===`organization`&&!t.logo&&r.push({what:`Logo`,why:`Google shows it beside your name.`}),t.sameAs.length===0&&r.push({what:`Profiles elsewhere`,why:`They help Google connect your other pages to this site.`})),r}function q(e){return e.type===`Person`?`person`:e.type===`Organization`?`organization`:`local`}function _t(t,n){let r=e(t);if(!(!r||r.protocol!==`https:`&&r.protocol!==`http:`))return`${r.origin}${n}`}function vt(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function J(e,t,n=``){let r=e[t];return typeof r==`string`?r.trim():n}function yt(e,t,n){let r=e[t];return typeof r==`boolean`?r:n}function bt(e){return e.split(/\r?\n/).map(e=>e.trim()).filter(e=>e!==``)}async function xt(e){let[n,r,i]=await Promise.all([e.kv.list(),e.schema?.listCollections()??[],he(e)]),a=new Map(n.map(e=>[e.key,e.value])),o=a.get(j);return{config:h(a.get(t)),collections:r.filter(e=>e.routable&&!e.hidden),redirects:o&&Array.isArray(o.rows)?o:null,redirectRows:i.rows,moreRedirects:i.more,scan:a.get(R)??null,stats:a.get(rt)??null}}async function St(e,t){let n=await ct(e);return JSON.stringify(n)!==JSON.stringify(t.stats)&&await e.kv.set(rt,n),{...t,stats:n}}function Ct(e){return e.stats??(e.scan?.status===`done`?e.scan.tally:null)}function wt(e){let{scan:t}=e,n=Ct(e);if(!t||t.status===`running`)return[{type:`banner`,title:`Checking your pages`,description:t?`${t.checked} checked so far. The rest are checked in the background.`:`This starts by itself and takes about a minute.`}];if(!n)return[];let r=n.checked-n.fix-n.hidden;return[{type:`stats`,items:[{label:`Pages checked`,value:n.checked},{label:`Nothing to fix`,value:r},{label:`To fix`,value:n.fix}]}]}function Tt(e){let{scan:t}=e,n=Ct(e);if(!n||!t||t.status===`running`)return[];let r=[];n.checked===0?r.push({type:`empty`,title:`No published pages yet`,size:`sm`}):n.fix===0?r.push({type:`empty`,title:`No pages to fix. Nice work.`,size:`sm`}):(r.push({type:`header`,text:`To fix`},{type:`table`,page_action_id:`fix_table`,columns:[{key:`page`,label:`Page`},{key:`missing`,label:`What's missing`},{key:`open`,label:``,format:`element`}],rows:n.rows.map(e=>({page:e.title,missing:e.issues.join(` `),open:{type:`link`,label:`Open page`,target:{kind:`content`,collection:e.collection,id:e.id}}}))}),n.more&&r.push({type:`context`,text:`Showing the first 10. Fix these and the next ones appear.`}));let i=n.look??[];if(i.length>0&&r.push({type:`accordion`,label:`Worth a look (${i.length}${i.length===10?`+`:``})`,blocks:[{type:`context`,text:`Nothing is wrong with these pages. These are improvements for when you have time.`},{type:`table`,page_action_id:`look_table`,columns:[{key:`page`,label:`Page`},{key:`advice`,label:`Could be better`},{key:`open`,label:``,format:`element`}],rows:i.map(e=>({page:e.title,advice:e.issues.join(` `),open:{type:`link`,label:`Open page`,target:{kind:`content`,collection:e.collection,id:e.id}}}))}]}),n.hidden>0){let e=(n.hiddenTitles??[]).join(`, `);r.push({type:`context`,text:`${n.hidden>10?`More than 10`:n.hidden} ${n.hidden===1?`page is`:`pages are`} hidden from Google and not counted${e?`: ${e}`:``}. To show one again, open it and switch off "Hide from search engines" in its SEO panel.`})}if(t.finishedAt){let e=new Date(t.finishedAt).toLocaleDateString(`en-GB`,{day:`numeric`,month:`short`});r.push({type:`context`,text:`Each page is checked again when it is saved. Last full check: ${e}.`})}return r}function Et(e){if(!e.scan)return[];let t=e.scan.status===`running`;return[{type:`actions`,elements:[{type:`button`,action_id:t?`check_more`:`check_pages`,label:t?`Update`:`Check all pages again`}]}]}function Dt(e){return e.collections.filter(t=>{let n=e.config.collections[t.slug];return n?.noindex===!0&&n.hiddenOk!==!0})}function Ot(e,t){let n=Dt(e);if(n.length===0)return[];let r=[{type:`banner`,variant:`alert`,title:`Some pages are hidden from Google`,description:`Every page in ${n.map(e=>e.label).join(`, `)} is hidden from search engines. If that is a leftover from building the site, switch it back on in the Settings tab, under Content types.`}];return t&&r.push({type:`actions`,elements:[{type:`button`,action_id:`hidden_ok`,label:`This is intended`}]}),r}function kt(e,t){let{steps:n,site:r}=e.config;return n.identity?[]:[{type:`banner`,title:`Tell Google who this site is for`,description:`Google can then show your name and details beside your pages. It takes a minute.`},{type:`accordion`,label:`Set this up (1 minute)`,default_open:!0,blocks:[{type:`form`,block_id:`setup_identity`,fields:[{type:`radio`,action_id:`kind`,label:`This site is for`,options:[{label:`A local business customers visit (shop, cafe, clinic)`,value:`local`},{label:`A company or organisation`,value:`organization`},{label:`A person`,value:`person`}]},{type:`select`,action_id:`business`,label:`Kind of business`,options:[{label:`Choose the closest`,value:``},...G],initial_value:``,condition:{field:`kind`,eq:`local`}},{type:`text_input`,action_id:`name`,label:`Name`,placeholder:`Your name or your business's name`,initial_value:r.name??t},{type:`text_input`,action_id:`street`,label:`Street address`,initial_value:r.address?.streetAddress??``,condition:{field:`kind`,eq:`local`}},{type:`text_input`,action_id:`town`,label:`Town or city`,initial_value:r.address?.addressLocality??``,condition:{field:`kind`,eq:`local`}}],submit:{label:`Save`,action_id:`setup_identity`}}]}]}function At(e,t){let{site:n}=e.config,r=q(n),i=G.find(e=>e.value===n.type)?.label,a=r===`person`?`a person`:r===`local`?(i??`a local business`).toLowerCase():`a company`,o=[n.address?.streetAddress,n.address?.addressLocality].filter(Boolean).join(`, `),s=ht(n);return[`Google is told: ${n.name??t}, ${a}`,o?`, ${o}`:``,s.length>0?`, open ${s.join(`, `)}`:``,`. Change this in the Settings tab.`].join(``)}function jt(e,t){if(!e.config.steps.identity)return[];let n=gt(e);return n.length===0?[{type:`context`,text:At(e,t)}]:[{type:`header`,text:`Your details`},{type:`context`,text:`${n.length} ${n.length===1?`thing`:`things`} Google needs from you. Add ${n.length===1?`it`:`them`} in the Settings tab.`},{type:`table`,page_action_id:`details_table`,columns:[{key:`what`,label:`Missing`},{key:`why`,label:`Why it matters`}],rows:n}]}function Mt(e,t){return[...wt(e),...Ot(e,!0),...kt(e,t),...jt(e,t),...Tt(e),...Et(e)]}function Nt(e){let t=Ct(e),n={type:`actions`,elements:[{type:`link`,label:`Open SEO`,target:{kind:`plugin-page`,path:`/overview`}}]};if(!t||t.checked===0){let{steps:t}=e.config;return{blocks:[{type:`section`,text:t.identity?`Your pages are being checked.`:`One thing left: tell Google who this site is for.`},n]}}return{blocks:[{type:`stats`,items:[t.fix===0?{label:`SEO`,value:`All pages ready`}:{label:t.fix===1?`Page to fix`:`Pages to fix`,value:t.fix}]},n]}}function Pt(t,n){let{site:r}=t.config,i=q(r),a=i===`local`,o=t.config.steps.identity,s=pt(r.sameAs),c=[{type:`context`,text:`Google reads these details from your site and can show them beside your pages. Sections marked needed are followed up on the Overview; the rest are up to you.`},{type:`form`,block_id:`identity`,fields:[{type:`radio`,action_id:`kind`,label:`This site is for`,options:[{label:`A local business customers visit (shop, cafe, clinic)`,value:`local`},{label:`A company or organisation`,value:`organization`},{label:`A person`,value:`person`}],...o?{initial_value:i}:{}},{type:`select`,action_id:`business`,label:`Kind of business`,options:[{label:`Choose the closest`,value:``},...G],initial_value:a?r.type:``,condition:{field:`kind`,eq:`local`}},{type:`text_input`,action_id:`name`,label:`Name`,placeholder:`Your name or your business's name`,initial_value:r.name??n},{type:`text_input`,action_id:`description`,label:`What you do, in one or two sentences`,multiline:!0,initial_value:r.description??``}],submit:{label:`Save`,action_id:`save_identity`}},{type:`context`,text:`Each section below is saved with its own Save button.`}],l={type:`accordion`,label:K(`Address and phone`,a?`needed`:`optional`,[r.address?.streetAddress,r.address?.addressLocality,r.telephone,r.email]),default_open:a&&gt(t).some(e=>e.what!==`Opening hours`),blocks:[{type:`context`,text:a?`Google needs an address before it treats you as a local business. Use the same details as your Google Business Profile, which is what puts you on the map.`:`Leave the address empty if you have no public one.`},{type:`form`,block_id:`contact`,fields:[{type:`text_input`,action_id:`street`,label:`Street address`,initial_value:r.address?.streetAddress??``},{type:`text_input`,action_id:`town`,label:`Town or city`,initial_value:r.address?.addressLocality??``},{type:`text_input`,action_id:`region`,label:`State or region`,initial_value:r.address?.addressRegion??``},{type:`text_input`,action_id:`postcode`,label:`Postcode`,initial_value:r.address?.postalCode??``},{type:`text_input`,action_id:`country`,label:`Country code (GB, US, IN, AU)`,initial_value:r.address?.addressCountry??``},{type:`text_input`,action_id:`telephone`,label:`Phone`,initial_value:r.telephone??``},{type:`text_input`,action_id:`email`,label:`Email`,initial_value:r.email??``},{type:`select`,action_id:`price_range`,label:`Price range`,options:dt.map(e=>({label:e===``?`Not shown`:e,value:e})),initial_value:r.priceRange??``},{type:`text_input`,action_id:`areas`,label:`Areas you serve, one per line (if you travel to customers)`,multiline:!0,initial_value:r.areaServed.join(`
3
- `)}],submit:{label:`Save address and phone`,action_id:`save_contact`}}]},u=a?{type:`accordion`,label:K(`Opening hours`,`needed`,ht(r)),blocks:[{type:`context`,text:`Type the hours for each day, like 9:00-17:00. For a break in the day use two ranges: 12:00-14:30, 18:00-22:00. A day left empty is shown as closed.`},{type:`form`,block_id:`hours`,fields:g.map(e=>({type:`text_input`,action_id:`hours_${e.toLowerCase()}`,label:e,placeholder:`Closed`,initial_value:b(e,r.openingHours)})),submit:{label:`Save opening hours`,action_id:`save_hours`}}]}:{type:`accordion`,label:`Opening hours (only for a local business)`,blocks:[{type:`context`,text:`Opening hours are for a place customers visit. Choose "A local business customers visit" above and save, and this section opens up.`}]},d={type:`accordion`,label:K(`Logo`,i===`organization`?`needed`:`worth`,[r.logo?`added`:void 0]),blocks:[{type:`context`,text:`Google can show your logo beside your name. In Media, open your logo and use Copy URL, then paste it here. Use a square image at least 112 pixels wide.`},{type:`form`,block_id:`logo`,fields:[{type:`text_input`,action_id:`logo_url`,label:`Logo link`,placeholder:`https://example.com/logo.png`,initial_value:r.logo??``}],submit:{label:`Save logo`,action_id:`save_logo`}}]},f={type:`accordion`,label:K(`Your profiles elsewhere`,a?`worth`:`needed`,r.sameAs.map(t=>e(t)?.host.replace(/^www\./,``))),blocks:[{type:`context`,text:`Links to your pages on other sites help Google connect them to you. Paste the full address of each profile you have.`},{type:`form`,block_id:`profiles`,fields:[...ft.map(e=>({type:`text_input`,action_id:`profile_${e.id}`,label:e.label,placeholder:`https://${e.hosts[0]}/yourname`,initial_value:s.named[e.id]??``})),{type:`text_input`,action_id:`profiles`,label:`Other profiles, one per line`,multiline:!0,initial_value:s.other.join(`
4
- `)}],submit:{label:`Save profiles`,action_id:`save_profiles`}}]},p={type:`accordion`,label:K(`More about you`,`optional`,[r.alternateName,r.legalName,r.foundingDate?`founded ${r.foundingDate}`:void 0]),blocks:[{type:`context`,text:`Nothing here is needed. Skip anything that does not apply.`},{type:`form`,block_id:`company`,fields:[{type:`text_input`,action_id:`alternate_name`,label:`Also known as (a short name or abbreviation)`,initial_value:r.alternateName??``},{type:`text_input`,action_id:`legal_name`,label:`Registered legal name`,initial_value:r.legalName??``},{type:`text_input`,action_id:`founded`,label:`Founded (year, or YYYY-MM-DD)`,placeholder:`2012`,initial_value:r.foundingDate??``}],submit:{label:`Save`,action_id:`save_company`}}]},m=a?[l,u,d,f,p]:i===`organization`?[d,f,l,p,u]:[f,d,l,p,u];return c.push(...m),c}function Ft(e,t){return e.config.collections[t]?.type??a(t)}function It(e,t){let{config:n}=e,r=e.collections.find(e=>e.slug===t),i=[{type:`context`,text:`Google is told what each kind of content is, so it can show it properly: a blog post with its author and date, a service as a service. These were worked out from the names and are usually right. Every kind of content that has its own pages is listed here; content that only appears inside other pages, such as testimonials, is not. To change a single page (an About or Contact page, say), open it and use Change page type in its Google preview panel. Picking from a menu saves straight away.`}];return r&&i.push({type:`banner`,variant:`alert`,title:`Hide every page in ${r.label} from Google?`,description:`People will no longer find these pages through search engines. You can switch this back at any time.`},{type:`actions`,elements:[{type:`button`,action_id:`confirm_hide`,label:`Yes, hide them`,style:`danger`,value:r.slug},{type:`button`,action_id:`cancel_hide`,label:`Cancel`}]}),i.push({type:`table`,page_action_id:`types_table`,empty_text:`This site has no content types with pages yet.`,columns:[{key:`name`,label:`Content type`},{key:`shown`,label:``,format:`element`},{key:`visible`,label:``,format:`element`}],rows:e.collections.map(t=>{let r=n.collections[t.slug]?.noindex===!0;return{name:t.label,shown:{type:`menu`,action_id:`set_type`,label:`Google treats these as: ${S(Ft(e,t.slug))}`,items:x.map(({value:e,label:n})=>({label:n,value:`${t.slug}|${e}`}))},visible:{type:`menu`,action_id:`set_visible`,label:r?`Hidden from Google`:`Can appear on Google`,items:[{label:`Can appear on Google`,value:`${t.slug}|show`},{label:`Hide from Google and other search engines`,value:`${t.slug}|hide`}]}}})},{type:`form`,block_id:`breadcrumbs`,fields:[{type:`toggle`,action_id:`breadcrumbs`,label:`Show the path to each page on Google (Home > Services > Cakes)`,description:`Leave on unless your theme already does this.`,initial_value:n.breadcrumbs}],submit:{label:`Save`,action_id:`save_advanced`}}),[{type:`accordion`,label:`Content types (usually right as they are): ${e.collections.map(t=>{let r=n.collections[t.slug]?.noindex===!0;return`${t.label} as ${S(Ft(e,t.slug))}${r?`, hidden`:``}`}).join(`; `)}`,default_open:r!==void 0,blocks:i}]}function Y(e,t,n,r){let i=[{type:`header`,text:`SEO`},{type:`context`,text:`How your site appears on Google and other search engines.`}];return n?{blocks:[...i,{type:`tab`,default_tab:r.tab,panels:[{label:`Overview`,blocks:Mt(e,t.site.name)},{label:`Redirects`,blocks:Ce({state:e.redirects,rows:e.redirectRows,more:e.moreRedirects,editing:r.editing,panel:r.panel,problem:r.problem,exported:r.exported,managerUrl:_t(t.site.url,`/_emdash/admin/redirects`)})},{label:`Settings`,blocks:[...Pt(e,t.site.name),...It(e,r.pendingHide)]}]}],...r.toast?{toast:r.toast}:{}}:{blocks:[...i,...wt(e),...Ot(e,!1),...Tt(e),{type:`context`,text:`Business details, opening hours and redirects are set by your site admin. Ask them if something there is wrong.`}]}}function Lt(t,n){if(t===``)return{};let r=e(t,`${n.replace(/\/+$/,``)}/`);return!r||r.protocol!==`https:`&&r.protocol!==`http:`?{error:`Couldn't save. The logo link must be a web address starting with https://`}:r.pathname.includes(`/_emdash/api/media/asset/`)?{error:`That link only works when signed in. In Media, use Copy URL on the image instead.`}:{logo:r.href}}function Rt(e,t){let n={tab:W.identity},{site:r}=e.config,i=J(t,`kind`,e.config.steps.identity?q(r):``);if(i!==`local`&&i!==`organization`&&i!==`person`)return{error:`Choose who this site is for.`,state:n};let a=J(t,`business`,q(r)===`local`?r.type:``),o=G.find(e=>e.value===a)?.value;if(i===`local`&&!o)return{error:`Choose the kind of business.`,state:n};let s=i===`person`?`Person`:i===`local`?o??`LocalBusiness`:`Organization`,c=J(t,`name`,r.name??``);return{config:{...e.config,site:{...r,type:s,name:c===``?void 0:c,description:J(t,`description`,r.description??``)||void 0,openingHours:i===`local`?r.openingHours:[]},steps:{...e.config.steps,identity:!0}},state:n}}function zt(e,t,n){let r={tab:W.identity},i=Lt(J(t,`logo_url`,e.config.site.logo??``),n);return`error`in i?{error:i.error,state:r}:{config:{...e.config,site:{...e.config.site,logo:i.logo}},state:r}}function Bt(e,t){let{site:n}=e.config,r={streetAddress:J(t,`street`)||void 0,addressLocality:J(t,`town`)||void 0,addressRegion:J(t,`region`)||void 0,postalCode:J(t,`postcode`)||void 0,addressCountry:J(t,`country`).toUpperCase()||void 0},i=J(t,`price_range`);return{config:{...e.config,site:{...n,email:J(t,`email`)||void 0,telephone:J(t,`telephone`)||void 0,address:Object.values(r).some(e=>e!==void 0)?r:void 0,priceRange:dt.includes(i)&&i!==``?i:void 0,areaServed:bt(J(t,`areas`,n.areaServed.join(`
5
- `)))}},state:{tab:W.identity}}}function Vt(e,t){let n={tab:W.identity},r=[];for(let i of g){let a=y(i,J(t,`hours_${i.toLowerCase()}`,b(i,e.config.site.openingHours)));if(!a)return{error:`Couldn't read the hours for ${i}. Write them like 9:00-17:00, with at most two ranges.`,state:n};r.push(...a)}return{config:{...e.config,site:{...e.config.site,openingHours:r}},state:n}}function Ht(t,n){let r={tab:W.identity},i=pt(t.config.site.sameAs),a=[...ft.map(e=>J(n,`profile_${e.id}`,i.named[e.id]??``)),...bt(J(n,`profiles`,i.other.join(`
6
- `)))].filter(e=>e!==``),o=[];for(let t of a){let n=e(/^https?:\/\//i.test(t)?t:`https://${t}`);if(!n||!n.host.includes(`.`))return{error:`"${t}" is not a web address. Paste the full link to the profile.`,state:r};o.push(n.href)}return{config:{...t.config,site:{...t.config.site,sameAs:o}},state:r}}function Ut(e,t){let n={tab:W.identity},{site:r}=e.config,i=J(t,`founded`,r.foundingDate??``);return i!==``&&!/^\d{4}(-\d{2}-\d{2})?$/.test(i)?{error:`Write the founding date as a year, like 2012, or as 2012-05-01.`,state:n}:{config:{...e.config,site:{...r,alternateName:J(t,`alternate_name`,r.alternateName??``)||void 0,legalName:J(t,`legal_name`,r.legalName??``)||void 0,foundingDate:i||void 0}},state:n}}function Wt(e,t){let{robots:n}=e.config,r=J(t,`snippet`,n.nosnippet?`none`:`full`),i=J(t,`image_preview`,n.maxImagePreview);return{config:{...e.config,breadcrumbs:yt(t,`breadcrumbs`,e.config.breadcrumbs),robots:{...n,nosnippet:r===`none`,maxSnippet:r===`short`?160:-1,maxImagePreview:i===`none`||i===`standard`||i===`large`?i:n.maxImagePreview}},state:{tab:W.types}}}function Gt(e,t,n){let r={tab:W.types},[i,a]=typeof t==`string`?t.split(`|`):[];if(!i||!e.collections.some(e=>e.slug===i))return{error:`That content type no longer exists.`,state:r};let o=e.config.collections[i]??{},s=n===`type`?x.find(e=>e.value===a)?.value:o.type??Ft(e,i);if(!s)return{error:`Choose one of the listed types.`,state:r};let c=n===`visible`?a===`hide`:o.noindex===!0;return{config:{...e.config,collections:{...e.config.collections,[i]:{type:s,noindex:c}},steps:{...e.config.steps,types:!0}},state:r}}async function Kt(e,t){if(t.scan?.status===`done`)return St(e,t);let n=t.scan?await H(e,t.scan,t.config):await at(e,t.collections.map(e=>e.slug),t.config);return{...t,scan:n,stats:n.status===`done`?n.tally:null}}async function qt(e,n,r){let i=await xt(r),a=(n??0)>=50,o=vt(e)?e:{},s=typeof o.action_id==`string`?o.action_id:``;if(o.type===`page_load`&&o.page===`widget:seo`)return Nt(await Kt(r,i));if(!a||o.type===`page_load`||s===``)return Y(await Kt(r,i),r,a,{tab:W.overview});let c=async(e,n=`Saved. Google will pick this up next time it visits.`)=>{if(`error`in e)return Y(i,r,a,{...e.state,toast:{type:`error`,message:e.error}});let o=h(e.config);return await r.kv.set(t,o),ut(r.plugin.id),Y({...i,config:o},r,a,{...e.state,toast:{type:`success`,message:n}})},l=async e=>{try{let{rows:t,more:n}=await he(r);return{...e,redirectRows:t,moreRedirects:n}}catch{return e}},u=async(e,t,n)=>e?Y(i,r,a,{tab:W.redirects,editing:n,...n?{}:{panel:`add`},problem:e}):Y(await l(i),r,a,{tab:W.redirects,toast:{type:`success`,message:t}});if(o.type===`block_action`){if(s===`check_pages`||s===`check_more`){let e=await Kt(r,s===`check_pages`?{...i,scan:null}:i);return Y(e,r,a,{tab:W.overview,toast:e.scan?.status===`done`?{type:`success`,message:`All pages checked.`}:{type:`info`,message:`${e.scan?.checked??0} pages checked so far. The rest follow in the background.`}})}if(s===`set_type`)return c(Gt(i,o.value,`type`));if(s===`set_visible`){let[e,t]=typeof o.value==`string`?o.value.split(`|`):[];return t===`hide`?Y(i,r,a,{tab:W.types,pendingHide:e}):c(Gt(i,o.value,`visible`),`These pages can appear on Google again.`)}if(s===`confirm_hide`&&typeof o.value==`string`)return c(Gt(i,`${o.value}|hide`,`visible`),`These pages are now hidden from Google and other search engines.`);if(s===`cancel_hide`)return Y(i,r,a,{tab:W.types});if(s===`hidden_ok`){let e={...i.config.collections};for(let t of Dt(i))e[t.slug]={...e[t.slug],hiddenOk:!0};return c({config:{...i.config,collections:e},state:{tab:W.overview}},`Noted. These pages stay hidden from search.`)}if(s===`edit_redirect`){let e=i.redirectRows.find(e=>e.id===o.value);return Y(i,r,a,{tab:W.redirects,editing:e})}if(s===`open_add`)return Y(i,r,a,{tab:W.redirects,panel:`add`});if(s===`open_import`)return Y(i,r,a,{tab:W.redirects,panel:`import`});if(s===`close_panel`)return Y(i,r,a,{tab:W.redirects});if(s===`remove_redirect`&&typeof o.value==`string`)return u(await be(r,o.value),`Redirect removed.`);if(s===`add_redirects`||s===`more_redirects`){if(!i.redirects||i.redirects.status===`done`)return Y(i,r,a,{tab:W.redirects});let e=await le(r,i.redirects);return Y(await l({...i,redirects:e}),r,a,{tab:W.redirects,toast:e.status===`done`?{type:`success`,message:`${N(e.added,`redirect`)} added.`}:{type:`info`,message:`${e.added} added so far. The rest follow in the background.`}})}if(s===`stop_redirects`&&i.redirects?.status===`adding`){let e=await we(r,i.redirects);return Y({...i,redirects:e},r,a,{tab:W.redirects,toast:{type:`info`,message:`Stopped. ${N(e.added,`redirect`)} added.`}})}if(s===`reset_redirects`)return i.redirects?.status!==`adding`&&await r.kv.delete(j),Y({...i,redirects:i.redirects?.status===`adding`?i.redirects:null},r,a,{tab:W.redirects});if(s===`remove_redirects`&&i.redirects){let e=await ue(r,i.redirects);return Y(await l({...i,redirects:e===0?null:i.redirects}),r,a,{tab:W.redirects,toast:e===0?{type:`success`,message:`Removed. Your other redirects are untouched.`}:{type:`info`,message:`${e} still to remove. Press Remove again.`}})}if(s===`export_redirects`){let{text:e,count:t}=await de(r);return Y(i,r,a,{tab:W.redirects,panel:`export`,exported:e,toast:{type:`info`,message:`${N(t,`redirect`)} listed below.`}})}return Y(i,r,a,{tab:W.overview})}if(o.type!==`form_submit`)return Y(i,r,a,{tab:W.overview});let d=vt(o.values)?o.values:{};if(s===`check_redirects`){let e=J(d,`list`);if(e===``)return Y(i,r,a,{tab:W.redirects,toast:{type:`error`,message:`Paste a list first.`}});let t=await se(r,e);return Y({...i,redirects:t},r,a,{tab:W.redirects,toast:{type:`success`,message:`Checked. Nothing has been added yet.`}})}if(s===`add_redirect`){let e=J(d,`source`),t=J(d,`code`,`301`)===`410`?``:J(d,`destination`);return u(await ve(r,e,t,J(d,`code`,`301`)),t===``?`Done. ${e} now tells visitors the page was removed.`:`Redirect added. ${e} now goes to ${t}.`)}if(s.startsWith(`save_redirect:`)){let e=s.slice(14),t=i.redirectRows.find(t=>t.id===e);return u(await ye(r,e,J(d,`source`,t?.source??``),J(d,`destination`,t?.destination??``),J(d,`code`,String(t?.type??301))),`Redirect changed.`,t)}if(s===`setup_identity`){let e=Rt(i,d);if(`error`in e)return c(e);let t=J(d,`street`),n=J(d,`town`),{site:r}=e.config,a=t!==``||n!==``?{...r.address,...t?{streetAddress:t}:{},...n?{addressLocality:n}:{}}:r.address;return c({config:{...e.config,site:{...r,address:a}},state:{tab:W.overview}})}return s===`save_identity`?c(Rt(i,d)):s===`save_logo`?c(zt(i,d,r.site.url)):s===`save_contact`?c(Bt(i,d)):s===`save_hours`?c(Vt(i,d)):s===`save_profiles`?c(Ht(i,d)):s===`save_company`?c(Ut(i,d)):s===`save_advanced`?c(Wt(i,d)):Y(i,r,a,{tab:W.overview})}function X(e){return{"@id":e}}function Z(e){let t={};for(let[n,r]of Object.entries(e))r==null||r===``||Array.isArray(r)&&r.length===0||(t[n]=r);return t}function Jt(t,n){return e(t,n)?.href??t}function Yt(t,n){return(t.siteUrl||n||(e(t.url)?.origin??``)).replace(/\/+$/,``)}function Xt(t,n){if(t.canonical)return Jt(t.canonical,`${n}/`);let r=e(t.url,`${n}/`);return r?(r.search=``,r.hash=``,r.href):t.url}function Zt(e){return e.path===`/`||e.path===``}function Qt(e){return r.includes(e)}function $t(e,t,n){let r=e.content?t.collections[e.content.collection]:void 0;if(n?.type)return n.type;if(r?.type)return r.type;let i=e.content?a(e.content.collection):`WebPage`;return i===`WebPage`?e.pageType===`article`?`BlogPosting`:`WebPage`:i}function en(e,t,n,r){let i=`${n}/#logo`,a=e.type===`Person`,o=!a&&e.type!==`Organization`&&e.address===void 0?`Organization`:e.type,s=!a&&(e.address!==void 0||e.geo!==void 0||e.openingHours.length>0);return Z({"@type":o,"@id":r,name:t,alternateName:e.alternateName,legalName:a?void 0:e.legalName,description:e.description,url:`${n}/`,logo:e.logo&&!a?{"@type":`ImageObject`,"@id":i,url:e.logo,contentUrl:e.logo,caption:t}:void 0,image:e.logo?a?e.logo:X(i):void 0,sameAs:e.sameAs,email:e.email,telephone:e.telephone,address:e.address?{"@type":`PostalAddress`,...e.address}:void 0,geo:e.geo&&!a?{"@type":`GeoCoordinates`,...e.geo}:void 0,openingHoursSpecification:s?e.openingHours.map(e=>({"@type":`OpeningHoursSpecification`,dayOfWeek:e.days,opens:e.opens,closes:e.closes})):void 0,priceRange:a?void 0:e.priceRange,areaServed:a?void 0:e.areaServed,foundingDate:a?void 0:e.foundingDate,vatID:a?void 0:e.vatID,taxID:a?void 0:e.taxID,numberOfEmployees:!a&&e.numberOfEmployees?{"@type":`QuantitativeValue`,value:e.numberOfEmployees}:void 0})}function tn(e){let t=e;try{t=decodeURIComponent(e)}catch{}let n=t.replace(/[-_]+/g,` `).trim();return n.charAt(0).toUpperCase()+n.slice(1)}function nn(e,t,n){let{page:r,config:i,site:a}=e;if(r.breadcrumbs)return r.breadcrumbs.map(e=>({name:e.name,url:Jt(e.url,`${t}/`)}));if(!i.breadcrumbs||Zt(r))return[];let o=r.path.split(`/`).filter(e=>e!==``);if(o.length===0)return[];let s=a.trailingSlash===`always`?`/`:``,c=[{name:`Home`,url:`${t}/`}],l=``;return o.forEach((e,r)=>{l+=`/${e}`;let i=r===o.length-1;c.push({name:i?n:tn(e),url:`${t}${l}${s}`})}),c}function rn(e,t){return e.length<=t?e:`${e.slice(0,t-1).trimEnd()}…`}function an(e,t,n){let r;for(let{"@context":i,...a}of t){let t=typeof a[`@id`]==`string`?a[`@id`]:void 0;if(t!==void 0){if(n.has(t))continue;n.add(t),r??=t}e.push(a)}return r}function on(e){let{page:t,config:n,record:r,site:i}=e,a=Yt(t,i.url),o=Xt(t,a),s=t.locale??i.locale,c=n.site.name??t.siteName??i.name,l=t.pageTitle??t.title??c,u=n.site.type===`Person`,d=`${a}/#${u?`person`:`organization`}`,f=`${a}/#website`,p=o,m=`${o}#breadcrumb`,h=$t(t,n,r),g=Qt(h),_=h===`Service`,v=h===`ProfilePage`,y=`${o}#service`,b=`${o}#person`,x=r?.publishedAt??t.articleMeta?.publishedTime??void 0,S=r?.updatedAt??t.articleMeta?.modifiedTime??void 0,C=t.image?Jt(t.image,`${a}/`):void 0,w=C??``,T=nn(e,a,l),E=[en(n.site,c,a,d),Z({"@type":`WebSite`,"@id":f,url:`${a}/`,name:c,alternateName:n.site.alternateName,description:n.site.description,publisher:X(d),inLanguage:s})];if(e.noindex)return E;let D=Z({"@type":g||_?`WebPage`:h,"@id":p,url:o,name:l,description:t.description,isPartOf:X(f),about:Zt(t)?X(d):void 0,primaryImageOfPage:C?X(w):void 0,image:C?X(w):void 0,breadcrumb:T.length>0?X(m):void 0,mainEntity:_?X(y):v?X(b):void 0,datePublished:x,dateModified:S,inLanguage:s});if(E.push(D),g){let e=(r?.authors??[]).map(e=>Z({"@type":`Person`,name:e.name,url:e.url})),n=t.articleMeta?.author?[{"@type":`Person`,name:t.articleMeta.author}]:[X(d)];E.push(Z({"@type":h,"@id":`${o}#article`,isPartOf:X(p),mainEntityOfPage:X(p),headline:rn(l,110),description:t.description,image:C?X(w):void 0,datePublished:x,dateModified:S,author:e.length>0?e:n,publisher:X(d),inLanguage:s}))}_&&E.push(Z({"@type":`Service`,"@id":y,name:l,description:t.description,url:o,image:C?X(w):void 0,provider:X(d),areaServed:n.site.areaServed})),v&&E.push(Z({"@type":`Person`,"@id":b,name:l,description:t.description,url:o,image:C?X(w):void 0,worksFor:u?void 0:X(d)})),C&&E.push({"@type":`ImageObject`,"@id":w,url:C,contentUrl:C,...Ge(r?.images,C,a)}),T.length>0&&E.push({"@type":`BreadcrumbList`,"@id":m,itemListElement:T.map((e,t)=>Z({"@type":`ListItem`,position:t+1,name:e.name,item:t===T.length-1?void 0:e.url}))});let O=new Set([`${a}/#logo`]);for(let e of E)typeof e[`@id`]==`string`&&O.add(e[`@id`]);let k=an(E,r?.custom??[],O);return k!==void 0&&!g&&D.mainEntity===void 0&&(D.mainEntity=X(k)),E}const sn=`default`;function cn(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function ln(t){let n=e(t);if(!n)return t;let r=n.pathname.split(`/`).filter(e=>e!==``);return[n.host,...r].join(` › `)}function un(e,t){return e.length<=t?e:`${e.slice(0,t-1).trimEnd()}…`}async function dn(n,r,i,o){if(!r)return{blocks:[]};let s=(i??0)>=50,c=cn(n)?n:{},l=h(await o.kv.get(t)),u=I(o),d=F(r.collection,r.id),f,p=s&&c.type===`block_action`&&c.action_id===`set_type`,[m,g]=await Promise.all([tt(o,r.collection,r.id,l),o.content?.getPublicUrl?.(r.collection,r.id)]),_=m?.record,v=m?.entry;if(_&&p){let e=typeof c.value==`string`?c.value:sn,t=x.find(t=>t.value===e)?.value,{type:n,...r}=_;_=t?{...r,type:t}:r,await u.put(d,_),f={type:`success`,message:`Saved. Google will pick this up next time it visits.`}}if(!_||!v)return{blocks:[{type:`context`,text:`Save this page to see how it may look on Google.`}]};if(_.status===`skip`)return{blocks:[{type:`context`,text:`This kind of content has no page of its own, so Google only sees it inside other pages. There is nothing to set here.`}]};let y=l.site.name??o.site.name,b=o.site.url.replace(/\/+$/,``),C=[`home`,`index`,``].includes(v.slug??``)?`${b}/`:`${b}/${v.slug}`,w=[`home`,`index`].includes(v.slug??``)?`${b}/`:g??C,T=_.title||`(no title)`,E=v.seo?.description?.trim()??``,D=E===``&&Ne(v.data)!==``,O=E||Ne(v.data),k=l.collections[r.collection]?.type??a(r.collection),ee=_.type??k,te=_.status===`hidden`,ne=_.issues??[],A=[{type:`context`,text:y?`${y} · ${ln(w)}`:ln(w)},{type:`header`,text:Oe(T)},{type:`section`,text:O===``?`No description yet. Google will pick some text from the page.`:un(O,160)},...D?[{type:`context`,text:`This description is the page's excerpt. To write a different one for search, fill in Meta Description in the SEO panel.`}]:[],{type:`context`,text:`What Google sees: the published page, with the SEO title and description as last saved. Google may rewrite them, and your site may add its name to the title.`},{type:`fields`,fields:[{label:`Shown to Google as`,value:S(ee)},{label:`In search results`,value:_.status===`draft`?`Not published yet`:te?`Hidden from search`:`Yes`}]}];if(ne.length===0)A.push({type:`context`,text:`Nothing to fix on this page.`});else{let e=[...ne].sort((e,t)=>Number(t.level===`fix`)-Number(e.level===`fix`));for(let t of e.slice(0,3))A.push({type:`section`,text:`${t.level===`fix`?`To fix`:`Worth a look`}: ${t.message}`},{type:`context`,text:t.fix});e.length>3&&A.push({type:`context`,text:`And ${e.length-3} more.`})}if(s){let t=on({page:{url:w,path:e(w)?.pathname??`/`,locale:v.locale,kind:`content`,pageType:`website`,title:T,pageTitle:T,description:O===``?null:O,canonical:v.seo?.canonical??null,image:null,content:{collection:r.collection,id:r.id,slug:v.slug}},config:l,record:_,noindex:te,site:o.site});A.push({type:`divider`},{type:`actions`,elements:[{type:`menu`,action_id:`set_type`,label:`Change page type`,items:[{label:`Same as other pages here (${S(k)})`,value:sn},...x.map(({value:e,label:t})=>({value:e,label:t}))]},.../^https?:\/\//.test(w)?[{type:`link`,label:`Test on Google`,target:{kind:`external`,url:`https://search.google.com/test/rich-results?url=${encodeURIComponent(w)}`}}]:[]]},{type:`accordion`,label:`View the markup`,blocks:[{type:`context`,text:`The schema markup (JSON-LD) this page sends to search engines.`},{type:`code`,language:`jsonc`,code:JSON.stringify({"@context":`https://schema.org`,"@graph":t},null,2)}]})}return{blocks:A,...f?{toast:f}:{}}}const fn=/\s*,\s*/;function pn(e,t,n){let r=(e??``).toLowerCase().split(fn).map(e=>e.trim()).filter(e=>e!==``),i=t||r.includes(`noindex`)||r.includes(`none`),a=r.includes(`nofollow`)||r.includes(`none`),o=[i?`noindex`:`index`,a?`nofollow`:`follow`],s=new Set([`index`,`noindex`,`follow`,`nofollow`,`none`,`all`]),c=r.filter(e=>!s.has(e));if(!i){let e=e=>c.some(t=>t.startsWith(e));n.nosnippet||c.includes(`nosnippet`)?c.includes(`nosnippet`)||c.push(`nosnippet`):e(`max-snippet:`)||c.push(`max-snippet:${n.maxSnippet}`),e(`max-image-preview:`)||c.push(`max-image-preview:${n.maxImagePreview}`),e(`max-video-preview:`)||c.push(`max-video-preview:${n.maxVideoPreview}`)}return[...o,...new Set(c)].join(`, `)}function mn(e){return e.startsWith(`noindex`)}async function Q(e){return h(await e.kv.get(t))}function hn(e){return/[?&]_preview=/.test(e)}async function $(e,t,n){let r=n?.id;if(typeof r==`string`)try{await et(e,t,r,await Q(e))}catch(n){e.log.warn(`could not refresh entry record`,{collection:t,id:r,error:String(n)})}}const gn={hooks:{"page:metadata":async(e,t)=>{let{page:n}=e,r=n.content,[i,a]=await Promise.all([lt(t,()=>Q(t),{fresh:hn(n.url)}),(async()=>{if(!r)return null;try{return{stored:await I(t).get(F(r.collection,r.id))}}catch(e){return{error:e}}})()]),o=null;if(r&&a){let{collection:e,id:i}=r;try{if(`error`in a)throw a.error;let{stored:r}=a,s=I(t);o=r??await et(t,e,i,await Q(t));let c=!!(n.seo?.ogImage||n.image);if(r&&Qe(r,c)){let t=await s.get(F(e,i)),n=t?Qe(t,c):null;n&&await s.put(F(e,i),n),o=n??t??r}}catch(n){t.log.warn(`could not load entry record`,{collection:e,id:i,error:String(n)})}}let s=n.content?i.collections[n.content.collection]:void 0,c=pn(n.seo?.robots,s?.noindex===!0,i.robots);return[{kind:`meta`,name:`robots`,content:c},{kind:`jsonld`,id:`primary`,graph:{"@context":`https://schema.org`,"@graph":on({page:n,config:i,record:o,noindex:mn(c),site:t.site})}}]},"content:afterSave":async(e,t)=>{await $(t,e.collection,e.content)},"content:afterPublish":async(e,t)=>{await $(t,e.collection,e.content)},"content:afterUnpublish":async(e,t)=>{await $(t,e.collection,e.content)},"content:afterRestore":async(e,t)=>{await $(t,e.collection,e.content)},"plugin:activate":async(e,t)=>{try{if(await it(t))return;let e=await at(t,(await t.schema?.listCollections()??[]).filter(e=>e.routable&&!e.hidden).map(e=>e.slug),await Q(t));e.status===`done`&&e.checked===0&&await t.kv.delete(R)}catch(e){t.log.warn(`could not start the first page check`,{error:String(e)})}},cron:async(e,t)=>{if(e.name===z){let e=await it(t);e?.status===`running`?await H(t,e,await Q(t)):await t.cron?.cancel(z);return}if(e.name!==M)return;let n=await ae(t);n?.status===`adding`?await le(t,n):await t.cron?.cancel(M)},"content:afterDelete":async(e,t)=>{await nt(t,e.collection,e.id)}},routes:{admin:{permission:`plugins:read`,handler:async(e,t)=>qt(e.input,e.user?.role,t)},"editor/preview":{permission:`content:read`,handler:async(e,t)=>dn(e.input,e.ui?.entry,e.user?.role,t)},hello:{handler:async(e,t)=>(t.log.info(`hello route called`,{pluginId:t.plugin.id}),{greeting:`hello`,pluginId:t.plugin.id})}}};export{gn as default};
1
+ function e(e){return e!=null}async function t(e,t,n){try{await e.settings.set(t.name,n)}catch(n){e.log.warn(`could not copy the settings to their new place`,{key:t.name,error:String(n)})}}async function n(n,r){let i=await n.settings.get(r.name);if(e(i))return i;let a=await n.kv.get(r.legacy);return e(a)?(await t(n,r,a),a):null}async function r(n,r,i){let a=r.get(`settings:${i.name}`);if(e(a))return a;let o=r.get(i.legacy);return e(o)?(await t(n,i,o),o):null}async function i(e,t,n){await e.settings.set(t.name,n);try{await e.kv.set(t.legacy,n)}catch(n){e.log.warn(`could not keep a copy of the settings for the earlier release`,{key:t.legacy,error:String(n)})}}function a(e,t){try{return new URL(e,t)}catch{return null}}const o={name:`config`,legacy:`config`};async function s(e){return x(await n(e,o))}const c=[`WebPage`,`AboutPage`,`ContactPage`,`CollectionPage`,`ProfilePage`],l=[`Article`,`BlogPosting`,`NewsArticle`],u=[`Service`];function d(e){let t=e.toLowerCase();return[`posts`,`post`,`blog`].includes(t)?`BlogPosting`:[`news`,`articles`,`article`].includes(t)?`Article`:[`services`,`service`].includes(t)?`Service`:[`team`,`people`,`staff`,`authors`].includes(t)?`ProfilePage`:`WebPage`}const f={site:{type:`Organization`,sameAs:[],openingHours:[],areaServed:[]},collections:{},robots:{maxSnippet:-1,maxImagePreview:`large`,maxVideoPreview:-1,nosnippet:!1},jsonLdField:`json_ld`,breadcrumbs:!0,steps:{identity:!1,types:!1}};function p(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function m(e){if(typeof e!=`string`)return;let t=e.trim();return t===``?void 0:t}function h(e){let t=m(e),n=t?a(t)?.protocol:void 0;return n===`https:`||n===`http:`?t:void 0}function g(e,t){return typeof e==`number`&&Number.isInteger(e)&&e>=-1?e:t}function _(e){let t=[...c,...l,...u];return typeof e==`string`&&t.includes(e)?e:void 0}function v(e){if(!p(e))return;let t={};for(let n of[`streetAddress`,`addressLocality`,`addressRegion`,`postalCode`,`addressCountry`]){let r=m(e[n]);r&&(t[n]=r)}return Object.keys(t).length>0?t:void 0}function y(e){if(!Array.isArray(e))return[];let t=[];for(let n of e){if(!p(n)||!Array.isArray(n.days))continue;let e=n.days.filter(e=>typeof e==`string`&&e!==``),r=m(n.opens),i=m(n.closes);e.length>0&&r&&i&&t.push({days:e,opens:r,closes:i})}return t}function b(e){if(!p(e))return{...f.site};let t=p(e.geo)?e.geo:void 0,n=t?.latitude,r=t?.longitude;return{type:m(e.type)??`Organization`,name:m(e.name),alternateName:m(e.alternateName),legalName:m(e.legalName),description:m(e.description),logo:h(e.logo),sameAs:Array.isArray(e.sameAs)?e.sameAs.map(h).filter(e=>e!==void 0):[],email:m(e.email),telephone:m(e.telephone),address:v(e.address),geo:typeof n==`number`&&typeof r==`number`?{latitude:n,longitude:r}:void 0,openingHours:y(e.openingHours),priceRange:m(e.priceRange),areaServed:Array.isArray(e.areaServed)?e.areaServed.map(m).filter(e=>e!==void 0):[],foundingDate:m(e.foundingDate),vatID:m(e.vatID),taxID:m(e.taxID),numberOfEmployees:typeof e.numberOfEmployees==`number`&&e.numberOfEmployees>0?Math.round(e.numberOfEmployees):void 0}}function x(e){if(!p(e))return f;let t={};if(p(e.collections))for(let[n,r]of Object.entries(e.collections))p(r)&&(t[n]={type:_(r.type),noindex:r.noindex===!0,...r.hiddenOk===!0?{hiddenOk:!0}:{}});let n=p(e.robots)?e.robots:{},r=n.maxImagePreview;return{site:b(e.site),collections:t,robots:{maxSnippet:g(n.maxSnippet,f.robots.maxSnippet),maxImagePreview:r===`none`||r===`standard`||r===`large`?r:f.robots.maxImagePreview,maxVideoPreview:g(n.maxVideoPreview,f.robots.maxVideoPreview),nosnippet:n.nosnippet===!0},jsonLdField:m(e.jsonLdField)??f.jsonLdField,breadcrumbs:e.breadcrumbs!==!1,steps:{identity:p(e.steps)&&e.steps.identity===!0,types:p(e.steps)&&e.steps.types===!0}}}const S=[`Monday`,`Tuesday`,`Wednesday`,`Thursday`,`Friday`,`Saturday`,`Sunday`],C=/^(\d{1,2})(?:[:.](\d{2}))?\s*[-–—]\s*(\d{1,2})(?:[:.](\d{2}))?$/;function w(e,t){let n=Number(e),r=Number(t??`0`);return n>24||r>59||n===24&&r!==0?null:`${String(n).padStart(2,`0`)}:${String(r).padStart(2,`0`)}`}function T(e,t){let n=t.trim();if(n===``||n.toLowerCase()===`closed`)return[];let r=n.split(/\s*[,;]\s*|\s+and\s+/i).filter(e=>e!==``);if(r.length>2)return null;let i=[];for(let t of r){let n=C.exec(t);if(!n)return null;let r=w(n[1]??``,n[2]),a=w(n[3]??``,n[4]);if(!r||!a)return null;i.push({days:[e],opens:r,closes:a})}return i}function E(e,t){return t.filter(t=>t.days.includes(e)).map(e=>`${e.opens}-${e.closes}`).join(`, `)}const D=[{value:`WebPage`,label:`Web page`,short:`Web page`},{value:`AboutPage`,label:`About page`,short:`About page`},{value:`ContactPage`,label:`Contact page`,short:`Contact page`},{value:`BlogPosting`,label:`Blog post`,short:`Blog post`},{value:`Article`,label:`Article`,short:`Article`},{value:`Service`,label:`Service`,short:`Service`},{value:`ProfilePage`,label:`Person or team member`,short:`Person`}];function O(e){return D.find(t=>t.value===e)?.short??e}const k=[301,302,307,308,410,451],A=2e3,j={empty:`No old address`,query:`Addresses with a ? are not supported`,external:`Points to another website`,noTarget:`No new address`,same:`Old and new address are the same`,code:`Unknown redirect type`,pattern:`Uses a pattern. Add it by hand under Manage > Redirects`,inactive:`Switched off in the export`,repeated:`Listed twice`,exists:`Already exists`,conflict:`Conflicts with an existing redirect`,loop:`Would send visitors in a circle`,tooMany:`Only the first ${A} rows are imported at once`};function M(e,t){let n=[],r=``,i=!1;for(let a=0;a<e.length;a+=1){let o=e[a];i?o===`"`&&e[a+1]===`"`?(r+=`"`,a+=1):o===`"`?i=!1:r+=o:o===`"`?i=!0:o===t?(n.push(r.trim()),r=``):r+=o}n.push(r.trim());let a=n[0]??``;return n.length===1&&/\S\s+\S/.test(a)?a.split(/\s+/):n}const ee={source:`source`,origin:`source`,from:`source`,"old url":`source`,old:`source`,sources:`source`,target:`target`,destination:`target`,to:`target`,"new url":`target`,new:`target`,url_to:`target`,regex:`regex`,code:`code`,"http code":`code`,type:`code`,header_code:`code`,format:`format`,matching:`matching`,status:`status`,ignore:`ignore`,id:`id`};function te(e,t){let n=e.map(e=>ee[e.toLowerCase()]),r=n.includes(`source`)&&n.includes(`target`);if(r){let e={};return n.forEach((t,n)=>{t&&e[t]===void 0&&(e[t]=n)}),{format:e.matching===void 0?e.format===void 0?e.regex===void 0?`plain`:`redirection`:`yoast`:`rankmath`,hasHeader:r,index:e}}let i=t.slice(0,20),a=i.map(e=>e[2]??``),o=i.map(e=>(e[3]??``).toLowerCase());return o.length>0&&o.every(e=>e===`plain`||e===`regex`)?{format:`yoast`,hasHeader:r,index:{source:0,target:1,code:2,format:3}}:a.length>0&&a.every(e=>e===`0`||e===`1`)?{format:`redirection`,hasHeader:r,index:{source:0,target:1,regex:2,code:3}}:{format:`plain`,hasHeader:r,index:{source:0,target:1,code:2}}}function ne(e){let t=e.trim();if(t===``)return{reason:j.empty};if(/^https?:\/\//i.test(t)){let e=a(t);if(!e)return{reason:j.empty};t=`${e.pathname}${e.search}`}return t.includes(`?`)?{reason:j.query}:(t.startsWith(`/`)||(t=`/${t}`),t.length>1&&(t=t.replace(/\/+$/,``)),{path:t===``?`/`:t})}const re=/[\\^$.*+?()[\]{}|]/;function ie(e,t){let n=e.trim();if(n.startsWith(`^`)&&(n=n.slice(1)),n.endsWith(`$`)&&(n=n.slice(0,-1)),n.endsWith(`/?`)&&(n=n.slice(0,-2)),!re.test(n))return{source:n,target:t};let r=/^(\/[^\\^$.*+?()[\]{}|]*\/)\(\.\*\)$/.exec(n);return r&&!/\$[2-9]/.test(t)?{source:`${r[1]}[...rest]`,target:t.replace(/\$1/g,`[...rest]`)}:null}function ae(e){if(e===void 0||e.trim()===``)return 301;let t=Number(e.trim());return k.includes(t)?t:null}function oe(e,t){let n=e.split(/\r?\n/),r=n.some(e=>e.includes(` `))?` `:`,`,i=n.map((e,t)=>({line:t+1,cells:M(e,r)})).filter(e=>e.cells.some(e=>e!==``)),o=i[0];if(!o)return{format:`plain`,ready:[],skipped:[]};let s=te(o.cells,i.map(e=>e.cells)),c=s.hasHeader?i.slice(1):i,l=(e,t)=>{let n=s.index[t];return n===void 0?void 0:e[n]},u=[],d=[],f=new Map(t.map(e=>[e.source,e.destination])),p=new Set;for(let{line:e,cells:t}of c){let n=l(t,`source`)??``,r=t=>d.push({line:e,source:n,reason:t});if(u.length>=A){r(j.tooMany);continue}if([`inactive`,`disabled`].includes((l(t,`status`)??`active`).toLowerCase())){r(j.inactive);continue}let i=ae(l(t,`code`));if(i===null){r(j.code);continue}let o=n,s=l(t,`target`)??``,c=(l(t,`matching`)??`exact`).toLowerCase();if(l(t,`regex`)===`1`||(l(t,`format`)??``).toLowerCase()===`regex`||c===`regex`){let e=ie(o,s);if(!e){r(j.pattern);continue}o=e.source,s=e.target}else if(c===`start`&&o.trim().endsWith(`/`))o=`${o.trim()}[...rest]`;else if(c!==`exact`){r(j.pattern);continue}let m=ne(o);if(`reason`in m){r(m.reason);continue}let h=i===410||i===451,g=``;if(!h){if(s.trim()===``){r(j.noTarget);continue}let e=/^https?:\/\//i.test(s.trim()),t=/^https?:\/\//i.test(n.trim())?a(n.trim())?.host:void 0;if(e&&t!==a(s.trim())?.host){r(j.external);continue}let i=ne(s);if(`reason`in i){r(i.reason===j.empty?j.noTarget:i.reason);continue}if(g=i.path,g===m.path){r(j.same);continue}}if(p.has(m.path)){r(j.repeated);continue}let _=f.get(m.path);if(_!==void 0){r(_===g?j.exists:j.conflict);continue}p.add(m.path),u.push({line:e,source:m.path,destination:g,type:i})}let m=new Map(f);for(let e of u)m.set(e.source,e.destination);let h=[];for(let e of u){let t=e.destination,n=!1;for(let r=0;r<20&&t!==``&&m.has(t);r+=1)if(t=m.get(t)??``,t===e.source){n=!0;break}n?d.push({line:e.line,source:e.source,reason:j.loop}):h.push({source:e.source,destination:e.destination,type:e.type})}return{format:s.format,ready:h,skipped:d}}function se(e){let t=e=>/[",\n]/.test(e)?`"${e.replace(/"/g,`""`)}"`:e;return[`source,target,code`,...e.map(e=>`${t(e.source)},${t(e.destination)},${e.type}`)].join(`
2
+ `)}const N=`redirects`,P=`redirects-import`,ce={redirection:`Redirection`,yoast:`Yoast SEO Premium`,rankmath:`Rank Math`,plain:`a plain list`};async function le(e){let t=await e.kv.get(N);return t&&Array.isArray(t.rows)?t:null}async function ue(e){let t=[],n;for(let r=0;r<5;r+=1){let r=await e.redirects?.list({limit:100,cursor:n});if(!r||(t.push(...r.items),n=r.hasMore?r.cursor:void 0,!n))break}return t}async function de(e,t){let n=oe(t,await ue(e)),r={status:`checked`,format:n.format,rows:n.ready,skipped:n.skipped,cursor:0,added:0,group:`Imported ${new Date().toISOString().slice(0,16).replace(`T`,` `)}`};return await e.kv.set(N,r),r}function fe(e){let t=e instanceof Error?e.message:String(e);return/already exists/i.test(t)?{kind:`exists`,message:t}:/invalid source pattern|must be different|destination|path traversal|loop/i.test(t)?{kind:`invalid`,message:t}:{kind:`stop`,message:t}}async function pe(e,t){let n={...t,status:`adding`,skipped:[...t.skipped]},r=async()=>{try{return await e.kv.set(N,n),!0}catch{return!1}};if(t.status===`checked`)try{await e.cron?.schedule(P,{schedule:`* * * * *`})}catch(t){e.log.warn(`could not schedule background import`,{error:String(t)})}let i=0,a=n.cursor;for(;n.cursor<n.rows.length;){let t=n.rows[n.cursor];if(!t)break;try{await e.redirects?.create?.({source:t.source,destination:t.destination,type:t.type,groupName:n.group}),n.added+=1}catch(e){let{kind:r,message:i}=fe(e);if(r===`stop`){if(n.cursor!==a||(n.stalls=(n.stalls??0)+1,n.stalls<3))break;n.skipped.push({line:0,source:t.source,reason:`EmDash could not add it: ${i}`})}else r===`exists`?n.added+=1:n.skipped.push({line:0,source:t.source,reason:`EmDash refused it: ${i}`})}if(n.cursor+=1,n.stalls=0,i+=1,i>=4){if(!await r())return n;i=0}}if(n.cursor>=n.rows.length){n.status=`done`;try{await e.cron?.cancel(P)}catch{}}return await r(),n}async function me(e,t){let n=await e.redirects?.list({limit:100,group:t.group}),r=n?.items??[],i=r.length;for(let t of r)try{let n=await e.redirects?.get(t.id);n&&await e.redirects?.delete?.(t.id,{_rev:n._rev}),--i}catch{break}if(i===0&&!n?.hasMore){try{await e.cron?.cancel(P)}catch{}return await e.kv.delete(N),0}return i}async function he(e){let t=[],n;for(let r=0;r<5;r+=1){let r=await e.redirects?.list({limit:100,cursor:n});if(!r||(t.push(...r.items),n=r.hasMore?r.cursor:void 0,!n))break}return{text:se(t),count:t.length}}function F(e,t){return`${e} ${t}${e===1?``:`s`}`}function ge(e){if(e.length===0)return[];let t=[{type:`header`,text:`Skipped (${e.length})`},{type:`context`,text:`Skipped rows are not added. Copy any you still need and add them by hand under Manage > Redirects, which also accepts patterns.`},{type:`table`,page_action_id:`skipped_table`,columns:[{key:`line`,label:`Row`},{key:`source`,label:`Old address`},{key:`reason`,label:`Why`}],rows:e.slice(0,50).map(e=>({line:e.line>0?String(e.line):``,source:e.source,reason:e.reason}))}];return e.length>50&&t.push({type:`context`,text:`And ${e.length-50} more.`}),t}const _e=[{value:`301`,label:`Permanent`},{value:`302`,label:`Temporary, the old address will come back`},{value:`410`,label:`Page removed on purpose, no new address`}];function ve(e){return e===301||e===308?`Permanent`:e===302||e===307?`Temporary`:e===410?`Deleted on purpose`:String(e)}async function ye(e){let t=await e.redirects?.list({limit:20});return{rows:(t?.items??[]).map(({id:e,source:t,destination:n,type:r,hits:i})=>({id:e,source:t,destination:n,type:r,hits:i})),more:t?.hasMore??!1}}function be(e){let t=e instanceof Error?e.message:String(e);return/already exists/i.test(t)?`There is already a redirect from that old address. Use Change in the list below.`:/must be different/i.test(t)?`The old and new address are the same.`:/loop/i.test(t)?`That would send visitors in a circle.`:/changed since/i.test(t)?`That redirect was just changed elsewhere. Try again.`:`EmDash could not save that redirect. Check both addresses start with /.`}function xe(e,t,n){let r=oe(se([{source:e,destination:t,type:Number(n)||301}]),[]);return r.ready[0]??r.skipped[0]?.reason??`Type the old address first.`}async function Se(e,t,n,r){let i=xe(t,n,r);if(typeof i==`string`)return`${i}.`;try{return await e.redirects?.create?.(i),null}catch(e){return be(e)}}async function Ce(e,t,n,r,i){let a=xe(n,r,i);if(typeof a==`string`)return`${a}.`;try{let n=await e.redirects?.get(t);return n?(await e.redirects?.update?.(t,{...a,_rev:n._rev}),null):`That redirect no longer exists.`}catch(e){return be(e)}}async function we(e,t){try{let n=await e.redirects?.get(t);return n&&await e.redirects?.delete?.(t,{_rev:n._rev}),null}catch(e){return be(e)}}function Te(e){if(!e)return[{type:`context`,text:`Paste a list exported from Redirection, Yoast SEO Premium or Rank Math, or any list of old address, new address. Nothing is added until you confirm.`},{type:`form`,block_id:`redirects`,fields:[{type:`text_input`,action_id:`list`,label:`Your list, one redirect per line`,multiline:!0,placeholder:`/old-page,/new-page`,initial_value:``}],submit:{label:`Check list`,action_id:`check_redirects`}}];if(e.status===`checked`){let t=e.rows.length;return[{type:`banner`,variant:t===0?`alert`:`default`,title:`${t} ready, ${e.skipped.length} skipped`,description:t===0?`Nothing in this list can be added. See why below.`:`Read as ${ce[e.format]}. Nothing has been added yet. Existing redirects are never changed.`},{type:`actions`,elements:[...t>0?[{type:`button`,action_id:`add_redirects`,label:`Add ${F(t,`redirect`)}`,style:`primary`,confirm:{title:`Add ${F(t,`redirect`)}?`,text:`Visitors to these old addresses will be sent to the new ones. You can remove them all again afterwards.`,confirm:`Add`,deny:`Cancel`}}]:[],{type:`button`,action_id:`reset_redirects`,label:`Start again`}]},...ge(e.skipped)]}return e.status===`adding`?[{type:`meter`,label:`${e.added} of ${e.rows.length} added`,value:e.cursor,max:e.rows.length},{type:`context`,text:`The rest are added in the background, a few each minute. You can leave this page.`},{type:`actions`,elements:[{type:`button`,action_id:`more_redirects`,label:`Add more now`,style:`primary`},{type:`button`,action_id:`stop_redirects`,label:`Stop here`}]}]:[{type:`banner`,title:`${F(e.added,`redirect`)} added from your list`,description:`They are labelled "${e.group}".`},{type:`actions`,elements:[{type:`button`,action_id:`reset_redirects`,label:`Import another list`},...e.added>0?[{type:`button`,action_id:`remove_redirects`,label:`Remove the ${e.added} just added`,confirm:{title:`Remove these redirects?`,text:`Only the redirects this import added are removed.`,confirm:`Remove`,deny:`Cancel`,style:`danger`}}]:[]]},...ge(e.skipped)]}function Ee(e,t){let n=e?String(e.type):`301`;return{type:`form`,block_id:e?`edit_redirect_${e.id}`:`add_one_${t}`,fields:[{type:`text_input`,action_id:`source`,label:`Redirect from`,placeholder:`/old-page`,initial_value:e?.source??``},{type:`text_input`,action_id:`destination`,label:`Redirect to`,placeholder:`/new-page`,initial_value:e?.destination??``,condition:{field:`code`,neq:`410`}},{type:`select`,action_id:`code`,label:`Kind`,options:_e.some(e=>e.value===n)?_e:[..._e,{value:n,label:`${ve(Number(n))} (${n})`}],initial_value:n}],submit:e?{label:`Save changes`,action_id:`save_redirect:${e.id}`}:{label:`Add redirect`,action_id:`add_redirect`}}}function De(e){let{state:t,rows:n,editing:r}=e,i=r?void 0:e.panel??(t?`import`:void 0),a=n[0]?.id??`first`,o=[{type:`context`,text:`Send visitors from an old address to a new one. Pages you rename in EmDash are redirected for you.`},{type:`actions`,elements:[{type:`button`,action_id:`open_add`,label:`Add a redirect`,...i===void 0&&!r?{style:`primary`}:{}},{type:`button`,action_id:`open_import`,label:`Import from WordPress`},{type:`button`,action_id:`export_redirects`,label:`Export`},...e.managerUrl?[{type:`link`,label:`Full Redirects screen`,target:{kind:`external`,url:e.managerUrl}}]:[]]}],s={type:`actions`,elements:[{type:`button`,action_id:`close_panel`,label:`Close`}]},c=e.problem?[{type:`banner`,variant:`error`,title:e.problem}]:[];return r?o.push({type:`header`,text:`Change a redirect`},...c,Ee(r,a),s,{type:`divider`}):i===`add`?o.push({type:`header`,text:`Add a redirect`},...c,Ee(void 0,a),s,{type:`divider`}):i===`import`?(o.push({type:`header`,text:`Import from WordPress`},...Te(t)),t||o.push(s),o.push({type:`divider`})):i===`export`&&o.push({type:`header`,text:`Export`},{type:`context`,text:`Copy this list to keep a backup or to paste into a spreadsheet. It can be imported again here.`},{type:`code`,code:e.exported??``,language:`bash`},s,{type:`divider`}),n.length===0?o.push({type:`empty`,title:`No redirects yet`,description:`Add one, or import a list from your old site.`,size:`sm`}):(o.push({type:`table`,page_action_id:`redirects_table`,columns:[{key:`source`,label:`Redirect from`},{key:`destination`,label:`Redirect to`},{key:`kind`,label:`Kind`},{key:`hits`,label:`Visits`,format:`number`},{key:`edit`,label:``,format:`element`},{key:`remove`,label:``,format:`element`}],rows:n.map(e=>({source:e.source,destination:e.destination||`(none)`,kind:ve(e.type),hits:e.hits,edit:{type:`button`,action_id:`edit_redirect`,label:`Change`,value:e.id},remove:{type:`button`,action_id:`remove_redirect`,label:`Remove`,value:e.id,confirm:{title:`Remove this redirect?`,text:`Visitors to ${e.source} will see a not-found page.`,confirm:`Remove`,deny:`Keep`,style:`danger`}}}))}),e.more&&o.push({type:`context`,text:`Showing the newest ${n.length}. The rest are in the full Redirects screen.`})),o}async function Oe(e,t){let n={...t,status:`done`};try{await e.cron?.cancel(P)}catch{}return await e.kv.set(N,n),n}const ke=new Set("iIl.,:;|!'`jtfr ()[]".split(``)),Ae=new Set(`mwMWQO@%`.split(``));function je(e){let t=0;for(let n of e)ke.has(n)?t+=5:Ae.has(n)?t+=15:n>=`A`&&n<=`Z`?t+=12:t+=9.5;return Math.round(t)}function Me(e){if(je(e)<=580)return e;let t=e;for(;t.length>1&&je(`${t}…`)>580;)t=t.slice(0,-1);return`${t.trimEnd()}…`}function Ne(e){return e.toLowerCase().replace(/\s+/g,` `).trim()}const Pe=new Set([`home`,`homepage`,`home page`,`index`,`untitled`,`welcome`]),Fe=new Set([`_type`,`_key`,`id`,`slug`,`url`,`href`,`src`,`style`,`icon`]);function Ie(e){let t={textLength:0,imagesWithoutAlt:0,hasImage:!1},n=(e,r,i)=>{if(i>12)return;if(typeof e==`string`){!Fe.has(r)&&!/^(https?:)?\//.test(e)&&(t.textLength+=e.trim().length);return}if(Array.isArray(e)){for(let t of e)n(t,r,i+1);return}if(typeof e!=`object`||!e)return;let a=e;(a._type===`image`||typeof a.src==`string`&&`alt`in a)&&(t.hasImage=!0,(typeof a.alt!=`string`||a.alt.trim()===``)&&(t.imagesWithoutAlt+=1));for(let[e,t]of Object.entries(a))n(t,e,i+1)};for(let[t,r]of Object.entries(e))t!==`json_ld`&&n(r,t,0);return t}const I={id:`no-social-image`,level:`look`,message:`This page has no picture for shared links, unless your site has a default sharing image.`,fix:`Add an image in the SEO panel. If your theme adds a picture itself, this clears once the page has been viewed.`};function Le(e){return typeof e.excerpt==`string`?e.excerpt.trim():``}function Re(e){let t=[],{seo:n}=e,r=Ie(e.data),i=n?.title?.trim()||e.title.trim();if(i===``&&t.push({id:`no-title`,level:`fix`,message:`This page has no title.`,fix:`Give the page a title.`}),Pe.has(i.toLowerCase())&&t.push({id:`generic-title`,level:`fix`,message:`The title is just "${i}", which is what Google shows as the headline.`,fix:`Put your name and what you do in SEO Title, in the page's SEO panel.`}),n&&!n.description?.trim()&&Le(e.data)===``&&t.push({id:`no-description`,level:`fix`,message:`No search description, so Google writes its own summary of this page.`,fix:`Fill in Meta Description in the page's SEO panel.`}),e.duplicateTitle&&i!==``&&t.push({id:`duplicate-title`,level:`fix`,message:`Another page has the same title, so Google cannot tell them apart.`,fix:`Give this page its own title in the SEO panel.`}),n?.canonical&&e.slug){let r=a(n.canonical,`${e.siteUrl.replace(/\/+$/,``)}/`),i=r?.pathname.replace(/\/+$/,``).split(`/`).pop(),o=[`home`,`index`].includes(e.slug)&&(i??``)===``;r&&i!==e.slug&&!o&&t.push({id:`canonical-elsewhere`,level:`fix`,message:`This page tells Google to show a different page instead (canonical).`,fix:`Clear the canonical address in the SEO panel unless that is intended.`})}if(i!==``&&je(i)>580&&t.push({id:`title-long`,level:`look`,message:`The end of this title may be cut off in Google.`,fix:`Shorten the title, or put the important words first.`}),n&&!n.image&&!r.hasImage&&t.push(I),e.isArticle&&e.authorCount===0&&t.push({id:`no-author`,level:`look`,message:`This article has no author.`,fix:`Add a byline to the article.`}),r.imagesWithoutAlt>0){let e=r.imagesWithoutAlt;t.push({id:`images-without-alt`,level:`look`,message:`${e} ${e===1?`picture has`:`pictures have`} no description for screen readers.`,fix:`Add alt text to each picture.`})}return r.textLength<80&&t.push({id:`nearly-empty`,level:`look`,message:`This page has almost no text.`,fix:`Add some content, or hide the page from search.`}),t}function ze(e,t){return t?`hidden`:e.some(e=>e.level===`fix`)?`fix`:e.length>0?`look`:`ready`}const Be=/^[0-9A-HJKMNP-TV-Z]{26}(\.[A-Za-z0-9]+)?$/i;function Ve(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function He(e){return typeof e==`number`&&Number.isFinite(e)&&e>=1?Math.round(e):void 0}function Ue(e){if(!e.startsWith(`/_emdash/api/media/file/`))return;let t=e.slice(24);try{t=decodeURIComponent(t)}catch{return}return t!==``&&!t.includes(`/`)?t:void 0}function We(e,t){let n=a(e,`${t.replace(/\/+$/,``)}/`);if(!n||!/^https?:$/.test(n.protocol)||n.search!==``)return[];let{pathname:r}=n;if(r===`/_image`||r.includes(`/cdn-cgi/image/`))return[];let i=Ue(r);if(i)return[`file:${i}`];let o=[`url:${n.origin}${r}`],s=r.slice(1);return Be.test(s)&&o.push(`file:${s}`),o}function Ge(e){if(typeof e!=`string`||e===``)return[];if(e.startsWith(`/`)){let t=e.includes(`?`)?void 0:Ue(e);return t?[`file:${t}`]:[]}return/^https?:\/\//i.test(e)?We(e,`http://localhost`).filter(e=>e.startsWith(`url:`)):[]}function Ke(e){return typeof e==`string`&&e!==``&&!e.includes(`/`)?[`file:${e}`]:[]}function qe(e){let t=He(e.width),n=He(e.height);if(t===void 0||n===void 0||typeof e.mimeType==`string`&&!e.mimeType.startsWith(`image/`))return;let r=[];if(e._type===`image`&&Ve(e.asset))r.push(...Ke(e.asset._ref),...Ge(e.asset.url));else if(typeof e.id==`string`){if(e.provider===void 0||e.provider===`local`){let t=Ve(e.meta)?e.meta:{};r.push(...Ke(t.storageKey),...Ke(e.id))}r.push(...Ge(e.src))}let i=[...new Set(r)];return i.length>0?{keys:i,width:t,height:n}:void 0}function Je(e){let t=[],n=new Set,r=(e,i)=>{if(t.length>=10||i>12)return;if(Array.isArray(e)){for(let t of e)r(t,i+1);return}if(!Ve(e))return;let a=qe(e);if(a&&!a.keys.some(e=>n.has(e))){for(let e of a.keys)n.add(e);t.push(a)}for(let t of Object.values(e))r(t,i+1)};for(let[t,n]of Object.entries(e))t!==`json_ld`&&r(n,0);return t.slice(0,10)}function Ye(e,t,n){if(!e||e.length===0)return;let r=We(t,n);if(r.length===0)return;let i=e.find(e=>e.keys.some(e=>r.includes(e)));return i?{width:i.width,height:i.height}:void 0}const Xe=16*1024;function L(e,t){return`${e}:${t}`}function R(e){return e.storage.entries}function Ze(e){return typeof e==`object`&&!!e&&!Array.isArray(e)&&`@type`in e}function Qe(e){let t=e;if(typeof e==`string`){if(e.trim()===``||e.length>Xe)return[];try{t=JSON.parse(e)}catch{return[]}}let n=(Array.isArray(t)?t:[t]).filter(Ze);return JSON.stringify(n).length>Xe?[]:n}function $e(e){let{title:t,name:n}=e.data;return typeof t==`string`?t:typeof n==`string`?n:``}function z(e){let{collection:t,entry:n,authors:r,previous:i,config:a,siteUrl:o}=e,s=a.collections[t],c=i?.type??s?.type??d(t),u=n.seo?.title?.trim()||$e(n),f=n.status===`published`,p=f&&e.hasPages,m=e.hasPages?Re({slug:n.slug,data:n.data,seo:n.seo,title:$e(n),siteUrl:o,isArticle:l.includes(c),authorCount:r.length,duplicateTitle:e.duplicateTitle}):[],h=m.some(e=>e.id===I.id),g=h&&i?.imageSeen===!0,_=g?m.filter(e=>e.id!==I.id):m,v=e.hasPages?Je(n.data):[];return{v:1,publishedAt:n.publishedAt,updatedAt:n.updatedAt,authors:r,...i?.type?{type:i.type}:{},custom:Qe(n.data[a.jsonLdField]),...v.length>0?{images:v}:{},needsImage:h,...g?{imageSeen:g}:{},collection:t,entryId:n.id,title:u,status:e.hasPages?f?ze(_,n.seo?.noIndex===!0||s?.noindex===!0):`draft`:`skip`,titleKey:p?Ne(u):``,issues:_,checkedAt:new Date().toISOString()}}function et(e,t){return e.status===`hidden`||e.status===`draft`||e.status===`skip`?e.status:ze(t,!1)}function tt(e,t){let n=e.issues??[],r=n.some(e=>e.id===I.id);if(!(e.needsImage??r)||e.imageSeen===!0===t&&r!==t)return null;let i=n.filter(e=>e.id!==I.id),a=t?i:[...i,I],{imageSeen:o,...s}=e;return{...s,needsImage:!0,...t?{imageSeen:!0}:{},issues:a,status:et(e,a)}}async function nt(e,t){return(await rt(e,[t]))[0]??[]}async function rt(e,t){let n=[...new Set(t.filter(e=>e!==``))];if(n.length===0)return t.map(()=>[]);let r=await R(e).query({where:{titleKey:n.length===1?n[0]??``:{in:n}},limit:10*n.length});return t.map(e=>e===``?[]:r.items.filter(t=>t.data.titleKey===e))}function B(e){return e.issues?.some(e=>e.id===`duplicate-title`)??!1}function it(e,t){let n=e.length>1;for(let{id:r,data:i}of e)B(i)!==n&&t.set(r,V(i,n))}function V(e,t){let n=(e.issues??[]).filter(e=>e.id!==`duplicate-title`),r=t?[...n,{id:`duplicate-title`,level:`fix`,message:`Another page has the same title, so Google cannot tell them apart.`,fix:`Give this page its own title in the SEO panel.`}]:n;return{...e,issues:r,status:et(e,r)}}async function at(e,t,n,r){return(await st(e,t,n,r))?.record??null}async function ot(e,t,n,r){let i=await e.content?.get(t,n);if(!i)return null;let a=R(e),o=L(t,n),[s,c,l]=await Promise.all([e.bylines?.getEntriesBylines(t,[n])??[],a.get(o),e.schema?.getCollection(t)]),u=z({collection:t,entry:i,authors:(s[0]?.bylines??[]).map(({byline:e})=>({name:e.displayName,...e.websiteUrl?{url:e.websiteUrl}:{}})),previous:c,config:r,siteUrl:e.site.url,duplicateTitle:!1,hasPages:l?l.routable&&!l.hidden:!0}),d=u.titleKey??``,f=c?.titleKey??``;return{entry:i,previous:c,record:V(u,d!==``&&d===f&&c!==null&&B(c)),newKey:d,oldKey:f}}async function st(e,t,n,r){let i=await ot(e,t,n,r);if(!i)return null;let{entry:a,record:o,newKey:s,oldKey:c}=i,l=R(e),u=L(t,n);await l.put(u,o);let[d=[],f=[]]=await rt(e,[s,c===s?``:c]),p=new Map,m=d,h=d.find(e=>e.id===u)?.data;if(s!==``&&h?.checkedAt!==o.checkedAt){let e=h??f.find(e=>e.id===u)?.data??null;e&&lt(e.updatedAt,o.updatedAt)&&(p.set(u,o),m=[...d.filter(e=>e.id!==u),{id:u,data:o}])}return it(m,p),it(f.filter(e=>e.id!==u),p),p.size>0&&await l.putMany([...p].map(([e,t])=>({id:e,data:t}))),{record:p.get(u)??o,entry:a}}async function ct(e,t,n,r,i){let a=await ot(e,t,n,r);if(!a)return null;let{entry:o,previous:s,newKey:c,oldKey:l}=a,u=i?i(a.record):a.record,d=L(t,n);return s===null||c===l?await R(e).put(d,u):i&&await R(e).put(d,i(s)),{record:u,entry:o}}function lt(e,t){if(!e||!t)return!1;let n=Date.parse(e),r=Date.parse(t);return Number.isFinite(n)&&Number.isFinite(r)&&n<r}async function ut(e,t,n){let r=R(e),i=L(t,n),a=await r.get(i);await r.delete(i);let o=new Map;it((await nt(e,a?.titleKey??``)).filter(e=>e.id!==i),o),o.size>0&&await r.putMany([...o].map(([e,t])=>({id:e,data:t})))}const H=`scan`,dt=`stats`,U=`seo-scan`,ft=[`ready`,`look`,`fix`,`hidden`];async function pt(e){return e.kv.get(H)}async function mt(e,t,n){let r={status:`running`,collections:t,scope:[...t],phase:`entries`,checked:0,tally:{checked:0,fix:0,hidden:0,rows:[],more:!1},startedAt:new Date().toISOString()};try{await e.cron?.schedule(U,{schedule:`* * * * *`})}catch(t){e.log.warn(`could not schedule background check`,{error:String(t)})}return yt(e,r,n)}async function ht(e,t,n){let r=t.collections[0];if(r===void 0){t.phase=`titles`;return}let i=new Date().toISOString(),a=e=>(e.checkedAt??``)>=t.startedAt,o=await e.content?.list(r,{limit:20,cursor:t.cursor,where:{status:`published`}}),s=o?.items??[];if(s.length>0){let c=R(e),l=s.map(e=>e.id),[u,d]=await Promise.all([e.bylines?.getEntriesBylines(r,l)??[],c.getMany(l.map(e=>L(r,e)))]),f=new Map(u.map(e=>[e.entryId,e.bylines])),p=new Set,m=s.map(t=>{let o=L(r,t.id),s=d.get(o)??null;return s&&(lt(t.updatedAt,s.updatedAt)&&a(s)||(s.checkedAt??``)>=i)?(p.add(o),{id:o,data:s}):{id:o,data:z({hasPages:!0,collection:r,entry:t,authors:(f.get(t.id)??[]).map(({byline:e})=>({name:e.displayName,...e.websiteUrl?{url:e.websiteUrl}:{}})),previous:s,config:n,siteUrl:e.site.url,duplicateTitle:s?B(s):!1})}});if(t.cursor===void 0&&t.checked===0&&!o?.hasMore&&t.collections.length===1){let e=new Map;for(let{data:t}of m)t.titleKey&&e.set(t.titleKey,(e.get(t.titleKey)??0)+1);for(let t of m){let n=(e.get(t.data.titleKey??``)??0)>1;p.has(t.id)&&B(t.data)!==n&&p.delete(t.id),t.data=V(t.data,n)}t.status=`done`,t.finishedAt=new Date().toISOString(),t.sweep={}}let h=m.filter(e=>!p.has(e.id));h.length>0&&await c.putMany(h);for(let{data:e}of m)vt(t.tally,e,1);t.checked+=s.length}o?.hasMore&&o.cursor?t.cursor=o.cursor:(t.cursor=void 0,t.collections=t.collections.slice(1),t.collections.length===0&&t.status!==`done`&&(t.phase=`titles`,t.sweep={}))}async function gt(e,t,n){let r=new Set(t.scope??[]),i=R(e),a=t.sweep?.cursor,o=new Set(t.sweep?.kept??[]),s=r.size>0&&e.content?await i.query({where:{status:{in:ft}},limit:100,cursor:a}):{items:[],hasMore:!1,cursor:void 0},c=s.items.filter(({id:e,data:n})=>!o.has(e)&&r.has(n.collection??``)&&(n.entryId??``)!==``&&(n.checkedAt??``)<t.startedAt).slice(0,1),l=await Promise.all(c.map(({data:t})=>e.content?.get(t.collection??``,t.entryId??``))),u=[],d=[];c.forEach(({id:t,data:r},i)=>{let a=l[i];a?a.status===`published`?o.add(t):d.push({id:t,data:z({hasPages:!0,collection:r.collection??``,entry:a,authors:r.authors,previous:r,config:n,siteUrl:e.site.url,duplicateTitle:!1})}):u.push(t)}),u.length>0&&await i.deleteMany(u),d.length>0&&await i.putMany(d);let f=o.size>0?{kept:[...o]}:{};c.length>0?t.sweep={...a?{cursor:a}:{},...f}:s.hasMore&&s.cursor?t.sweep={cursor:s.cursor,...f}:delete t.sweep}async function _t(e,t){let n=R(e),r=await n.query({orderBy:{titleKey:`asc`},limit:100,cursor:t.titleCursor}),i=r.items.filter(e=>(e.data.titleKey??``)!==``),a=new Map(i.map(e=>[e.id,e.data])),o=new Map,s=(e,t,n)=>{B(t)!==n&&o.set(e,n)},c=t.lastTitle;for(let e=0;e<i.length;e+=1){let t=i[e];if(!t)continue;let r=t.data.titleKey??``,o=i[e+1],l=c?.key===r,u=o?.data.titleKey===r;if(l&&c&&!c.flagged&&e===0){let e=await n.get(c.id);e&&(a.set(c.id,e),s(c.id,e,!0))}let d=l||u;s(t.id,t.data,d),c={key:r,id:t.id,flagged:d}}if(o.size>0){let e=new Set([...o.keys()].map(e=>a.get(e)?.titleKey??``)),r=[...a].filter(([,t])=>e.has(t.titleKey??``)).map(([e])=>e),i=await n.getMany(r);for(let t of r){let n=a.get(t),r=i.get(t);(!n||r?.checkedAt!==n.checkedAt||r?.titleKey!==n.titleKey)&&e.delete(n?.titleKey??``)}let s=[];for(let[n,r]of o){let i=a.get(n);if(!i||!e.has(i.titleKey??``))continue;let o=V(i,r);s.push({id:n,data:o}),vt(t.tally,i,-1),vt(t.tally,o,1)}s.length>0&&await n.putMany(s)}t.lastTitle=c,r.hasMore&&r.cursor?t.titleCursor=r.cursor:(t.status=`done`,t.finishedAt=new Date().toISOString(),t.titleCursor=void 0,t.lastTitle=void 0)}function W(e,t=`fix`){return{collection:e.collection??``,id:e.entryId??``,title:e.title||`(no title)`,issues:(e.issues??[]).filter(e=>e.level===t).map(e=>e.message)}}function vt(e,t,n){if(!(!t.status||t.status===`draft`||t.status===`skip`)){if(e.checked+=n,t.status===`hidden`){e.hidden+=n;let r=e.hiddenTitles??[],i=t.title||`(no title)`;e.hiddenTitles=n===1?[...r,i].slice(0,10):r.filter(e=>e!==i)}if(t.status===`look`){let r=e.look??[];e.look=n===1?[...r,W(t,`look`)].slice(0,10):r.filter(e=>e.id!==t.entryId)}t.status===`fix`&&(e.fix+=n,n===1?e.rows.length<10?e.rows.push(W(t)):e.more=!0:e.rows=e.rows.filter(e=>e.id!==t.entryId))}}async function yt(e,t,n){let r={...t,collections:[...t.collections],tally:{...t.tally,rows:[...t.tally.rows]}};if(r.status===`done`&&!r.sweep)return r;if(r.sweep)await gt(e,r,n);else if(r.phase===`entries`){for(let t=0;t<5&&r.phase===`entries`;t+=1){let t=r.checked;if(await ht(e,r,n),r.checked!==t||r.status===`done`)break}r.phase===`titles`&&r.checked===0&&(r.status=`done`,r.finishedAt=new Date().toISOString())}else await _t(e,r);if(r.status===`done`&&!r.sweep)try{await e.cron?.cancel(U)}catch{}return await e.kv.set(H,r),r}async function bt(e){let t=R(e),[n,r,i,a,o]=await Promise.all([t.count({status:{in:[`ready`,`look`,`fix`,`hidden`]}}),t.count({status:`fix`}),t.query({where:{status:`fix`},limit:10}),t.query({where:{status:`look`},limit:10}),t.query({where:{status:`hidden`},limit:10})]);return{checked:n,fix:r,hidden:o.hasMore?11:o.items.length,rows:i.items.map(({data:e})=>W(e)),more:i.hasMore,look:a.items.map(({data:e})=>W(e,`look`)),hiddenTitles:o.items.map(({data:e})=>e.title||`(no title)`)}}const xt=new Map;async function St(e,t,{fresh:n=!1,now:r=Date.now()}={}){let i=e.site?.url??``,a=xt.get(e.plugin.id);a||xt.set(e.plugin.id,a=new Map);let o=a.get(i);if(n||!o||r>=o.until){let e=t(),n={value:e,until:r+3e4};a.set(i,n),e.catch(()=>{a.get(i)===n&&a.delete(i)}),o=n}return structuredClone(await o.value)}function Ct(e){xt.delete(e)}const G={overview:0,redirects:1,identity:2,types:2},K=[{value:`FoodEstablishment`,label:`Restaurant, cafe or bakery`},{value:`Store`,label:`Shop`},{value:`MedicalBusiness`,label:`Health and medical`},{value:`Dentist`,label:`Dentist`},{value:`LegalService`,label:`Legal`},{value:`FinancialService`,label:`Financial`},{value:`HomeAndConstructionBusiness`,label:`Home services (plumber, electrician, builder)`},{value:`HealthAndBeautyBusiness`,label:`Beauty and hair`},{value:`SportsActivityLocation`,label:`Fitness`},{value:`LodgingBusiness`,label:`Hotel or lodging`},{value:`AutomotiveBusiness`,label:`Automotive`},{value:`ProfessionalService`,label:`Professional service`},{value:`LocalBusiness`,label:`Other`}],wt=[``,`$`,`$$`,`$$$`,`$$$$`],Tt=[{id:`facebook`,label:`Facebook`,hosts:[`www.facebook.com`,`facebook.com`,`fb.com`]},{id:`instagram`,label:`Instagram`,hosts:[`www.instagram.com`,`instagram.com`]},{id:`linkedin`,label:`LinkedIn`,hosts:[`www.linkedin.com`,`linkedin.com`]},{id:`x`,label:`X (Twitter)`,hosts:[`x.com`,`www.x.com`,`twitter.com`,`www.twitter.com`]},{id:`youtube`,label:`YouTube`,hosts:[`www.youtube.com`,`youtube.com`]}];function Et(e){let t={},n=[];for(let r of e){let e=a(r)?.host??``,i=Tt.find(t=>t.hosts.includes(e));i&&!(i.id in t)?t[i.id]=r:n.push(r)}return{named:t,other:n}}const Dt={needed:`needed`,worth:`worth adding`,optional:`optional`};function q(e,t,n){let r=n.filter(e=>!!e);return r.length>0?`${e}: ${r.join(`, `)}`:`${e} (${Dt[t]}, not added yet)`}function Ot(e){return S.map(t=>{let n=E(t,e.openingHours).replace(`, `,` and `);return n===``?void 0:`${t.slice(0,3)} ${n}`}).filter(e=>e!==void 0)}function kt(e){let{site:t}=e.config,n=J(t),r=[];return n===`local`?((!t.address?.streetAddress||!t.address.addressLocality)&&r.push({what:`Address`,why:`Without it Google cannot treat you as a local business.`}),t.openingHours.length===0&&r.push({what:`Opening hours`,why:`Google cannot show when you are open.`}),t.telephone||r.push({what:`Phone number`,why:`Customers cannot call you from Google.`})):(n===`organization`&&!t.logo&&r.push({what:`Logo`,why:`Google shows it beside your name.`}),t.sameAs.length===0&&r.push({what:`Profiles elsewhere`,why:`They help Google connect your other pages to this site.`})),r}function J(e){return e.type===`Person`?`person`:e.type===`Organization`?`organization`:`local`}function At(e,t){let n=a(e);if(!(!n||n.protocol!==`https:`&&n.protocol!==`http:`))return`${n.origin}${t}`}function jt(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Y(e,t,n=``){let r=e[t];return typeof r==`string`?r.trim():n}function Mt(e,t,n){let r=e[t];return typeof r==`boolean`?r:n}function Nt(e){return e.split(/\r?\n/).map(e=>e.trim()).filter(e=>e!==``)}async function Pt(e){let[t,n,i]=await Promise.all([e.kv.list(),e.schema?.listCollections()??[],ye(e)]),a=new Map(t.map(e=>[e.key,e.value])),s=a.get(N);return{config:x(await r(e,a,o)),collections:n.filter(e=>e.routable&&!e.hidden),redirects:s&&Array.isArray(s.rows)?s:null,redirectRows:i.rows,moreRedirects:i.more,scan:a.get(H)??null,stats:a.get(dt)??null}}async function Ft(e,t){let n=await bt(e);return JSON.stringify(n)!==JSON.stringify(t.stats)&&await e.kv.set(dt,n),{...t,stats:n}}function It(e){return e.stats??(e.scan?.status===`done`?e.scan.tally:null)}function Lt(e){let{scan:t}=e,n=It(e);if(!t||t.status===`running`)return[{type:`banner`,title:`Checking your pages`,description:t?`${t.checked} checked so far. The rest are checked in the background.`:`This starts by itself and takes about a minute.`}];if(!n)return[];let r=n.checked-n.fix-n.hidden;return[{type:`stats`,items:[{label:`Pages checked`,value:n.checked},{label:`Nothing to fix`,value:r},{label:`To fix`,value:n.fix}]}]}function Rt(e){let{scan:t}=e,n=It(e);if(!n||!t||t.status===`running`)return[];let r=[];n.checked===0?r.push({type:`empty`,title:`No published pages yet`,size:`sm`}):n.fix===0?r.push({type:`empty`,title:`No pages to fix. Nice work.`,size:`sm`}):(r.push({type:`header`,text:`To fix`},{type:`table`,page_action_id:`fix_table`,columns:[{key:`page`,label:`Page`},{key:`missing`,label:`What's missing`},{key:`open`,label:``,format:`element`}],rows:n.rows.map(e=>({page:e.title,missing:e.issues.join(` `),open:{type:`link`,label:`Open page`,target:{kind:`content`,collection:e.collection,id:e.id}}}))}),n.more&&r.push({type:`context`,text:`Showing the first 10. Fix these and the next ones appear.`}));let i=n.look??[];if(i.length>0&&r.push({type:`accordion`,label:`Worth a look (${i.length}${i.length===10?`+`:``})`,blocks:[{type:`context`,text:`Nothing is wrong with these pages. These are improvements for when you have time.`},{type:`table`,page_action_id:`look_table`,columns:[{key:`page`,label:`Page`},{key:`advice`,label:`Could be better`},{key:`open`,label:``,format:`element`}],rows:i.map(e=>({page:e.title,advice:e.issues.join(` `),open:{type:`link`,label:`Open page`,target:{kind:`content`,collection:e.collection,id:e.id}}}))}]}),n.hidden>0){let e=(n.hiddenTitles??[]).join(`, `);r.push({type:`context`,text:`${n.hidden>10?`More than 10`:n.hidden} ${n.hidden===1?`page is`:`pages are`} hidden from Google and not counted${e?`: ${e}`:``}. To show one again, open it and switch off "Hide from search engines" in its SEO panel.`})}if(t.finishedAt){let e=new Date(t.finishedAt).toLocaleDateString(`en-GB`,{day:`numeric`,month:`short`});r.push({type:`context`,text:`Each page is checked again when it is saved. Last full check: ${e}.`})}return r}function zt(e){if(!e.scan)return[];let t=e.scan.status===`running`;return[{type:`actions`,elements:[{type:`button`,action_id:t?`check_more`:`check_pages`,label:t?`Update`:`Check all pages again`}]}]}function Bt(e){return e.collections.filter(t=>{let n=e.config.collections[t.slug];return n?.noindex===!0&&n.hiddenOk!==!0})}function Vt(e,t){let n=Bt(e);if(n.length===0)return[];let r=[{type:`banner`,variant:`alert`,title:`Some pages are hidden from Google`,description:`Every page in ${n.map(e=>e.label).join(`, `)} is hidden from search engines. If that is a leftover from building the site, switch it back on in the Settings tab, under Content types.`}];return t&&r.push({type:`actions`,elements:[{type:`button`,action_id:`hidden_ok`,label:`This is intended`}]}),r}function Ht(e,t){let{steps:n,site:r}=e.config;return n.identity?[]:[{type:`banner`,title:`Tell Google who this site is for`,description:`Google can then show your name and details beside your pages. It takes a minute.`},{type:`accordion`,label:`Set this up (1 minute)`,default_open:!0,blocks:[{type:`form`,block_id:`setup_identity`,fields:[{type:`radio`,action_id:`kind`,label:`This site is for`,options:[{label:`A local business customers visit (shop, cafe, clinic)`,value:`local`},{label:`A company or organisation`,value:`organization`},{label:`A person`,value:`person`}]},{type:`select`,action_id:`business`,label:`Kind of business`,options:[{label:`Choose the closest`,value:``},...K],initial_value:``,condition:{field:`kind`,eq:`local`}},{type:`text_input`,action_id:`name`,label:`Name`,placeholder:`Your name or your business's name`,initial_value:r.name??t},{type:`text_input`,action_id:`street`,label:`Street address`,initial_value:r.address?.streetAddress??``,condition:{field:`kind`,eq:`local`}},{type:`text_input`,action_id:`town`,label:`Town or city`,initial_value:r.address?.addressLocality??``,condition:{field:`kind`,eq:`local`}}],submit:{label:`Save`,action_id:`setup_identity`}}]}]}function Ut(e,t){let{site:n}=e.config,r=J(n),i=K.find(e=>e.value===n.type)?.label,a=r===`person`?`a person`:r===`local`?(i??`a local business`).toLowerCase():`a company`,o=[n.address?.streetAddress,n.address?.addressLocality].filter(Boolean).join(`, `),s=Ot(n);return[`Google is told: ${n.name??t}, ${a}`,o?`, ${o}`:``,s.length>0?`, open ${s.join(`, `)}`:``,`. Change this in the Settings tab.`].join(``)}function Wt(e,t){if(!e.config.steps.identity)return[];let n=kt(e);return n.length===0?[{type:`context`,text:Ut(e,t)}]:[{type:`header`,text:`Your details`},{type:`context`,text:`${n.length} ${n.length===1?`thing`:`things`} Google needs from you. Add ${n.length===1?`it`:`them`} in the Settings tab.`},{type:`table`,page_action_id:`details_table`,columns:[{key:`what`,label:`Missing`},{key:`why`,label:`Why it matters`}],rows:n}]}function Gt(e,t){return[...Lt(e),...Vt(e,!0),...Ht(e,t),...Wt(e,t),...Rt(e),...zt(e)]}function Kt(e){let t=It(e),n={type:`actions`,elements:[{type:`link`,label:`Open SEO`,target:{kind:`plugin-page`,path:`/overview`}}]};if(!t||t.checked===0){let{steps:t}=e.config;return{blocks:[{type:`section`,text:t.identity?`Your pages are being checked.`:`One thing left: tell Google who this site is for.`},n]}}return{blocks:[{type:`stats`,items:[t.fix===0?{label:`SEO`,value:`All pages ready`}:{label:t.fix===1?`Page to fix`:`Pages to fix`,value:t.fix}]},n]}}function qt(e,t){let{site:n}=e.config,r=J(n),i=r===`local`,o=e.config.steps.identity,s=Et(n.sameAs),c=[{type:`context`,text:`Google reads these details from your site and can show them beside your pages. Sections marked needed are followed up on the Overview; the rest are up to you.`},{type:`form`,block_id:`identity`,fields:[{type:`radio`,action_id:`kind`,label:`This site is for`,options:[{label:`A local business customers visit (shop, cafe, clinic)`,value:`local`},{label:`A company or organisation`,value:`organization`},{label:`A person`,value:`person`}],...o?{initial_value:r}:{}},{type:`select`,action_id:`business`,label:`Kind of business`,options:[{label:`Choose the closest`,value:``},...K],initial_value:i?n.type:``,condition:{field:`kind`,eq:`local`}},{type:`text_input`,action_id:`name`,label:`Name`,placeholder:`Your name or your business's name`,initial_value:n.name??t},{type:`text_input`,action_id:`description`,label:`What you do, in one or two sentences`,multiline:!0,initial_value:n.description??``}],submit:{label:`Save`,action_id:`save_identity`}},{type:`context`,text:`Each section below is saved with its own Save button.`}],l={type:`accordion`,label:q(`Address and phone`,i?`needed`:`optional`,[n.address?.streetAddress,n.address?.addressLocality,n.telephone,n.email]),default_open:i&&kt(e).some(e=>e.what!==`Opening hours`),blocks:[{type:`context`,text:i?`Google needs an address before it treats you as a local business. Use the same details as your Google Business Profile, which is what puts you on the map.`:`Leave the address empty if you have no public one.`},{type:`form`,block_id:`contact`,fields:[{type:`text_input`,action_id:`street`,label:`Street address`,initial_value:n.address?.streetAddress??``},{type:`text_input`,action_id:`town`,label:`Town or city`,initial_value:n.address?.addressLocality??``},{type:`text_input`,action_id:`region`,label:`State or region`,initial_value:n.address?.addressRegion??``},{type:`text_input`,action_id:`postcode`,label:`Postcode`,initial_value:n.address?.postalCode??``},{type:`text_input`,action_id:`country`,label:`Country code (GB, US, IN, AU)`,initial_value:n.address?.addressCountry??``},{type:`text_input`,action_id:`telephone`,label:`Phone`,initial_value:n.telephone??``},{type:`text_input`,action_id:`email`,label:`Email`,initial_value:n.email??``},{type:`select`,action_id:`price_range`,label:`Price range`,options:wt.map(e=>({label:e===``?`Not shown`:e,value:e})),initial_value:n.priceRange??``},{type:`text_input`,action_id:`areas`,label:`Areas you serve, one per line (if you travel to customers)`,multiline:!0,initial_value:n.areaServed.join(`
3
+ `)}],submit:{label:`Save address and phone`,action_id:`save_contact`}}]},u=i?{type:`accordion`,label:q(`Opening hours`,`needed`,Ot(n)),blocks:[{type:`context`,text:`Type the hours for each day, like 9:00-17:00. For a break in the day use two ranges: 12:00-14:30, 18:00-22:00. A day left empty is shown as closed.`},{type:`form`,block_id:`hours`,fields:S.map(e=>({type:`text_input`,action_id:`hours_${e.toLowerCase()}`,label:e,placeholder:`Closed`,initial_value:E(e,n.openingHours)})),submit:{label:`Save opening hours`,action_id:`save_hours`}}]}:{type:`accordion`,label:`Opening hours (only for a local business)`,blocks:[{type:`context`,text:`Opening hours are for a place customers visit. Choose "A local business customers visit" above and save, and this section opens up.`}]},d={type:`accordion`,label:q(`Logo`,r===`organization`?`needed`:`worth`,[n.logo?`added`:void 0]),blocks:[{type:`context`,text:`Google can show your logo beside your name. In Media, open your logo and use Copy URL, then paste it here. Use a square image at least 112 pixels wide.`},{type:`form`,block_id:`logo`,fields:[{type:`text_input`,action_id:`logo_url`,label:`Logo link`,placeholder:`https://example.com/logo.png`,initial_value:n.logo??``}],submit:{label:`Save logo`,action_id:`save_logo`}}]},f={type:`accordion`,label:q(`Your profiles elsewhere`,i?`worth`:`needed`,n.sameAs.map(e=>a(e)?.host.replace(/^www\./,``))),blocks:[{type:`context`,text:`Links to your pages on other sites help Google connect them to you. Paste the full address of each profile you have.`},{type:`form`,block_id:`profiles`,fields:[...Tt.map(e=>({type:`text_input`,action_id:`profile_${e.id}`,label:e.label,placeholder:`https://${e.hosts[0]}/yourname`,initial_value:s.named[e.id]??``})),{type:`text_input`,action_id:`profiles`,label:`Other profiles, one per line`,multiline:!0,initial_value:s.other.join(`
4
+ `)}],submit:{label:`Save profiles`,action_id:`save_profiles`}}]},p={type:`accordion`,label:q(`More about you`,`optional`,[n.alternateName,n.legalName,n.foundingDate?`founded ${n.foundingDate}`:void 0]),blocks:[{type:`context`,text:`Nothing here is needed. Skip anything that does not apply.`},{type:`form`,block_id:`company`,fields:[{type:`text_input`,action_id:`alternate_name`,label:`Also known as (a short name or abbreviation)`,initial_value:n.alternateName??``},{type:`text_input`,action_id:`legal_name`,label:`Registered legal name`,initial_value:n.legalName??``},{type:`text_input`,action_id:`founded`,label:`Founded (year, or YYYY-MM-DD)`,placeholder:`2012`,initial_value:n.foundingDate??``}],submit:{label:`Save`,action_id:`save_company`}}]},m=i?[l,u,d,f,p]:r===`organization`?[d,f,l,p,u]:[f,d,l,p,u];return c.push(...m),c}function Jt(e,t){return e.config.collections[t]?.type??d(t)}function Yt(e,t){let{config:n}=e,r=e.collections.find(e=>e.slug===t),i=[{type:`context`,text:`Google is told what each kind of content is, so it can show it properly: a blog post with its author and date, a service as a service. These were worked out from the names and are usually right. Every kind of content that has its own pages is listed here; content that only appears inside other pages, such as testimonials, is not. To change a single page (an About or Contact page, say), open it and use Change page type in its Google preview panel. Picking from a menu saves straight away.`}];return r&&i.push({type:`banner`,variant:`alert`,title:`Hide every page in ${r.label} from Google?`,description:`People will no longer find these pages through search engines. You can switch this back at any time.`},{type:`actions`,elements:[{type:`button`,action_id:`confirm_hide`,label:`Yes, hide them`,style:`danger`,value:r.slug},{type:`button`,action_id:`cancel_hide`,label:`Cancel`}]}),i.push({type:`table`,page_action_id:`types_table`,empty_text:`This site has no content types with pages yet.`,columns:[{key:`name`,label:`Content type`},{key:`shown`,label:``,format:`element`},{key:`visible`,label:``,format:`element`}],rows:e.collections.map(t=>{let r=n.collections[t.slug]?.noindex===!0;return{name:t.label,shown:{type:`menu`,action_id:`set_type`,label:`Google treats these as: ${O(Jt(e,t.slug))}`,items:D.map(({value:e,label:n})=>({label:n,value:`${t.slug}|${e}`}))},visible:{type:`menu`,action_id:`set_visible`,label:r?`Hidden from Google`:`Can appear on Google`,items:[{label:`Can appear on Google`,value:`${t.slug}|show`},{label:`Hide from Google and other search engines`,value:`${t.slug}|hide`}]}}})},{type:`form`,block_id:`breadcrumbs`,fields:[{type:`toggle`,action_id:`breadcrumbs`,label:`Show the path to each page on Google (Home > Services > Cakes)`,description:`Leave on unless your theme already does this.`,initial_value:n.breadcrumbs}],submit:{label:`Save`,action_id:`save_advanced`}}),[{type:`accordion`,label:`Content types (usually right as they are): ${e.collections.map(t=>{let r=n.collections[t.slug]?.noindex===!0;return`${t.label} as ${O(Jt(e,t.slug))}${r?`, hidden`:``}`}).join(`; `)}`,default_open:r!==void 0,blocks:i}]}function X(e,t,n,r){let i=[{type:`header`,text:`SEO`},{type:`context`,text:`How your site appears on Google and other search engines.`}];return n?{blocks:[...i,{type:`tab`,default_tab:r.tab,panels:[{label:`Overview`,blocks:Gt(e,t.site.name)},{label:`Redirects`,blocks:De({state:e.redirects,rows:e.redirectRows,more:e.moreRedirects,editing:r.editing,panel:r.panel,problem:r.problem,exported:r.exported,managerUrl:At(t.site.url,`/_emdash/admin/redirects`)})},{label:`Settings`,blocks:[...qt(e,t.site.name),...Yt(e,r.pendingHide)]}]}],...r.toast?{toast:r.toast}:{}}:{blocks:[...i,...Lt(e),...Vt(e,!1),...Rt(e),{type:`context`,text:`Business details, opening hours and redirects are set by your site admin. Ask them if something there is wrong.`}]}}function Xt(e,t){if(e===``)return{};let n=a(e,`${t.replace(/\/+$/,``)}/`);return!n||n.protocol!==`https:`&&n.protocol!==`http:`?{error:`Couldn't save. The logo link must be a web address starting with https://`}:n.pathname.includes(`/_emdash/api/media/asset/`)?{error:`That link only works when signed in. In Media, use Copy URL on the image instead.`}:{logo:n.href}}function Zt(e,t){let n={tab:G.identity},{site:r}=e.config,i=Y(t,`kind`,e.config.steps.identity?J(r):``);if(i!==`local`&&i!==`organization`&&i!==`person`)return{error:`Choose who this site is for.`,state:n};let a=Y(t,`business`,J(r)===`local`?r.type:``),o=K.find(e=>e.value===a)?.value;if(i===`local`&&!o)return{error:`Choose the kind of business.`,state:n};let s=i===`person`?`Person`:i===`local`?o??`LocalBusiness`:`Organization`,c=Y(t,`name`,r.name??``);return{config:{...e.config,site:{...r,type:s,name:c===``?void 0:c,description:Y(t,`description`,r.description??``)||void 0,openingHours:i===`local`?r.openingHours:[]},steps:{...e.config.steps,identity:!0}},state:n}}function Qt(e,t,n){let r={tab:G.identity},i=Xt(Y(t,`logo_url`,e.config.site.logo??``),n);return`error`in i?{error:i.error,state:r}:{config:{...e.config,site:{...e.config.site,logo:i.logo}},state:r}}function $t(e,t){let{site:n}=e.config,r={streetAddress:Y(t,`street`)||void 0,addressLocality:Y(t,`town`)||void 0,addressRegion:Y(t,`region`)||void 0,postalCode:Y(t,`postcode`)||void 0,addressCountry:Y(t,`country`).toUpperCase()||void 0},i=Y(t,`price_range`);return{config:{...e.config,site:{...n,email:Y(t,`email`)||void 0,telephone:Y(t,`telephone`)||void 0,address:Object.values(r).some(e=>e!==void 0)?r:void 0,priceRange:wt.includes(i)&&i!==``?i:void 0,areaServed:Nt(Y(t,`areas`,n.areaServed.join(`
5
+ `)))}},state:{tab:G.identity}}}function en(e,t){let n={tab:G.identity},r=[];for(let i of S){let a=T(i,Y(t,`hours_${i.toLowerCase()}`,E(i,e.config.site.openingHours)));if(!a)return{error:`Couldn't read the hours for ${i}. Write them like 9:00-17:00, with at most two ranges.`,state:n};r.push(...a)}return{config:{...e.config,site:{...e.config.site,openingHours:r}},state:n}}function tn(e,t){let n={tab:G.identity},r=Et(e.config.site.sameAs),i=[...Tt.map(e=>Y(t,`profile_${e.id}`,r.named[e.id]??``)),...Nt(Y(t,`profiles`,r.other.join(`
6
+ `)))].filter(e=>e!==``),o=[];for(let e of i){let t=a(/^https?:\/\//i.test(e)?e:`https://${e}`);if(!t||!t.host.includes(`.`))return{error:`"${e}" is not a web address. Paste the full link to the profile.`,state:n};o.push(t.href)}return{config:{...e.config,site:{...e.config.site,sameAs:o}},state:n}}function nn(e,t){let n={tab:G.identity},{site:r}=e.config,i=Y(t,`founded`,r.foundingDate??``);return i!==``&&!/^\d{4}(-\d{2}-\d{2})?$/.test(i)?{error:`Write the founding date as a year, like 2012, or as 2012-05-01.`,state:n}:{config:{...e.config,site:{...r,alternateName:Y(t,`alternate_name`,r.alternateName??``)||void 0,legalName:Y(t,`legal_name`,r.legalName??``)||void 0,foundingDate:i||void 0}},state:n}}function rn(e,t){let{robots:n}=e.config,r=Y(t,`snippet`,n.nosnippet?`none`:`full`),i=Y(t,`image_preview`,n.maxImagePreview);return{config:{...e.config,breadcrumbs:Mt(t,`breadcrumbs`,e.config.breadcrumbs),robots:{...n,nosnippet:r===`none`,maxSnippet:r===`short`?160:-1,maxImagePreview:i===`none`||i===`standard`||i===`large`?i:n.maxImagePreview}},state:{tab:G.types}}}function an(e,t,n){let r={tab:G.types},[i,a]=typeof t==`string`?t.split(`|`):[];if(!i||!e.collections.some(e=>e.slug===i))return{error:`That content type no longer exists.`,state:r};let o=e.config.collections[i]??{},s=n===`type`?D.find(e=>e.value===a)?.value:o.type??Jt(e,i);if(!s)return{error:`Choose one of the listed types.`,state:r};let c=n===`visible`?a===`hide`:o.noindex===!0;return{config:{...e.config,collections:{...e.config.collections,[i]:{type:s,noindex:c}},steps:{...e.config.steps,types:!0}},state:r}}async function on(e,t){if(t.scan?.status===`done`)return Ft(e,t);let n=t.scan?await yt(e,t.scan,t.config):await mt(e,t.collections.map(e=>e.slug),t.config);return{...t,scan:n,stats:n.status===`done`?n.tally:null}}async function sn(e,t,n){let r=await Pt(n),a=(t??0)>=50,s=jt(e)?e:{},c=typeof s.action_id==`string`?s.action_id:``;if(s.type===`page_load`&&s.page===`widget:seo`)return Kt(await on(n,r));if(!a||s.type===`page_load`||c===``)return X(await on(n,r),n,a,{tab:G.overview});let l=async(e,t=`Saved. Google will pick this up next time it visits.`)=>{if(`error`in e)return X(r,n,a,{...e.state,toast:{type:`error`,message:e.error}});let s=x(e.config);return await i(n,o,s),Ct(n.plugin.id),X({...r,config:s},n,a,{...e.state,toast:{type:`success`,message:t}})},u=async e=>{try{let{rows:t,more:r}=await ye(n);return{...e,redirectRows:t,moreRedirects:r}}catch{return e}},d=async(e,t,i)=>e?X(r,n,a,{tab:G.redirects,editing:i,...i?{}:{panel:`add`},problem:e}):X(await u(r),n,a,{tab:G.redirects,toast:{type:`success`,message:t}});if(s.type===`block_action`){if(c===`check_pages`||c===`check_more`){let e=await on(n,c===`check_pages`?{...r,scan:null}:r);return X(e,n,a,{tab:G.overview,toast:e.scan?.status===`done`?{type:`success`,message:`All pages checked.`}:{type:`info`,message:`${e.scan?.checked??0} pages checked so far. The rest follow in the background.`}})}if(c===`set_type`)return l(an(r,s.value,`type`));if(c===`set_visible`){let[e,t]=typeof s.value==`string`?s.value.split(`|`):[];return t===`hide`?X(r,n,a,{tab:G.types,pendingHide:e}):l(an(r,s.value,`visible`),`These pages can appear on Google again.`)}if(c===`confirm_hide`&&typeof s.value==`string`)return l(an(r,`${s.value}|hide`,`visible`),`These pages are now hidden from Google and other search engines.`);if(c===`cancel_hide`)return X(r,n,a,{tab:G.types});if(c===`hidden_ok`){let e={...r.config.collections};for(let t of Bt(r))e[t.slug]={...e[t.slug],hiddenOk:!0};return l({config:{...r.config,collections:e},state:{tab:G.overview}},`Noted. These pages stay hidden from search.`)}if(c===`edit_redirect`){let e=r.redirectRows.find(e=>e.id===s.value);return X(r,n,a,{tab:G.redirects,editing:e})}if(c===`open_add`)return X(r,n,a,{tab:G.redirects,panel:`add`});if(c===`open_import`)return X(r,n,a,{tab:G.redirects,panel:`import`});if(c===`close_panel`)return X(r,n,a,{tab:G.redirects});if(c===`remove_redirect`&&typeof s.value==`string`)return d(await we(n,s.value),`Redirect removed.`);if(c===`add_redirects`||c===`more_redirects`){if(!r.redirects||r.redirects.status===`done`)return X(r,n,a,{tab:G.redirects});let e=await pe(n,r.redirects);return X(await u({...r,redirects:e}),n,a,{tab:G.redirects,toast:e.status===`done`?{type:`success`,message:`${F(e.added,`redirect`)} added.`}:{type:`info`,message:`${e.added} added so far. The rest follow in the background.`}})}if(c===`stop_redirects`&&r.redirects?.status===`adding`){let e=await Oe(n,r.redirects);return X({...r,redirects:e},n,a,{tab:G.redirects,toast:{type:`info`,message:`Stopped. ${F(e.added,`redirect`)} added.`}})}if(c===`reset_redirects`)return r.redirects?.status!==`adding`&&await n.kv.delete(N),X({...r,redirects:r.redirects?.status===`adding`?r.redirects:null},n,a,{tab:G.redirects});if(c===`remove_redirects`&&r.redirects){let e=await me(n,r.redirects);return X(await u({...r,redirects:e===0?null:r.redirects}),n,a,{tab:G.redirects,toast:e===0?{type:`success`,message:`Removed. Your other redirects are untouched.`}:{type:`info`,message:`${e} still to remove. Press Remove again.`}})}if(c===`export_redirects`){let{text:e,count:t}=await he(n);return X(r,n,a,{tab:G.redirects,panel:`export`,exported:e,toast:{type:`info`,message:`${F(t,`redirect`)} listed below.`}})}return X(r,n,a,{tab:G.overview})}if(s.type!==`form_submit`)return X(r,n,a,{tab:G.overview});let f=jt(s.values)?s.values:{};if(c===`check_redirects`){let e=Y(f,`list`);if(e===``)return X(r,n,a,{tab:G.redirects,toast:{type:`error`,message:`Paste a list first.`}});let t=await de(n,e);return X({...r,redirects:t},n,a,{tab:G.redirects,toast:{type:`success`,message:`Checked. Nothing has been added yet.`}})}if(c===`add_redirect`){let e=Y(f,`source`),t=Y(f,`code`,`301`)===`410`?``:Y(f,`destination`);return d(await Se(n,e,t,Y(f,`code`,`301`)),t===``?`Done. ${e} now tells visitors the page was removed.`:`Redirect added. ${e} now goes to ${t}.`)}if(c.startsWith(`save_redirect:`)){let e=c.slice(14),t=r.redirectRows.find(t=>t.id===e);return d(await Ce(n,e,Y(f,`source`,t?.source??``),Y(f,`destination`,t?.destination??``),Y(f,`code`,String(t?.type??301))),`Redirect changed.`,t)}if(c===`setup_identity`){let e=Zt(r,f);if(`error`in e)return l(e);let t=Y(f,`street`),n=Y(f,`town`),{site:i}=e.config,a=t!==``||n!==``?{...i.address,...t?{streetAddress:t}:{},...n?{addressLocality:n}:{}}:i.address;return l({config:{...e.config,site:{...i,address:a}},state:{tab:G.overview}})}return c===`save_identity`?l(Zt(r,f)):c===`save_logo`?l(Qt(r,f,n.site.url)):c===`save_contact`?l($t(r,f)):c===`save_hours`?l(en(r,f)):c===`save_profiles`?l(tn(r,f)):c===`save_company`?l(nn(r,f)):c===`save_advanced`?l(rn(r,f)):X(r,n,a,{tab:G.overview})}function Z(e){return{"@id":e}}function Q(e){let t={};for(let[n,r]of Object.entries(e))r==null||r===``||Array.isArray(r)&&r.length===0||(t[n]=r);return t}function cn(e,t){return a(e,t)?.href??e}function ln(e,t){return(e.siteUrl||t||(a(e.url)?.origin??``)).replace(/\/+$/,``)}function un(e,t){if(e.canonical)return cn(e.canonical,`${t}/`);let n=a(e.url,`${t}/`);return n?(n.search=``,n.hash=``,n.href):e.url}function dn(e){return e.path===`/`||e.path===``}function fn(e){return l.includes(e)}function pn(e,t,n){let r=e.content?t.collections[e.content.collection]:void 0;if(n?.type)return n.type;if(r?.type)return r.type;let i=e.content?d(e.content.collection):`WebPage`;return i===`WebPage`?e.pageType===`article`?`BlogPosting`:`WebPage`:i}function mn(e,t,n,r){let i=`${n}/#logo`,a=e.type===`Person`,o=!a&&e.type!==`Organization`&&e.address===void 0?`Organization`:e.type,s=!a&&(e.address!==void 0||e.geo!==void 0||e.openingHours.length>0);return Q({"@type":o,"@id":r,name:t,alternateName:e.alternateName,legalName:a?void 0:e.legalName,description:e.description,url:`${n}/`,logo:e.logo&&!a?{"@type":`ImageObject`,"@id":i,url:e.logo,contentUrl:e.logo,caption:t}:void 0,image:e.logo?a?e.logo:Z(i):void 0,sameAs:e.sameAs,email:e.email,telephone:e.telephone,address:e.address?{"@type":`PostalAddress`,...e.address}:void 0,geo:e.geo&&!a?{"@type":`GeoCoordinates`,...e.geo}:void 0,openingHoursSpecification:s?e.openingHours.map(e=>({"@type":`OpeningHoursSpecification`,dayOfWeek:e.days,opens:e.opens,closes:e.closes})):void 0,priceRange:a?void 0:e.priceRange,areaServed:a?void 0:e.areaServed,foundingDate:a?void 0:e.foundingDate,vatID:a?void 0:e.vatID,taxID:a?void 0:e.taxID,numberOfEmployees:!a&&e.numberOfEmployees?{"@type":`QuantitativeValue`,value:e.numberOfEmployees}:void 0})}function hn(e){let t=e;try{t=decodeURIComponent(e)}catch{}let n=t.replace(/[-_]+/g,` `).trim();return n.charAt(0).toUpperCase()+n.slice(1)}function gn(e,t,n){let{page:r,config:i,site:a}=e;if(r.breadcrumbs)return r.breadcrumbs.map(e=>({name:e.name,url:cn(e.url,`${t}/`)}));if(!i.breadcrumbs||dn(r))return[];let o=r.path.split(`/`).filter(e=>e!==``);if(o.length===0)return[];let s=a.trailingSlash===`always`?`/`:``,c=[{name:`Home`,url:`${t}/`}],l=``;return o.forEach((e,r)=>{l+=`/${e}`;let i=r===o.length-1;c.push({name:i?n:hn(e),url:`${t}${l}${s}`})}),c}function _n(e,t){return e.length<=t?e:`${e.slice(0,t-1).trimEnd()}…`}function vn(e,t,n){let r;for(let{"@context":i,...a}of t){let t=typeof a[`@id`]==`string`?a[`@id`]:void 0;if(t!==void 0){if(n.has(t))continue;n.add(t),r??=t}e.push(a)}return r}function yn(e){let{page:t,config:n,record:r,site:i}=e,a=ln(t,i.url),o=un(t,a),s=t.locale??i.locale,c=n.site.name??t.siteName??i.name,l=t.pageTitle??t.title??c,u=n.site.type===`Person`,d=`${a}/#${u?`person`:`organization`}`,f=`${a}/#website`,p=o,m=`${o}#breadcrumb`,h=pn(t,n,r),g=fn(h),_=h===`Service`,v=h===`ProfilePage`,y=`${o}#service`,b=`${o}#person`,x=r?.publishedAt??t.articleMeta?.publishedTime??void 0,S=r?.updatedAt??t.articleMeta?.modifiedTime??void 0,C=t.image?cn(t.image,`${a}/`):void 0,w=C??``,T=gn(e,a,l),E=[mn(n.site,c,a,d),Q({"@type":`WebSite`,"@id":f,url:`${a}/`,name:c,alternateName:n.site.alternateName,description:n.site.description,publisher:Z(d),inLanguage:s})];if(e.noindex)return E;let D=Q({"@type":g||_?`WebPage`:h,"@id":p,url:o,name:l,description:t.description,isPartOf:Z(f),about:dn(t)?Z(d):void 0,primaryImageOfPage:C?Z(w):void 0,image:C?Z(w):void 0,breadcrumb:T.length>0?Z(m):void 0,mainEntity:_?Z(y):v?Z(b):void 0,datePublished:x,dateModified:S,inLanguage:s});if(E.push(D),g){let e=(r?.authors??[]).map(e=>Q({"@type":`Person`,name:e.name,url:e.url})),n=t.articleMeta?.author?[{"@type":`Person`,name:t.articleMeta.author}]:[Z(d)];E.push(Q({"@type":h,"@id":`${o}#article`,isPartOf:Z(p),mainEntityOfPage:Z(p),headline:_n(l,110),description:t.description,image:C?Z(w):void 0,datePublished:x,dateModified:S,author:e.length>0?e:n,publisher:Z(d),inLanguage:s}))}_&&E.push(Q({"@type":`Service`,"@id":y,name:l,description:t.description,url:o,image:C?Z(w):void 0,provider:Z(d),areaServed:n.site.areaServed})),v&&E.push(Q({"@type":`Person`,"@id":b,name:l,description:t.description,url:o,image:C?Z(w):void 0,worksFor:u?void 0:Z(d)})),C&&E.push({"@type":`ImageObject`,"@id":w,url:C,contentUrl:C,...Ye(r?.images,C,a)}),T.length>0&&E.push({"@type":`BreadcrumbList`,"@id":m,itemListElement:T.map((e,t)=>Q({"@type":`ListItem`,position:t+1,name:e.name,item:t===T.length-1?void 0:e.url}))});let O=new Set([`${a}/#logo`]);for(let e of E)typeof e[`@id`]==`string`&&O.add(e[`@id`]);let k=vn(E,r?.custom??[],O);return k!==void 0&&!g&&D.mainEntity===void 0&&(D.mainEntity=Z(k)),E}const bn=`default`;function xn(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Sn(e){let t=a(e);if(!t)return e;let n=t.pathname.split(`/`).filter(e=>e!==``);return[t.host,...n].join(` › `)}function Cn(e,t){return e.length<=t?e:`${e.slice(0,t-1).trimEnd()}…`}async function wn(e,t,n,r){if(!t)return{blocks:[]};let i=(n??0)>=50,o=xn(e)?e:{},c=await s(r),l=i&&o.type===`block_action`&&o.action_id===`set_type`,u=typeof o.value==`string`?o.value:bn,f=D.find(e=>e.value===u)?.value,[p,m]=await Promise.all([ct(r,t.collection,t.id,c,l?e=>{let{type:t,...n}=e;return f?{...n,type:f}:n}:void 0),r.content?.getPublicUrl?.(t.collection,t.id)]),h=p?.record,g=p?.entry,_=h&&l?{type:`success`,message:`Saved. Google will pick this up next time it visits.`}:void 0;if(!h||!g)return{blocks:[{type:`context`,text:`Save this page to see how it may look on Google.`}]};if(h.status===`skip`)return{blocks:[{type:`context`,text:`This kind of content has no page of its own, so Google only sees it inside other pages. There is nothing to set here.`}]};let v=c.site.name??r.site.name,y=r.site.url.replace(/\/+$/,``),b=[`home`,`index`,``].includes(g.slug??``)?`${y}/`:`${y}/${g.slug}`,x=[`home`,`index`].includes(g.slug??``)?`${y}/`:m??b,S=h.title||`(no title)`,C=g.seo?.description?.trim()??``,w=C===``&&Le(g.data)!==``,T=C||Le(g.data),E=c.collections[t.collection]?.type??d(t.collection),k=h.type??E,A=h.status===`hidden`,j=h.issues??[],M=[{type:`context`,text:v?`${v} · ${Sn(x)}`:Sn(x)},{type:`header`,text:Me(S)},{type:`section`,text:T===``?`No description yet. Google will pick some text from the page.`:Cn(T,160)},...w?[{type:`context`,text:`This description is the page's excerpt. To write a different one for search, fill in Meta Description in the SEO panel.`}]:[],{type:`context`,text:`What Google sees: the published page, with the SEO title and description as last saved. Google may rewrite them, and your site may add its name to the title.`},{type:`fields`,fields:[{label:`Shown to Google as`,value:O(k)},{label:`In search results`,value:h.status===`draft`?`Not published yet`:A?`Hidden from search`:`Yes`}]}];if(j.length===0)M.push({type:`context`,text:`Nothing to fix on this page.`});else{let e=[...j].sort((e,t)=>Number(t.level===`fix`)-Number(e.level===`fix`));for(let t of e.slice(0,3))M.push({type:`section`,text:`${t.level===`fix`?`To fix`:`Worth a look`}: ${t.message}`},{type:`context`,text:t.fix});e.length>3&&M.push({type:`context`,text:`And ${e.length-3} more.`})}if(i){let e=yn({page:{url:x,path:a(x)?.pathname??`/`,locale:g.locale,kind:`content`,pageType:`website`,title:S,pageTitle:S,description:T===``?null:T,canonical:g.seo?.canonical??null,image:null,content:{collection:t.collection,id:t.id,slug:g.slug}},config:c,record:h,noindex:A,site:r.site});M.push({type:`divider`},{type:`actions`,elements:[{type:`menu`,action_id:`set_type`,label:`Change page type`,items:[{label:`Same as other pages here (${O(E)})`,value:bn},...D.map(({value:e,label:t})=>({value:e,label:t}))]},.../^https?:\/\//.test(x)?[{type:`link`,label:`Test on Google`,target:{kind:`external`,url:`https://search.google.com/test/rich-results?url=${encodeURIComponent(x)}`}}]:[]]},{type:`accordion`,label:`View the markup`,blocks:[{type:`context`,text:`The schema markup (JSON-LD) this page sends to search engines.`},{type:`code`,language:`jsonc`,code:JSON.stringify({"@context":`https://schema.org`,"@graph":e},null,2)}]})}return{blocks:M,..._?{toast:_}:{}}}const Tn=/\s*,\s*/;function En(e,t,n){let r=(e??``).toLowerCase().split(Tn).map(e=>e.trim()).filter(e=>e!==``),i=t||r.includes(`noindex`)||r.includes(`none`),a=r.includes(`nofollow`)||r.includes(`none`),o=[i?`noindex`:`index`,a?`nofollow`:`follow`],s=new Set([`index`,`noindex`,`follow`,`nofollow`,`none`,`all`]),c=r.filter(e=>!s.has(e));if(!i){let e=e=>c.some(t=>t.startsWith(e));n.nosnippet||c.includes(`nosnippet`)?c.includes(`nosnippet`)||c.push(`nosnippet`):e(`max-snippet:`)||c.push(`max-snippet:${n.maxSnippet}`),e(`max-image-preview:`)||c.push(`max-image-preview:${n.maxImagePreview}`),e(`max-video-preview:`)||c.push(`max-video-preview:${n.maxVideoPreview}`)}return[...o,...new Set(c)].join(`, `)}function Dn(e){return e.startsWith(`noindex`)}function On(e){return/[?&]_preview=/.test(e)}async function $(e,t,n){let r=n?.id;if(typeof r==`string`)try{await at(e,t,r,await s(e))}catch(n){e.log.warn(`could not refresh entry record`,{collection:t,id:r,error:String(n)})}}const kn={hooks:{"page:metadata":async(e,t)=>{let{page:n}=e,r=n.content,[i,a]=await Promise.all([St(t,()=>s(t),{fresh:On(n.url)}),(async()=>{if(!r)return null;try{return{stored:await R(t).get(L(r.collection,r.id))}}catch(e){return{error:e}}})()]),o=null;if(r&&a){let{collection:e,id:i}=r;try{if(`error`in a)throw a.error;let{stored:r}=a,c=R(t);o=r??await at(t,e,i,await s(t));let l=!!(n.seo?.ogImage||n.image);if(r&&tt(r,l)){let t=await c.get(L(e,i)),n=t?tt(t,l):null;n&&await c.put(L(e,i),n),o=n??t??r}}catch(n){t.log.warn(`could not load entry record`,{collection:e,id:i,error:String(n)})}}let c=n.content?i.collections[n.content.collection]:void 0,l=En(n.seo?.robots,c?.noindex===!0,i.robots);return[{kind:`meta`,name:`robots`,content:l},{kind:`jsonld`,id:`primary`,graph:{"@context":`https://schema.org`,"@graph":yn({page:n,config:i,record:o,noindex:Dn(l),site:t.site})}}]},"content:afterSave":async(e,t)=>{await $(t,e.collection,e.content)},"content:afterPublish":async(e,t)=>{await $(t,e.collection,e.content)},"content:afterUnpublish":async(e,t)=>{await $(t,e.collection,e.content)},"content:afterRestore":async(e,t)=>{await $(t,e.collection,e.content)},"plugin:activate":async(e,t)=>{try{if(await pt(t))return;let e=await mt(t,(await t.schema?.listCollections()??[]).filter(e=>e.routable&&!e.hidden).map(e=>e.slug),await s(t));e.status===`done`&&e.checked===0&&await t.kv.delete(H)}catch(e){t.log.warn(`could not start the first page check`,{error:String(e)})}},cron:async(e,t)=>{if(e.name===U){let e=await pt(t);e?.status===`running`||e?.sweep?await yt(t,e,await s(t)):await t.cron?.cancel(U);return}if(e.name!==P)return;let n=await le(t);n?.status===`adding`?await pe(t,n):await t.cron?.cancel(P)},"content:afterDelete":async(e,t)=>{await ut(t,e.collection,e.id)}},routes:{admin:{permission:`plugins:read`,handler:async(e,t)=>sn(e.input,e.user?.role,t)},"editor/preview":{permission:`content:read`,handler:async(e,t)=>wn(e.input,e.ui?.entry,e.user?.role,t)},hello:{handler:async(e,t)=>(t.log.info(`hello route called`,{pluginId:t.plugin.id}),{greeting:`hello`,pluginId:t.plugin.id})}}};export{kn as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moorage/plugin-seo",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "description": "SEO for EmDash: schema markup, JSON-LD structured data, Google preview, SEO checks, noindex, WordPress redirects import. Yoast alternative.",
5
5
  "keywords": [
6
6
  "emdash",