@weatherboard/cms 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -1
- package/dist/portable/sections.d.cts +5 -1
- package/dist/portable/sections.d.mts +5 -1
- package/dist/portable/sections.d.ts +5 -1
- package/dist/site-content.cjs +3 -3
- package/dist/site-content.cjs.map +3 -3
- package/dist/site-content.mjs +3 -3
- package/dist/site-content.mjs.map +3 -3
- package/package.json +1 -1
package/dist/site-content.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
function S(n){if(!Array.isArray(n))return!1;for(let e=0;e<n.length;e+=1)if(!Object.hasOwn(n,e))return!1;return!0}var On=/^[A-Za-z][A-Za-z0-9_]{0,63}$/,xn=/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;function Ln(n){if(!n||!Array.isArray(n.types)||n.types.length===0)throw new TypeError("CMS dependencies require document types");let e=[...n.types];for(let o of e)if(typeof o!="string"||!On.test(o))throw new TypeError("Invalid CMS document type");if(n.ids!==void 0&&!Array.isArray(n.ids))throw new TypeError("Invalid CMS document IDs");let t=n.ids===void 0?void 0:[...n.ids];for(let o of t??[])if(typeof o!="string"||!xn.test(o)||/^(drafts|versions)\./.test(o))throw new TypeError("Invalid CMS document ID");if(new Set(e).size+new Set(t).size>128)throw new TypeError("Too many CMS tags");return Object.freeze({types:Object.freeze(e),...t===void 0?{}:{ids:Object.freeze(t)}})}function A(n){if(!n||typeof n.name!="string"||!/^[A-Za-z][A-Za-z0-9_.-]{0,127}$/.test(n.name)||typeof n.query!="string"||n.query.trim()===""||typeof n.resolve!="function")throw new TypeError("Invalid CMS query configuration");let e=n.params;if(!e||typeof e!="object"||Object.getPrototypeOf(e)!==Object.prototype&&Object.getPrototypeOf(e)!==null)throw new TypeError("CMS params must be plain JSON scalars");let t={};for(let o of Reflect.ownKeys(e)){let i=Object.getOwnPropertyDescriptor(e,o);if(typeof o!="string"||!i||!Object.hasOwn(i,"value")||!i.enumerable)throw new TypeError("CMS params must be plain JSON scalars");let r=i.value;if(!(r===null||typeof r=="string"||typeof r=="boolean"||typeof r=="number"&&Number.isFinite(r)))throw new TypeError("CMS params must be plain JSON scalars");Object.defineProperty(t,o,{value:r,enumerable:!0})}return Object.freeze({name:n.name,query:n.query,params:Object.freeze(t),dependencies:Ln(n.dependencies),resolve:n.resolve})}var E=["media-end","media-start","media-below"],j=["beside","stacked"],G=["staggered","aligned"],$={Split:"media-end",HeadingList:"beside",StaggerRow:"staggered"},Hn={featureStoriesBlock:"feature_stories",surfaceCardBlock:"cta",accentBandBlock:"accent_band",locationsBlock:"locations",textMediaBlock:"text_media",faqBlock:"faq",galleryBlock:"gallery",contactBlock:"contact"},F=2,z=4,
|
|
1
|
+
function S(n){if(!Array.isArray(n))return!1;for(let e=0;e<n.length;e+=1)if(!Object.hasOwn(n,e))return!1;return!0}var On=/^[A-Za-z][A-Za-z0-9_]{0,63}$/,xn=/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;function Ln(n){if(!n||!Array.isArray(n.types)||n.types.length===0)throw new TypeError("CMS dependencies require document types");let e=[...n.types];for(let o of e)if(typeof o!="string"||!On.test(o))throw new TypeError("Invalid CMS document type");if(n.ids!==void 0&&!Array.isArray(n.ids))throw new TypeError("Invalid CMS document IDs");let t=n.ids===void 0?void 0:[...n.ids];for(let o of t??[])if(typeof o!="string"||!xn.test(o)||/^(drafts|versions)\./.test(o))throw new TypeError("Invalid CMS document ID");if(new Set(e).size+new Set(t).size>128)throw new TypeError("Too many CMS tags");return Object.freeze({types:Object.freeze(e),...t===void 0?{}:{ids:Object.freeze(t)}})}function A(n){if(!n||typeof n.name!="string"||!/^[A-Za-z][A-Za-z0-9_.-]{0,127}$/.test(n.name)||typeof n.query!="string"||n.query.trim()===""||typeof n.resolve!="function")throw new TypeError("Invalid CMS query configuration");let e=n.params;if(!e||typeof e!="object"||Object.getPrototypeOf(e)!==Object.prototype&&Object.getPrototypeOf(e)!==null)throw new TypeError("CMS params must be plain JSON scalars");let t={};for(let o of Reflect.ownKeys(e)){let i=Object.getOwnPropertyDescriptor(e,o);if(typeof o!="string"||!i||!Object.hasOwn(i,"value")||!i.enumerable)throw new TypeError("CMS params must be plain JSON scalars");let r=i.value;if(!(r===null||typeof r=="string"||typeof r=="boolean"||typeof r=="number"&&Number.isFinite(r)))throw new TypeError("CMS params must be plain JSON scalars");Object.defineProperty(t,o,{value:r,enumerable:!0})}return Object.freeze({name:n.name,query:n.query,params:Object.freeze(t),dependencies:Ln(n.dependencies),resolve:n.resolve})}var E=["media-end","media-start","media-below"],j=["beside","stacked"],G=["staggered","aligned"],$={Split:"media-end",HeadingList:"beside",StaggerRow:"staggered"},Hn={featureStoriesBlock:"feature_stories",surfaceCardBlock:"cta",accentBandBlock:"accent_band",locationsBlock:"locations",textMediaBlock:"text_media",faqBlock:"faq",galleryBlock:"gallery",contactBlock:"contact"},F=2,z=4,b={layoutDefaulted:"section.layout.defaulted",unknownType:"section.type.unknown",imageMissingAlt:"section.image.missing-alt",imageMissingAsset:"section.image.missing-asset",emptySkipped:"section.empty.skipped"};var h=n=>n!==null&&typeof n=="object"&&!Array.isArray(n),_=n=>typeof n=="string"&&n.trim()!=="",O=n=>n===null||typeof n=="string",R=n=>n===null||typeof n=="string"&&J.test(n),un=n=>typeof n=="string"&&K.test(n),w=n=>_(n)||h(n)&&_(n.text)&&(n.copySource==="captured"||n.copySource==="proposed"),C=n=>n===null||w(n),pn=n=>h(n)&&w(n.label)&&un(n.href),x=n=>n===null||pn(n),Q=n=>n===null||typeof n=="string"&&M.test(n),q=(n,e)=>n.some(t=>t===e),v=n=>h(n)&&_(n.asset)&&_(n.alt)&&O(n.caption)&&(n.hotspot===null||h(n.hotspot)&&typeof n.hotspot.x=="number"&&typeof n.hotspot.y=="number");function dn(n){if(!h(n))return!1;switch(n.kind){case"campaign":return x(n.action)&&S(n.images)&&n.images.every(e=>typeof e=="string"&&R(e));case"locations":return(n.anchor===null||typeof n.anchor=="string"&&M.test(n.anchor))&&w(n.heading)&&C(n.tail)&&R(n.image);case"feature_stories":return w(n.heading)&&C(n.tail)&&S(n.items)&&n.items.length>0&&n.items.every(e=>h(e)&&w(e.heading)&&w(e.body)&&pn(e.action)&&R(e.image)&&Z.some(t=>t===e.shape)&&typeof e.card=="boolean");case"accent_band":return w(n.heading)&&w(n.body)&&x(n.action)&&R(n.image);case"cta":return _(n.heading)&&O(n.body)&&h(n.link)&&_(n.link.label)&&un(n.link.href);default:return!1}}function Nn(n){if(!h(n))return!1;switch(n.kind){case"campaign":return!1;case"text_media":return Q(n.anchor)&&q(E,n.layout)&&w(n.heading)&&C(n.tail)&&w(n.body)&&x(n.action)&&(n.image===null||v(n.image));case"faq":return Q(n.anchor)&&q(j,n.layout)&&w(n.heading)&&C(n.tail)&&C(n.intro)&&S(n.items)&&n.items.length>0&&n.items.every(e=>h(e)&&w(e.question)&&w(e.answer));case"gallery":return Q(n.anchor)&&q(G,n.layout)&&C(n.heading)&&S(n.images)&&n.images.length>0&&n.images.every(v);case"contact":return Q(n.anchor)&&q(E,n.layout)&&w(n.heading)&&C(n.body)&&typeof n.showEmail=="boolean"&&typeof n.showPhone=="boolean"&&x(n.action)&&(n.image===null||v(n.image));default:return dn(n)}}function Pn(n,e){if(n===void 0)return e===void 0;if(!S(n)||!n.every(Nn)||!S(e)||!e.every(r=>h(r)&&q(Object.values(b),r.code)&&_(r.where)))return!1;let t=n,o=t.flatMap(r=>"anchor"in r&&r.anchor!==null?[r.anchor]:[]);return new Set(o).size!==o.length?!1:t.flatMap(r=>{switch(r.kind){case"text_media":case"contact":case"accent_band":return[r.action?.href];case"feature_stories":return r.items.map(a=>a.action.href);case"cta":return[r.link.href];default:return[]}}).every(r=>r===void 0||!r.startsWith("#")||o.includes(r.slice(1)))}function yn(n){if(!h(n)||!O(n.intro)||!R(n.photo)||!S(n.blocks))return!1;let e=n.hero;if(e!==null&&(!h(e)||!w(e.heading)||!C(e.subline)||!C(e.intro)||!R(e.image)||!R(e.inset)||!x(e.cta)||!x(e.secondaryCta))||!n.blocks.every(dn))return!1;let t=n,o=t.blocks.flatMap(r=>r.kind==="locations"&&r.anchor!==null?[r.anchor]:[]);return new Set(o).size!==o.length?!1:[t.hero?.cta?.href,t.hero?.secondaryCta?.href,...t.blocks.flatMap(r=>{switch(r.kind){case"campaign":case"accent_band":return[r.action?.href];case"feature_stories":return r.items.map(a=>a.action.href);case"cta":return[r.link.href];default:return[]}})].every(r=>r===void 0||!r.startsWith("#")||o.includes(r.slice(1)))}function fn(n){return S(n)&&n.every(e=>h(e)&&_(e.where)&&typeof e.text=="string")}function gn(n){return n===null||h(n)&&yn(n.composition)&&typeof n.body=="string"&&fn(n.proposedCopy)&&typeof n.campaign=="string"&&["shown","off","not-started","ended","none"].includes(n.campaign)}function nn(n){return n===null||h(n)&&_(n.slug)&&_(n.title)&&yn(n.composition)&&typeof n.body=="string"&&typeof n.migrated=="boolean"&&fn(n.proposedCopy)&&Pn(n.sections,n.warnings)}function hn(n){return n===null||h(n)&&_(n.name)&&O(n.description)&&h(n.contact)&&O(n.contact.email)&&O(n.contact.phone)&&S(n.social)&&n.social.every(e=>h(e)&&_(e.network)&&typeof e.url=="string"&&/^https?:\/\//.test(e.url))}var tn="malformed-content",k=class extends Error{code=tn;documentId;problems;constructor(e,t){super(`${tn}: ${e}: ${t.join("; ")}`),this.name="MalformedContentError",this.documentId=e,this.problems=t}},J=/^[a-z0-9]+(?:-[a-z0-9]+)*$/,K=/^(?:\/(?![/\\])[^\s]*|#[a-z][a-z0-9]*(?:-[a-z0-9]+)*|mailto:[^\s@]+@[^\s@]+|tel:\+?[0-9][0-9 ()-]*|https?:\/\/[^\s/]+[^\s]*)$/,M=/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/,Z=["wide","tall","round","free"],L="homePage",H="siteSettings",N=class{problems=[];proposed=[];fail(e,t){return this.problems.push(`${e} ${t}`),null}object(e,t){return typeof e=="object"&&e!==null&&!Array.isArray(e)?e:this.fail(t,"is not an object")}dense(e,t){return S(e)?!0:(this.fail(t,"contains missing entries"),!1)}optionalString(e,t){return e==null?null:typeof e=="string"?e.trim()===""?null:e:this.fail(t,"is not text")}copy(e,t){if(e==null)return null;let o=this.object(e,t);if(o===null)return null;let i=o.text,r=o.copySource;return i!==void 0&&typeof i!="string"?this.fail(`${t}.text`,"is not text"):r!==void 0&&r!=="captured"&&r!=="proposed"?this.fail(`${t}.copySource`,`is ${JSON.stringify(r)}, not captured or proposed`):typeof i!="string"||i.trim()===""?null:r==="proposed"?(this.proposed.push({where:t,text:i}),{text:i,copySource:"proposed"}):r==="captured"?{text:i,copySource:"captured"}:i}requiredCopy(e,t){let o=this.copy(e,t);return o===null&&!this.problems.some(i=>i.startsWith(t))&&this.fail(t,"is missing its words"),o}photo(e,t){return e==null?null:typeof e=="string"&&J.test(e)?e:this.fail(t,`is ${JSON.stringify(e)}, not a photo library slug`)}photos(e,t,o){return e==null?[]:Array.isArray(e)?this.dense(e,t)?(e.length>o&&this.fail(t,`holds ${String(e.length)} photos; at most ${String(o)}`),e.map((i,r)=>this.photo(i,`${t}[${String(r)}]`)).filter(i=>i!==null)):[]:(this.fail(t,"is not a list of photos"),[])}action(e,t){if(e==null)return null;let o=this.object(e,t);if(o===null)return null;let i=this.requiredCopy(o.label,`${t}.label`),r=o.href;return typeof r!="string"||!K.test(r)?this.fail(`${t}.href`,`is ${JSON.stringify(r)}, not a site path, #jump-link, mailto:, tel: or web address`):i===null?null:{label:i,href:r}}requiredAction(e,t){return e==null?this.fail(t,"is missing"):this.action(e,t)}};function Y(n){return typeof n=="string"?n:n.text}function Dn(n){let e=new N,t=on(n,"body",e);if(e.problems.length>0)throw new k("body",e.problems);return t}function on(n,e,t){if(n==null)return"";if(!Array.isArray(n))return t.fail(e,"is not rich text"),"";if(!t.dense(n,e))return"";let o=[],i=!1;return n.forEach((r,a)=>{let s=`${e}[${String(a)}]`,u=t.object(r,s);if(u===null)return;if(u._type!=="block"){t.fail(s,`is a ${JSON.stringify(u._type)}; only text is supported in rich text so far`);return}let l=Gn(u,s,t),c=u.listItem,d=u.style??"normal",p;if(c==="bullet"||c==="number"){let f=typeof u.level=="number"&&u.level>1?u.level:1;p=`${" ".repeat(f-1)}${c==="bullet"?"-":"1."} ${l}`}else if(d==="h2")p=`## ${l}`;else if(d==="h3")p=`### ${l}`;else if(d==="blockquote")p=`> ${l}`;else if(d==="normal")p=l;else{t.fail(`${s}.style`,`is ${JSON.stringify(d)}, which the schema does not offer`);return}let y=c==="bullet"||c==="number";o.length>0&&o.push(y&&i?`
|
|
2
2
|
`:`
|
|
3
3
|
|
|
4
|
-
`),o.push(p),i=y}),o.join("")}var jn={strong:"**",em:"*",code:"`"};function Gn(n,e,t){let o=new Map,i=Array.isArray(n.markDefs)?n.markDefs:[];if(!t.dense(i,`${e}.markDefs`))return"";for(let a of i){let s=a;s._type==="link"&&typeof s._key=="string"&&typeof s.href=="string"&&o.set(s._key,s.href)}let r=Array.isArray(n.children)?n.children:[];return t.dense(r,`${e}.children`)?r.map((a,s)=>{let u=a;if(u._type!=="span"||typeof u.text!="string")return t.fail(`${e}.children[${String(s)}]`,"is not a text span"),"";let l=u.text,c=Array.isArray(u.marks)?u.marks:[];if(!t.dense(c,`${e}.children[${String(s)}].marks`))return"";let d=null;for(let p of c){if(typeof p!="string")continue;let y=jn[p];y!==void 0?l=`${y}${l}${y}`:o.has(p)?d=o.get(p)??null:t.fail(`${e}.children[${String(s)}].marks`,`names ${JSON.stringify(p)}, which is neither a style nor a link`)}return d===null?l:`[${l}](${d})`}).join(""):""}function mn(n,e){if(typeof n!="object"||n===null)return"none";let t=n;if(t.enabled!==!0)return"off";let o=typeof t.startsAt=="string"?Date.parse(t.startsAt):null,i=typeof t.endsAt=="string"?Date.parse(t.endsAt):null;return o!==null&&e.getTime()<o?"not-started":i!==null&&e.getTime()>=i?"ended":"shown"}function P(n,e,t){return typeof e._key=="string"?`${n}[_key=="${e._key}"]`:`${n}[${String(t)}]`}function rn(n,e){let t=new N,o=t.object(n,"homePage");if(o===null)throw new
|
|
4
|
+
`),o.push(p),i=y}),o.join("")}var jn={strong:"**",em:"*",code:"`"};function Gn(n,e,t){let o=new Map,i=Array.isArray(n.markDefs)?n.markDefs:[];if(!t.dense(i,`${e}.markDefs`))return"";for(let a of i){let s=a;s._type==="link"&&typeof s._key=="string"&&typeof s.href=="string"&&o.set(s._key,s.href)}let r=Array.isArray(n.children)?n.children:[];return t.dense(r,`${e}.children`)?r.map((a,s)=>{let u=a;if(u._type!=="span"||typeof u.text!="string")return t.fail(`${e}.children[${String(s)}]`,"is not a text span"),"";let l=u.text,c=Array.isArray(u.marks)?u.marks:[];if(!t.dense(c,`${e}.children[${String(s)}].marks`))return"";let d=null;for(let p of c){if(typeof p!="string")continue;let y=jn[p];y!==void 0?l=`${y}${l}${y}`:o.has(p)?d=o.get(p)??null:t.fail(`${e}.children[${String(s)}].marks`,`names ${JSON.stringify(p)}, which is neither a style nor a link`)}return d===null?l:`[${l}](${d})`}).join(""):""}function mn(n,e){if(typeof n!="object"||n===null)return"none";let t=n;if(t.enabled!==!0)return"off";let o=typeof t.startsAt=="string"?Date.parse(t.startsAt):null,i=typeof t.endsAt=="string"?Date.parse(t.endsAt):null;return o!==null&&e.getTime()<o?"not-started":i!==null&&e.getTime()>=i?"ended":"shown"}function P(n,e,t){return typeof e._key=="string"?`${n}[_key=="${e._key}"]`:`${n}[${String(t)}]`}function rn(n,e){let t=new N,o=t.object(n,"homePage");if(o===null)throw new k(L,t.problems);let i=typeof o._id=="string"?o._id:L;o._type!=="homePage"&&t.fail("_type",`is ${JSON.stringify(o._type)}, not homePage`);let r=null,a=o.hero===void 0?t.fail("hero","is missing"):t.object(o.hero,"hero");if(a!==null){let f=t.photos(a.photos,"hero.photos",2),g=t.requiredCopy(a.headline,"hero.headline"),m=t.copy(a.subline,"hero.subline"),T=t.copy(a.lead,"hero.lead"),I=t.action(a.primaryAction,"hero.primaryAction"),$n=t.action(a.secondaryAction,"hero.secondaryAction");g!==null&&(r={heading:g,subline:m,intro:T,image:f[0]??null,inset:f[1]??null,cta:I,secondaryCta:$n})}let s=[],u=[],l="",c=mn(o.campaign,e.now);if(c==="shown"){let f=t.object(o.campaign,"campaign");if(f!==null){let g=t.requiredCopy(f.title,"campaign.title"),m=t.photos(f.photos,"campaign.photos",3);m.length===0&&t.fail("campaign.photos","is empty; a shown campaign needs at least one photo");let T=on(f.body,"campaign.body",t);T===""&&t.fail("campaign.body","is empty; a shown campaign needs its text"),f.bodyCopySource==="proposed"&&t.proposed.push({where:"campaign.body",text:T});let I=t.action(f.action,"campaign.action");I!==null&&u.push({where:"campaign.action.href",href:I.href}),g!==null&&(l=`# ${Y(g)}
|
|
5
5
|
|
|
6
|
-
${T}`),s.push({kind:"campaign",action:b,images:m})}}let d=[],p=o.blocks??[];Array.isArray(p)?t.dense(p,"blocks")&&p.forEach((f,g)=>{let m=t.object(f,`blocks[${String(g)}]`);if(m===null)return;let T=P("blocks",m,g),b=wn(m,T,t);b!==null&&(u.push(...Sn(b,m,T)),b.kind==="locations"&&b.anchor!==null&&(d.includes(b.anchor)&&t.fail(`${T}.jumpLink`,`repeats "${b.anchor}", already used by another section`),d.push(b.anchor)),s.push(b))}):t.fail("blocks","is not a list");let y=[];r?.cta&&y.push({where:"hero.primaryAction.href",href:r.cta.href}),r?.secondaryCta&&y.push({where:"hero.secondaryAction.href",href:r.secondaryCta.href}),y.push(...u);for(let{where:f,href:g}of y)g.startsWith("#")&&!d.includes(g.slice(1))&&t.fail(f,`jumps to ${g}, which no section on the page is named`);if(t.problems.length>0)throw new I(i,t.problems);return{composition:{intro:null,photo:null,hero:r,blocks:s},body:l,campaign:c,proposedCopy:t.proposed}}function Sn(n,e,t){switch(n.kind){case"feature_stories":{let o=Array.isArray(e.stories)?e.stories:[];return n.items.map((i,r)=>({where:`${P(`${t}.stories`,o[r]??{},r)}.action.href`,href:i.action.href}))}case"accent_band":return n.action===null?[]:[{where:`${t}.action.href`,href:n.action.href}];case"cta":return[{where:`${t}.action.href`,href:n.link.href}];default:return[]}}function U(n,e,t){let o=n.jumpLink;return o==null||o===""?null:typeof o!="string"||!M.test(o)?t.fail(`${e}.jumpLink`,`is ${JSON.stringify(o)}, not lowercase words joined by hyphens`):o}function wn(n,e,t){switch(n._type){case"featureStoriesBlock":{let o=t.requiredCopy(n.heading,`${e}.heading`),i=t.copy(n.tail,`${e}.tail`),r=n.stories;if(!Array.isArray(r)||r.length===0)return t.fail(`${e}.stories`,"has no stories");if(!t.dense(r,`${e}.stories`))return null;let a=[];return r.forEach((s,u)=>{let l=t.object(s,`${e}.stories[${String(u)}]`);if(l===null)return;let c=P(`${e}.stories`,l,u),d=t.requiredCopy(l.heading,`${c}.heading`),p=t.requiredCopy(l.body,`${c}.body`),y=t.requiredAction(l.action,`${c}.action`),f=t.photo(l.photo,`${c}.photo`),g=l.layout??"wide";if(!Z.includes(g)){t.fail(`${c}.layout`,`is ${JSON.stringify(g)}, not wide, tall, round or free`);return}let m=l.onCard??!1;if(typeof m!="boolean"){t.fail(`${c}.onCard`,"is not on or off");return}d===null||p===null||y===null||a.push({heading:d,body:p,action:y,image:f,shape:g,card:m})}),o===null?null:{kind:"feature_stories",heading:o,tail:i,items:a}}case"surfaceCardBlock":{let o=t.requiredCopy(n.heading,`${e}.heading`),i=t.copy(n.body,`${e}.body`),r=t.requiredAction(n.action,`${e}.action`);return o===null||r===null?null:{kind:"cta",heading:Y(o),body:i===null?null:Y(i),link:{label:Y(r.label),href:r.href}}}case"accentBandBlock":{let o=t.requiredCopy(n.heading,`${e}.heading`),i=t.requiredCopy(n.body,`${e}.body`),r=t.action(n.action,`${e}.action`),a=t.photo(n.photo,`${e}.photo`);return o===null||i===null?null:{kind:"accent_band",heading:o,body:i,action:r,image:a}}case"locationsBlock":{let o=U(n,e,t),i=t.requiredCopy(n.heading,`${e}.heading`),r=t.copy(n.tail,`${e}.tail`),a=t.photo(n.photo,`${e}.photo`);return i===null?null:{kind:"locations",anchor:o,heading:i,tail:r,image:a}}default:return t.fail(`${e}._type`,`is ${JSON.stringify(n._type)}, not a section type this reader knows`)}}function V(n,e,t,o,i){let r=n.layout,a=t.find(s=>s===r);return a!==void 0?a:(i.push({code:_.layoutDefaulted,where:`${e}.layout`}),o)}function en(n,e,t,o){if(n==null)return null;let i=t.object(n,e);if(i===null)return null;let r=i.asset,a=typeof r=="object"&&r!==null?r._ref:void 0;if(typeof a!="string"||a==="")return o.push({code:_.imageMissingAsset,where:`${e}.asset`}),null;let s=i.alt;if(typeof s!="string"||s.trim()==="")return o.push({code:_.imageMissingAlt,where:`${e}.alt`}),null;let u=t.optionalString(i.caption,`${e}.caption`),l=null;if(i.hotspot!==void 0&&i.hotspot!==null){let c=t.object(i.hotspot,`${e}.hotspot`),d=c?.x,p=c?.y;typeof d=="number"&&typeof p=="number"&&d>=0&&d<=1&&p>=0&&p<=1?l={x:d,y:p}:c!==null&&t.fail(`${e}.hotspot`,"is not a point inside the image")}return{asset:a,alt:s,caption:u,hotspot:l}}function qn(n,e,t,o){switch(n._type){case"featureStoriesBlock":case"surfaceCardBlock":case"accentBandBlock":case"locationsBlock":{let i=wn(n,e,t);return i===null||i.kind==="campaign"?null:i}case"textMediaBlock":{let i=U(n,e,t),r=t.requiredCopy(n.heading,`${e}.heading`),a=t.copy(n.tail,`${e}.tail`),s=t.requiredCopy(n.body,`${e}.body`),u=t.action(n.action,`${e}.action`),l=en(n.photo,`${e}.photo`,t,o),c=V(n,e,E,$.Split,o);return r===null||s===null?null:{kind:"text_media",anchor:i,layout:c,heading:r,tail:a,body:s,action:u,image:l}}case"faqBlock":{let i=U(n,e,t),r=t.requiredCopy(n.heading,`${e}.heading`),a=t.copy(n.tail,`${e}.tail`),s=t.copy(n.intro,`${e}.intro`),u=V(n,e,j,$.HeadingList,o),l=n.items;if(!Array.isArray(l)||l.length===0)return t.fail(`${e}.items`,"has no questions");if(!t.dense(l,`${e}.items`))return null;let c=[];return l.forEach((d,p)=>{let y=t.object(d,`${e}.items[${String(p)}]`);if(y===null)return;let f=P(`${e}.items`,y,p);if(y._type!==void 0&&y._type!=="faqItem"){t.fail(`${f}._type`,`is ${JSON.stringify(y._type)}, not faqItem`);return}let g=t.requiredCopy(y.question,`${f}.question`),m=t.requiredCopy(y.answer,`${f}.answer`);g!==null&&m!==null&&c.push({question:g,answer:m})}),r===null?null:{kind:"faq",anchor:i,layout:u,heading:r,tail:a,intro:s,items:c}}case"galleryBlock":{let i=U(n,e,t),r=t.copy(n.heading,`${e}.heading`),a=V(n,e,G,$.StaggerRow,o),s=n.photos??[];if(!Array.isArray(s))return t.fail(`${e}.photos`,"is not a list of photos");if(!t.dense(s,`${e}.photos`))return null;if(s.length<F||s.length>z)return t.fail(`${e}.photos`,`holds ${String(s.length)} photos; a gallery shows ${String(F)} to ${String(z)}`);let u=s.flatMap((l,c)=>{let d=en(l,P(`${e}.photos`,typeof l=="object"&&l!==null?l:{},c),t,o);return d===null?[]:[d]});return u.length===0?(o.push({code:_.emptySkipped,where:e}),null):{kind:"gallery",anchor:i,layout:a,heading:r,images:u}}case"contactBlock":{let i=U(n,e,t),r=t.requiredCopy(n.heading,`${e}.heading`),a=t.copy(n.body,`${e}.body`),s=y=>{let f=n[y]??!0;return typeof f=="boolean"?f:(t.fail(`${e}.${y}`,"is not on or off"),!1)},u=s("showEmail"),l=s("showPhone"),c=t.action(n.action,`${e}.action`),d=en(n.photo,`${e}.photo`,t,o),p=V(n,e,E,$.Split,o);return r===null?null:!u&&!l&&a===null&&c===null?(o.push({code:_.emptySkipped,where:e}),null):{kind:"contact",anchor:i,layout:p,heading:r,body:a,showEmail:u,showPhone:l,action:c,image:d}}default:return o.push({code:_.unknownType,where:`${e}._type`}),null}}function Mn(n,e,t){switch(n.kind){case"text_media":case"contact":return n.action===null?[]:[{where:`${t}.action.href`,href:n.action.href}];case"faq":case"gallery":return[];default:return Sn(n,e,t)}}function Un(n,e){let t=[],o=[];if(!Array.isArray(n))return e.fail("sections","is not a list"),{sections:t,warnings:o};if(!e.dense(n,"sections"))return{sections:t,warnings:o};let i=[],r=[];n.forEach((a,s)=>{let u=e.object(a,`sections[${String(s)}]`);if(u===null)return;let l=P("sections",u,s),c=qn(u,l,e,o);if(c===null)return;r.push(...Mn(c,u,l));let d="anchor"in c?c.anchor:null;d!==null&&(i.includes(d)&&e.fail(`${l}.jumpLink`,`repeats "${d}", already used by another section`),i.push(d)),t.push(c)});for(let{where:a,href:s}of r)s.startsWith("#")&&!i.includes(s.slice(1))&&e.fail(a,`jumps to ${s}, which no section on the page is named`);return{sections:t,warnings:o}}function B(n){let e=new N,t=e.object(n,"page");if(t===null)throw new I("page",e.problems);let o=typeof t._id=="string"?t._id:"page";t._type!=="page"&&e.fail("_type",`is ${JSON.stringify(t._type)}, not page`);let i=e.optionalString(t.title,"title");i===null&&e.fail("title","is missing"),t.titleCopySource==="proposed"&&i!==null&&e.proposed.push({where:"title",text:i});let r=t.slug,a=typeof r?.current=="string"&&r.current!==""?r.current:null;a===null&&e.fail("slug.current","is missing");let s=e.copy(t.lead,"lead"),u=e.photo(t.photo,"photo"),l=on(t.body,"body",e);t.bodyCopySource==="proposed"&&e.proposed.push({where:"body",text:l});let c=t.sections===void 0||t.sections===null?null:Un(t.sections,e);if(e.problems.length>0||i===null||a===null)throw new I(o,e.problems);return{slug:a,title:i,composition:{intro:s===null?null:Y(s),photo:u,hero:null,blocks:[]},body:l,migrated:t.migrated===!0,proposedCopy:e.proposed,...c===null?{}:c}}function sn(n){let e=new N,t=e.object(n,"siteSettings");if(t===null)throw new I(H,e.problems);let o=e.optionalString(t.title,"title");o===null&&e.fail("title","is missing; a site needs its name");let i=e.optionalString(t.description,"description"),r=t.contact===void 0?{}:e.object(t.contact,"contact")??{},a=e.optionalString(r.email,"contact.email"),s=e.optionalString(r.phone,"contact.phone"),u=[],l=t.social??[];if(Array.isArray(l)?e.dense(l,"social")&&l.forEach((c,d)=>{let p=e.object(c,`social[${String(d)}]`);if(p===null)return;let y=e.optionalString(p.network,`social[${String(d)}].network`),f=e.optionalString(p.url,`social[${String(d)}].url`);if(y===null||f===null||!/^https?:\/\//.test(f)){e.fail(`social[${String(d)}]`,"needs a network and a web address");return}u.push({network:y,url:f})}):e.fail("social","is not a list"),e.problems.length>0||o===null)throw new I(H,e.problems);return{name:o,description:i,contact:{email:a,phone:s},social:u}}var W="*[_id == $id][0]",an='*[_type == "page" && defined(slug.current)]|order(slug.current asc)',ln='*[_type == "page" && slug.current == $slug][0]';function Yn(n){return{home:async({now:e})=>{let t=await n.query(W,{params:{id:L}});return t==null?null:rn(t,{now:e})},pages:async()=>{let e=await n.query(an);if(!Array.isArray(e))throw new I("page",["the page query did not return a list"]);if(!S(e))throw new I("page",["the page query contains missing entries"]);return e.map(t=>B(t))},pageBySlug:async e=>{let t=await n.query(ln,{params:{slug:e}});return t==null?null:B(t)},siteSettings:async()=>{let e=await n.query(W,{params:{id:H}});return e==null?null:sn(e)}}}function X(n,e,t,o){if(!o(e))throw new TypeError("Invalid CMS content fallback");return n==null?{data:e,fallbackFields:["$"]}:{data:t(n),fallbackFields:[]}}function Bn(n){if(!(n instanceof Date)||!Number.isFinite(n.getTime()))throw new TypeError("Invalid CMS campaign date");let e=n.getTime();return A({name:"homePage.v1",query:W,params:{id:L},dependencies:{types:["homePage"],ids:[L]},resolve:(t,o)=>X(t,o,i=>rn(i,{now:new Date(e)}),gn)})}function Wn(n){if(typeof n!="string"||n==="")throw new TypeError("Invalid CMS page slug");return A({name:"page.v1",query:ln,params:{slug:n},dependencies:{types:["page"]},resolve:(e,t)=>X(e,t,B,nn)})}function Fn(){return A({name:"pages.v1",query:an,params:{},dependencies:{types:["page"]},resolve:(n,e)=>X(n,e,t=>{if(!Array.isArray(t))throw new I("page",["the page query did not return a list"]);if(!S(t))throw new I("page",["the page query contains missing entries"]);return t.map(o=>B(o))},t=>S(t)&&t.every(o=>o!==null&&nn(o)))})}function zn(){return A({name:"siteSettings.v1",query:W,params:{id:H},dependencies:{types:["siteSettings"],ids:[H]},resolve:(n,e)=>X(n,e,sn,hn)})}var In=["columns","rows"],kn=40,_n="siteHero.layout.defaulted",Tn="siteHero.tagline.dropped",Cn="siteHero.taglines.defaulted";var D={key:"hero",documentId:"siteHero",documentType:"siteHero",fields:[{name:"heading",label:"Heading",noun:{article:"a",word:"heading"},kind:"single-line",required:!0,minLength:1,maxLength:80,noTrailingFullStop:!0},{name:"intro",label:"Introduction",noun:{article:"an",word:"introduction"},kind:"multi-line",required:!0,minLength:1,maxLength:320}],copy:{currentTitle:"On your site now",editTitle:"Edit and publish",empty:"Your site has no hero text yet. Whatever you publish below becomes its first version."}};function Qn(n,e){let{article:t,word:o}=n.noun;if(e.length===0)return n.required?`Enter ${t} ${o}.`:null;let i=[...e].length;return i<n.minLength?`Make the ${o} at least ${String(n.minLength)} characters. It is ${String(i)} now.`:i>n.maxLength?`Keep the ${o} to ${String(n.maxLength)} characters or fewer. It is ${String(i)} now.`:e.includes("\u2014")?`The ${o} contains a long dash. Use a comma, a colon or a short dash instead.`:n.kind==="single-line"&&/[\r\n]/.test(e)?`The ${o} must be a single line.`:n.noTrailingFullStop===!0&&e.endsWith(".")?`${o.charAt(0).toUpperCase()}${o.slice(1)}s on your site do not end with a full stop. Remove the last full stop.`:null}function cn(n,e){let t={},o={};for(let i of n.fields){let r=Object.hasOwn(e,i.name)?e[i.name]:void 0,a=typeof r=="string"?r.trim():"",s=Qn(i,a);Object.defineProperty(s===null?t:o,i.name,{value:s??a,enumerable:!0})}return Object.keys(o).length>0?{ok:!1,errors:o}:{ok:!0,value:t}}function An(n){if(!Array.isArray(n))return{ok:!1,error:"Enter a list of taglines."};let e=D.fields[0];if(!e)throw new TypeError("Missing siteHero heading definition");let t={...e,name:"text",noun:{article:"a",word:"tagline"},maxLength:kn},o=[],i=[],r=new Set;for(let[a,s]of n.entries()){if(!s||typeof s!="object"||Array.isArray(s)){i.push({index:a,error:"Enter a key and text for each tagline."});continue}let u=s,l=Object.hasOwn(u,"key")?u.key:void 0;if(typeof l!="string"||!/^[a-z][a-z0-9_-]{0,31}$/.test(l)){i.push({index:a,error:"Use a lowercase key of 1 to 32 letters, numbers, short dashes or underscores, starting with a letter."});continue}if(r.has(l)){i.push({index:a,error:"Use each tagline key only once."});continue}let c=cn({...D,fields:[t]},u);if(!c.ok){i.push({index:a,error:c.errors.text??"Invalid tagline."});continue}let d=c.value.text??"";if((d.match(/\p{L}/gu)?.length??0)>=2&&!/\p{Ll}/u.test(d)){i.push({index:a,error:"Use sentence case for the tagline, rather than all capitals."});continue}r.add(l),o.push({key:l,text:d})}return{ok:!0,value:o,dropped:i}}function En(n){let e=An(n);if(!e.ok)return e;let t=e.dropped[0];return t?{ok:!1,error:t.error}:{ok:!0,value:e.value}}function bn(n){return In.some(e=>n===e)}function Rn(n,e){let t=cn(D,e),o=En(e.taglines??[]);if(!t.ok||!o.ok||e.layout!==void 0&&!bn(e.layout))throw new TypeError("Invalid siteHero fallback");let i={heading:t.value.heading??"",intro:t.value.intro??"",layout:e.layout??"columns",taglines:o.value};if(n===null||typeof n!="object"||Array.isArray(n))return{data:i,fallbackFields:["$"]};let r=n,a=cn(D,r),s=a.ok?[]:Object.keys(a.errors);for(let p of D.fields)if(!s.includes(p.name)){let y=a.ok?a.value[p.name]:r[p.name];typeof y=="string"&&(p.name==="heading"||p.name==="intro")&&(i[p.name]=y.trim())}let u=Object.hasOwn(r,"layout")?r.layout:void 0,l=[];bn(u)?i.layout=u:(i.layout="columns",s.push("layout"),l.push(_n));let c=An(Object.hasOwn(r,"taglines")?r.taglines:void 0);if(c.ok){i.taglines=c.value;for(let{index:p}of c.dropped)s.push(`taglines[${String(p)}]`);c.dropped.length>0&&l.push(Tn)}else s.push("taglines"),l.push(Cn);let d=[...D.fields.map(p=>p.name),"layout","taglines"].every(p=>s.includes(p));return{data:i,fallbackFields:d?["$"]:s,...l.length>0?{warnings:l}:{}}}function Jn(){return A({name:"siteHero.v1",query:'*[_id == $id && _type == "siteHero"][0]{heading,intro,layout,taglines}',params:{id:"siteHero"},dependencies:{types:["siteHero"],ids:["siteHero"]},resolve:Rn})}export{an as CONTENT_PAGES_QUERY,ln as CONTENT_PAGE_BY_SLUG_QUERY,j as HEADING_LIST_LAYOUTS,W as HOME_PAGE_DOCUMENT_QUERY,tn as MALFORMED_CONTENT,I as MalformedContentError,K as READER_ACTION_HREF,z as READER_GALLERY_PHOTO_LIMIT,F as READER_GALLERY_PHOTO_MIN,L as READER_HOME_PAGE_ID,M as READER_JUMP_LINK,J as READER_PHOTO_SLUG,Hn as READER_SECTION_KINDS,H as READER_SITE_SETTINGS_ID,Z as READER_STORY_LAYOUTS,$ as SECTION_LAYOUT_DEFAULTS,_ as SECTION_WARNINGS,In as SITE_HERO_LAYOUTS,_n as SITE_HERO_LAYOUT_WARNING,Cn as SITE_HERO_TAGLINES_DEFAULTED_WARNING,Tn as SITE_HERO_TAGLINE_DROPPED_WARNING,kn as SITE_HERO_TAGLINE_MAX_LENGTH,E as SPLIT_LAYOUTS,G as STAGGER_ROW_LAYOUTS,mn as campaignState,Wn as contentPageQuery,Fn as contentPagesQuery,Yn as createSiteContentReader,Bn as homeContentQuery,B as parseContentPage,rn as parseHomePage,Rn as parseSiteHero,sn as parseSiteSettings,Dn as portableTextToMarkdown,Jn as siteHeroQuery,zn as siteSettingsQuery,En as validateSiteHeroTaglines};
|
|
6
|
+
${T}`),s.push({kind:"campaign",action:I,images:m})}}let d=[],p=o.blocks??[];Array.isArray(p)?t.dense(p,"blocks")&&p.forEach((f,g)=>{let m=t.object(f,`blocks[${String(g)}]`);if(m===null)return;let T=P("blocks",m,g),I=wn(m,T,t);I!==null&&(u.push(...Sn(I,m,T)),I.kind==="locations"&&I.anchor!==null&&(d.includes(I.anchor)&&t.fail(`${T}.jumpLink`,`repeats "${I.anchor}", already used by another section`),d.push(I.anchor)),s.push(I))}):t.fail("blocks","is not a list");let y=[];r?.cta&&y.push({where:"hero.primaryAction.href",href:r.cta.href}),r?.secondaryCta&&y.push({where:"hero.secondaryAction.href",href:r.secondaryCta.href}),y.push(...u);for(let{where:f,href:g}of y)g.startsWith("#")&&!d.includes(g.slice(1))&&t.fail(f,`jumps to ${g}, which no section on the page is named`);if(t.problems.length>0)throw new k(i,t.problems);return{composition:{intro:null,photo:null,hero:r,blocks:s},body:l,campaign:c,proposedCopy:t.proposed}}function Sn(n,e,t){switch(n.kind){case"feature_stories":{let o=Array.isArray(e.stories)?e.stories:[];return n.items.map((i,r)=>({where:`${P(`${t}.stories`,o[r]??{},r)}.action.href`,href:i.action.href}))}case"accent_band":return n.action===null?[]:[{where:`${t}.action.href`,href:n.action.href}];case"cta":return[{where:`${t}.action.href`,href:n.link.href}];default:return[]}}function U(n,e,t){let o=n.jumpLink;return o==null||o===""?null:typeof o!="string"||!M.test(o)?t.fail(`${e}.jumpLink`,`is ${JSON.stringify(o)}, not lowercase words joined by hyphens`):o}function wn(n,e,t){switch(n._type){case"featureStoriesBlock":{let o=t.requiredCopy(n.heading,`${e}.heading`),i=t.copy(n.tail,`${e}.tail`),r=n.stories;if(!Array.isArray(r)||r.length===0)return t.fail(`${e}.stories`,"has no stories");if(!t.dense(r,`${e}.stories`))return null;let a=[];return r.forEach((s,u)=>{let l=t.object(s,`${e}.stories[${String(u)}]`);if(l===null)return;let c=P(`${e}.stories`,l,u),d=t.requiredCopy(l.heading,`${c}.heading`),p=t.requiredCopy(l.body,`${c}.body`),y=t.requiredAction(l.action,`${c}.action`),f=t.photo(l.photo,`${c}.photo`),g=l.layout??"wide";if(!Z.includes(g)){t.fail(`${c}.layout`,`is ${JSON.stringify(g)}, not wide, tall, round or free`);return}let m=l.onCard??!1;if(typeof m!="boolean"){t.fail(`${c}.onCard`,"is not on or off");return}d===null||p===null||y===null||a.push({heading:d,body:p,action:y,image:f,shape:g,card:m})}),o===null?null:{kind:"feature_stories",heading:o,tail:i,items:a}}case"surfaceCardBlock":{let o=t.requiredCopy(n.heading,`${e}.heading`),i=t.copy(n.body,`${e}.body`),r=t.requiredAction(n.action,`${e}.action`);return o===null||r===null?null:{kind:"cta",heading:Y(o),body:i===null?null:Y(i),link:{label:Y(r.label),href:r.href}}}case"accentBandBlock":{let o=t.requiredCopy(n.heading,`${e}.heading`),i=t.requiredCopy(n.body,`${e}.body`),r=t.action(n.action,`${e}.action`),a=t.photo(n.photo,`${e}.photo`);return o===null||i===null?null:{kind:"accent_band",heading:o,body:i,action:r,image:a}}case"locationsBlock":{let o=U(n,e,t),i=t.requiredCopy(n.heading,`${e}.heading`),r=t.copy(n.tail,`${e}.tail`),a=t.photo(n.photo,`${e}.photo`);return i===null?null:{kind:"locations",anchor:o,heading:i,tail:r,image:a}}default:return t.fail(`${e}._type`,`is ${JSON.stringify(n._type)}, not a section type this reader knows`)}}function V(n,e,t,o,i){let r=n.layout,a=t.find(s=>s===r);return a!==void 0?a:(i.push({code:b.layoutDefaulted,where:`${e}.layout`}),o)}function en(n,e,t,o){if(n==null)return null;let i=t.object(n,e);if(i===null)return null;let r=i.asset,a=typeof r=="object"&&r!==null?r._ref:void 0;if(typeof a!="string"||a==="")return o.push({code:b.imageMissingAsset,where:`${e}.asset`}),null;let s=i.alt;if(typeof s!="string"||s.trim()==="")return o.push({code:b.imageMissingAlt,where:`${e}.alt`}),null;let u=t.optionalString(i.caption,`${e}.caption`),l=null;if(i.hotspot!==void 0&&i.hotspot!==null){let c=t.object(i.hotspot,`${e}.hotspot`),d=c?.x,p=c?.y;typeof d=="number"&&typeof p=="number"&&d>=0&&d<=1&&p>=0&&p<=1?l={x:d,y:p}:c!==null&&t.fail(`${e}.hotspot`,"is not a point inside the image")}return{asset:a,alt:s,caption:u,hotspot:l}}function qn(n){return typeof n=="string"?n.slice(0,64).replace(/[^A-Za-z0-9_.-]/g,"?"):"?"}function Mn(n,e,t,o){switch(n._type){case"featureStoriesBlock":case"surfaceCardBlock":case"accentBandBlock":case"locationsBlock":{let i=wn(n,e,t);return i===null||i.kind==="campaign"?null:i}case"textMediaBlock":{let i=U(n,e,t),r=t.requiredCopy(n.heading,`${e}.heading`),a=t.copy(n.tail,`${e}.tail`),s=t.requiredCopy(n.body,`${e}.body`),u=t.action(n.action,`${e}.action`),l=en(n.photo,`${e}.photo`,t,o),c=V(n,e,E,$.Split,o);return r===null||s===null?null:{kind:"text_media",anchor:i,layout:c,heading:r,tail:a,body:s,action:u,image:l}}case"faqBlock":{let i=U(n,e,t),r=t.requiredCopy(n.heading,`${e}.heading`),a=t.copy(n.tail,`${e}.tail`),s=t.copy(n.intro,`${e}.intro`),u=V(n,e,j,$.HeadingList,o),l=n.items;if(!Array.isArray(l)||l.length===0)return t.fail(`${e}.items`,"has no questions");if(!t.dense(l,`${e}.items`))return null;let c=[];return l.forEach((d,p)=>{let y=t.object(d,`${e}.items[${String(p)}]`);if(y===null)return;let f=P(`${e}.items`,y,p);if(y._type!==void 0&&y._type!=="faqItem"){t.fail(`${f}._type`,`is ${JSON.stringify(y._type)}, not faqItem`);return}let g=t.requiredCopy(y.question,`${f}.question`),m=t.requiredCopy(y.answer,`${f}.answer`);g!==null&&m!==null&&c.push({question:g,answer:m})}),r===null?null:{kind:"faq",anchor:i,layout:u,heading:r,tail:a,intro:s,items:c}}case"galleryBlock":{let i=U(n,e,t),r=t.copy(n.heading,`${e}.heading`),a=V(n,e,G,$.StaggerRow,o),s=n.photos??[];if(!Array.isArray(s))return t.fail(`${e}.photos`,"is not a list of photos");if(!t.dense(s,`${e}.photos`))return null;if(s.length<F||s.length>z)return t.fail(`${e}.photos`,`holds ${String(s.length)} photos; a gallery shows ${String(F)} to ${String(z)}`);let u=s.flatMap((l,c)=>{let d=en(l,P(`${e}.photos`,typeof l=="object"&&l!==null?l:{},c),t,o);return d===null?[]:[d]});return u.length===0?(o.push({code:b.emptySkipped,where:e}),null):{kind:"gallery",anchor:i,layout:a,heading:r,images:u}}case"contactBlock":{let i=U(n,e,t),r=t.requiredCopy(n.heading,`${e}.heading`),a=t.copy(n.body,`${e}.body`),s=y=>{let f=n[y]??!0;return typeof f=="boolean"?f:(t.fail(`${e}.${y}`,"is not on or off"),!1)},u=s("showEmail"),l=s("showPhone"),c=t.action(n.action,`${e}.action`),d=en(n.photo,`${e}.photo`,t,o),p=V(n,e,E,$.Split,o);return r===null?null:!u&&!l&&a===null&&c===null?(o.push({code:b.emptySkipped,where:e}),null):{kind:"contact",anchor:i,layout:p,heading:r,body:a,showEmail:u,showPhone:l,action:c,image:d}}default:return o.push({code:b.unknownType,where:`${e}._type`,type:qn(n._type)}),null}}function Un(n,e,t){switch(n.kind){case"text_media":case"contact":return n.action===null?[]:[{where:`${t}.action.href`,href:n.action.href}];case"faq":case"gallery":return[];default:return Sn(n,e,t)}}function Yn(n,e){let t=[],o=[];if(!Array.isArray(n))return e.fail("sections","is not a list"),{sections:t,warnings:o};if(!e.dense(n,"sections"))return{sections:t,warnings:o};let i=[],r=[];n.forEach((a,s)=>{let u=e.object(a,`sections[${String(s)}]`);if(u===null)return;let l=P("sections",u,s),c=Mn(u,l,e,o);if(c===null)return;r.push(...Un(c,u,l));let d="anchor"in c?c.anchor:null;d!==null&&(i.includes(d)&&e.fail(`${l}.jumpLink`,`repeats "${d}", already used by another section`),i.push(d)),t.push(c)});for(let{where:a,href:s}of r)s.startsWith("#")&&!i.includes(s.slice(1))&&e.fail(a,`jumps to ${s}, which no section on the page is named`);return{sections:t,warnings:o}}function B(n){let e=new N,t=e.object(n,"page");if(t===null)throw new k("page",e.problems);let o=typeof t._id=="string"?t._id:"page";t._type!=="page"&&e.fail("_type",`is ${JSON.stringify(t._type)}, not page`);let i=e.optionalString(t.title,"title");i===null&&e.fail("title","is missing"),t.titleCopySource==="proposed"&&i!==null&&e.proposed.push({where:"title",text:i});let r=t.slug,a=typeof r?.current=="string"&&r.current!==""?r.current:null;a===null&&e.fail("slug.current","is missing");let s=e.copy(t.lead,"lead"),u=e.photo(t.photo,"photo"),l=on(t.body,"body",e);t.bodyCopySource==="proposed"&&e.proposed.push({where:"body",text:l});let c=t.sections===void 0||t.sections===null?null:Yn(t.sections,e);if(e.problems.length>0||i===null||a===null)throw new k(o,e.problems);return{slug:a,title:i,composition:{intro:s===null?null:Y(s),photo:u,hero:null,blocks:[]},body:l,migrated:t.migrated===!0,proposedCopy:e.proposed,...c===null?{}:c}}function sn(n){let e=new N,t=e.object(n,"siteSettings");if(t===null)throw new k(H,e.problems);let o=e.optionalString(t.title,"title");o===null&&e.fail("title","is missing; a site needs its name");let i=e.optionalString(t.description,"description"),r=t.contact===void 0?{}:e.object(t.contact,"contact")??{},a=e.optionalString(r.email,"contact.email"),s=e.optionalString(r.phone,"contact.phone"),u=[],l=t.social??[];if(Array.isArray(l)?e.dense(l,"social")&&l.forEach((c,d)=>{let p=e.object(c,`social[${String(d)}]`);if(p===null)return;let y=e.optionalString(p.network,`social[${String(d)}].network`),f=e.optionalString(p.url,`social[${String(d)}].url`);if(y===null||f===null||!/^https?:\/\//.test(f)){e.fail(`social[${String(d)}]`,"needs a network and a web address");return}u.push({network:y,url:f})}):e.fail("social","is not a list"),e.problems.length>0||o===null)throw new k(H,e.problems);return{name:o,description:i,contact:{email:a,phone:s},social:u}}var W="*[_id == $id][0]",an='*[_type == "page" && defined(slug.current)]|order(slug.current asc)',ln='*[_type == "page" && slug.current == $slug][0]';function Bn(n){return{home:async({now:e})=>{let t=await n.query(W,{params:{id:L}});return t==null?null:rn(t,{now:e})},pages:async()=>{let e=await n.query(an);if(!Array.isArray(e))throw new k("page",["the page query did not return a list"]);if(!S(e))throw new k("page",["the page query contains missing entries"]);return e.map(t=>B(t))},pageBySlug:async e=>{let t=await n.query(ln,{params:{slug:e}});return t==null?null:B(t)},siteSettings:async()=>{let e=await n.query(W,{params:{id:H}});return e==null?null:sn(e)}}}function X(n,e,t,o){if(!o(e))throw new TypeError("Invalid CMS content fallback");return n==null?{data:e,fallbackFields:["$"]}:{data:t(n),fallbackFields:[]}}function Wn(n){if(!(n instanceof Date)||!Number.isFinite(n.getTime()))throw new TypeError("Invalid CMS campaign date");let e=n.getTime();return A({name:"homePage.v1",query:W,params:{id:L},dependencies:{types:["homePage"],ids:[L]},resolve:(t,o)=>X(t,o,i=>rn(i,{now:new Date(e)}),gn)})}function Fn(n){if(typeof n!="string"||n==="")throw new TypeError("Invalid CMS page slug");return A({name:"page.v1",query:ln,params:{slug:n},dependencies:{types:["page"]},resolve:(e,t)=>X(e,t,B,nn)})}function zn(){return A({name:"pages.v1",query:an,params:{},dependencies:{types:["page"]},resolve:(n,e)=>X(n,e,t=>{if(!Array.isArray(t))throw new k("page",["the page query did not return a list"]);if(!S(t))throw new k("page",["the page query contains missing entries"]);return t.map(o=>B(o))},t=>S(t)&&t.every(o=>o!==null&&nn(o)))})}function Qn(){return A({name:"siteSettings.v1",query:W,params:{id:H},dependencies:{types:["siteSettings"],ids:[H]},resolve:(n,e)=>X(n,e,sn,hn)})}var kn=["columns","rows"],_n=40,bn="siteHero.layout.defaulted",Tn="siteHero.tagline.dropped",Cn="siteHero.taglines.defaulted";var D={key:"hero",documentId:"siteHero",documentType:"siteHero",fields:[{name:"heading",label:"Heading",noun:{article:"a",word:"heading"},kind:"single-line",required:!0,minLength:1,maxLength:80,noTrailingFullStop:!0},{name:"intro",label:"Introduction",noun:{article:"an",word:"introduction"},kind:"multi-line",required:!0,minLength:1,maxLength:320}],copy:{currentTitle:"On your site now",editTitle:"Edit and publish",empty:"Your site has no hero text yet. Whatever you publish below becomes its first version."}};function Jn(n,e){let{article:t,word:o}=n.noun;if(e.length===0)return n.required?`Enter ${t} ${o}.`:null;let i=[...e].length;return i<n.minLength?`Make the ${o} at least ${String(n.minLength)} characters. It is ${String(i)} now.`:i>n.maxLength?`Keep the ${o} to ${String(n.maxLength)} characters or fewer. It is ${String(i)} now.`:e.includes("\u2014")?`The ${o} contains a long dash. Use a comma, a colon or a short dash instead.`:n.kind==="single-line"&&/[\r\n]/.test(e)?`The ${o} must be a single line.`:n.noTrailingFullStop===!0&&e.endsWith(".")?`${o.charAt(0).toUpperCase()}${o.slice(1)}s on your site do not end with a full stop. Remove the last full stop.`:null}function cn(n,e){let t={},o={};for(let i of n.fields){let r=Object.hasOwn(e,i.name)?e[i.name]:void 0,a=typeof r=="string"?r.trim():"",s=Jn(i,a);Object.defineProperty(s===null?t:o,i.name,{value:s??a,enumerable:!0})}return Object.keys(o).length>0?{ok:!1,errors:o}:{ok:!0,value:t}}function An(n){if(!Array.isArray(n))return{ok:!1,error:"Enter a list of taglines."};let e=D.fields[0];if(!e)throw new TypeError("Missing siteHero heading definition");let t={...e,name:"text",noun:{article:"a",word:"tagline"},maxLength:_n},o=[],i=[],r=new Set;for(let[a,s]of n.entries()){if(!s||typeof s!="object"||Array.isArray(s)){i.push({index:a,error:"Enter a key and text for each tagline."});continue}let u=s,l=Object.hasOwn(u,"key")?u.key:void 0;if(typeof l!="string"||!/^[a-z][a-z0-9_-]{0,31}$/.test(l)){i.push({index:a,error:"Use a lowercase key of 1 to 32 letters, numbers, short dashes or underscores, starting with a letter."});continue}if(r.has(l)){i.push({index:a,error:"Use each tagline key only once."});continue}let c=cn({...D,fields:[t]},u);if(!c.ok){i.push({index:a,error:c.errors.text??"Invalid tagline."});continue}let d=c.value.text??"";if((d.match(/\p{L}/gu)?.length??0)>=2&&!/\p{Ll}/u.test(d)){i.push({index:a,error:"Use sentence case for the tagline, rather than all capitals."});continue}r.add(l),o.push({key:l,text:d})}return{ok:!0,value:o,dropped:i}}function En(n){let e=An(n);if(!e.ok)return e;let t=e.dropped[0];return t?{ok:!1,error:t.error}:{ok:!0,value:e.value}}function In(n){return kn.some(e=>n===e)}function Rn(n,e){let t=cn(D,e),o=En(e.taglines??[]);if(!t.ok||!o.ok||e.layout!==void 0&&!In(e.layout))throw new TypeError("Invalid siteHero fallback");let i={heading:t.value.heading??"",intro:t.value.intro??"",layout:e.layout??"columns",taglines:o.value};if(n===null||typeof n!="object"||Array.isArray(n))return{data:i,fallbackFields:["$"]};let r=n,a=cn(D,r),s=a.ok?[]:Object.keys(a.errors);for(let p of D.fields)if(!s.includes(p.name)){let y=a.ok?a.value[p.name]:r[p.name];typeof y=="string"&&(p.name==="heading"||p.name==="intro")&&(i[p.name]=y.trim())}let u=Object.hasOwn(r,"layout")?r.layout:void 0,l=[];In(u)?i.layout=u:(i.layout="columns",s.push("layout"),l.push(bn));let c=An(Object.hasOwn(r,"taglines")?r.taglines:void 0);if(c.ok){i.taglines=c.value;for(let{index:p}of c.dropped)s.push(`taglines[${String(p)}]`);c.dropped.length>0&&l.push(Tn)}else s.push("taglines"),l.push(Cn);let d=[...D.fields.map(p=>p.name),"layout","taglines"].every(p=>s.includes(p));return{data:i,fallbackFields:d?["$"]:s,...l.length>0?{warnings:l}:{}}}function Kn(){return A({name:"siteHero.v1",query:'*[_id == $id && _type == "siteHero"][0]{heading,intro,layout,taglines}',params:{id:"siteHero"},dependencies:{types:["siteHero"],ids:["siteHero"]},resolve:Rn})}export{an as CONTENT_PAGES_QUERY,ln as CONTENT_PAGE_BY_SLUG_QUERY,j as HEADING_LIST_LAYOUTS,W as HOME_PAGE_DOCUMENT_QUERY,tn as MALFORMED_CONTENT,k as MalformedContentError,K as READER_ACTION_HREF,z as READER_GALLERY_PHOTO_LIMIT,F as READER_GALLERY_PHOTO_MIN,L as READER_HOME_PAGE_ID,M as READER_JUMP_LINK,J as READER_PHOTO_SLUG,Hn as READER_SECTION_KINDS,H as READER_SITE_SETTINGS_ID,Z as READER_STORY_LAYOUTS,$ as SECTION_LAYOUT_DEFAULTS,b as SECTION_WARNINGS,kn as SITE_HERO_LAYOUTS,bn as SITE_HERO_LAYOUT_WARNING,Cn as SITE_HERO_TAGLINES_DEFAULTED_WARNING,Tn as SITE_HERO_TAGLINE_DROPPED_WARNING,_n as SITE_HERO_TAGLINE_MAX_LENGTH,E as SPLIT_LAYOUTS,G as STAGGER_ROW_LAYOUTS,mn as campaignState,Fn as contentPageQuery,zn as contentPagesQuery,Bn as createSiteContentReader,Wn as homeContentQuery,B as parseContentPage,rn as parseHomePage,Rn as parseSiteHero,sn as parseSiteSettings,Dn as portableTextToMarkdown,Kn as siteHeroQuery,Qn as siteSettingsQuery,En as validateSiteHeroTaglines};
|
|
7
7
|
//# sourceMappingURL=site-content.mjs.map
|