@weatherboard/cms 0.1.0 → 0.3.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 +122 -0
- package/dist/contracts/query.d.cts +1 -0
- package/dist/contracts/query.d.mts +1 -0
- package/dist/contracts/query.d.ts +1 -0
- package/dist/contracts/text.d.cts +26 -1
- package/dist/contracts/text.d.mts +26 -1
- package/dist/contracts/text.d.ts +26 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +3 -3
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +3 -3
- package/dist/next.cjs +1 -1
- package/dist/next.cjs.map +3 -3
- package/dist/next.mjs +1 -1
- package/dist/next.mjs.map +3 -3
- package/dist/portable/sections.d.cts +136 -0
- package/dist/portable/sections.d.mts +136 -0
- package/dist/portable/sections.d.ts +136 -0
- package/dist/portable/site-content.d.cts +13 -0
- package/dist/portable/site-content.d.mts +13 -0
- package/dist/portable/site-content.d.ts +13 -0
- package/dist/runtime/reader.d.cts +3 -1
- package/dist/runtime/reader.d.mts +3 -1
- package/dist/runtime/reader.d.ts +3 -1
- package/dist/sanity.cjs +1 -1
- package/dist/sanity.cjs.map +2 -2
- package/dist/sanity.mjs +1 -1
- package/dist/sanity.mjs.map +2 -2
- package/dist/server.cjs +1 -1
- package/dist/server.cjs.map +3 -3
- package/dist/server.mjs +1 -1
- package/dist/server.mjs.map +3 -3
- package/dist/site-content.cjs +3 -3
- package/dist/site-content.cjs.map +4 -4
- package/dist/site-content.d.cts +4 -0
- package/dist/site-content.d.mts +4 -0
- package/dist/site-content.d.ts +4 -0
- package/dist/site-content.mjs +3 -3
- package/dist/site-content.mjs.map +4 -4
- package/package.json +34 -5
package/dist/site-content.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
function
|
|
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 En=/^[A-Za-z][A-Za-z0-9_]{0,63}$/,Rn=/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;function $n(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"||!En.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"||!Rn.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:$n(n.dependencies),resolve:n.resolve})}var E=["media-end","media-start","media-below"],j=["beside","stacked"],q=["staggered","aligned"],$={Split:"media-end",HeadingList:"beside",StaggerRow:"staggered"},On={featureStoriesBlock:"feature_stories",surfaceCardBlock:"cta",accentBandBlock:"accent_band",locationsBlock:"locations",textMediaBlock:"text_media",faqBlock:"faq",galleryBlock:"gallery",contactBlock:"contact"},F=2,z=4,_={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),I=n=>typeof n=="string"&&n.trim()!=="",O=n=>n===null||typeof n=="string",R=n=>n===null||typeof n=="string"&&J.test(n),pn=n=>typeof n=="string"&&K.test(n),w=n=>I(n)||h(n)&&I(n.text)&&(n.copySource==="captured"||n.copySource==="proposed"),T=n=>n===null||w(n),dn=n=>h(n)&&w(n.label)&&pn(n.href),x=n=>n===null||dn(n),Q=n=>n===null||typeof n=="string"&&G.test(n),M=(n,e)=>n.some(t=>t===e),v=n=>h(n)&&I(n.asset)&&I(n.alt)&&O(n.caption)&&(n.hotspot===null||h(n.hotspot)&&typeof n.hotspot.x=="number"&&typeof n.hotspot.y=="number");function yn(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"&&G.test(n.anchor))&&w(n.heading)&&T(n.tail)&&R(n.image);case"feature_stories":return w(n.heading)&&T(n.tail)&&S(n.items)&&n.items.length>0&&n.items.every(e=>h(e)&&w(e.heading)&&w(e.body)&&dn(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 I(n.heading)&&O(n.body)&&h(n.link)&&I(n.link.label)&&pn(n.link.href);default:return!1}}function xn(n){if(!h(n))return!1;switch(n.kind){case"campaign":return!1;case"text_media":return Q(n.anchor)&&M(E,n.layout)&&w(n.heading)&&T(n.tail)&&w(n.body)&&x(n.action)&&(n.image===null||v(n.image));case"faq":return Q(n.anchor)&&M(j,n.layout)&&w(n.heading)&&T(n.tail)&&T(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)&&M(q,n.layout)&&T(n.heading)&&S(n.images)&&n.images.length>0&&n.images.every(v);case"contact":return Q(n.anchor)&&M(E,n.layout)&&w(n.heading)&&T(n.body)&&typeof n.showEmail=="boolean"&&typeof n.showPhone=="boolean"&&x(n.action)&&(n.image===null||v(n.image));default:return yn(n)}}function Ln(n,e){if(n===void 0)return e===void 0;if(!S(n)||!n.every(xn)||!S(e)||!e.every(r=>h(r)&&M(Object.values(_),r.code)&&I(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 fn(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)||!T(e.subline)||!T(e.intro)||!R(e.image)||!R(e.inset)||!x(e.cta)||!x(e.secondaryCta))||!n.blocks.every(yn))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 gn(n){return S(n)&&n.every(e=>h(e)&&I(e.where)&&typeof e.text=="string")}function hn(n){return n===null||h(n)&&fn(n.composition)&&typeof n.body=="string"&&gn(n.proposedCopy)&&typeof n.campaign=="string"&&["shown","off","not-started","ended","none"].includes(n.campaign)}function nn(n){return n===null||h(n)&&I(n.slug)&&I(n.title)&&fn(n.composition)&&typeof n.body=="string"&&typeof n.migrated=="boolean"&&gn(n.proposedCopy)&&Ln(n.sections,n.warnings)}function mn(n){return n===null||h(n)&&I(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)&&I(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]*)$/,G=/^[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 Hn(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)}]`,c=t.object(r,s);if(c===null)return;if(c._type!=="block"){t.fail(s,`is a ${JSON.stringify(c._type)}; only text is supported in rich text so far`);return}let l=Pn(c,s,t),u=c.listItem,p=c.style??"normal",d;if(u==="bullet"||u==="number"){let f=typeof c.level=="number"&&c.level>1?c.level:1;d=`${" ".repeat(f-1)}${u==="bullet"?"-":"1."} ${l}`}else if(p==="h2")d=`## ${l}`;else if(p==="h3")d=`### ${l}`;else if(p==="blockquote")d=`> ${l}`;else if(p==="normal")d=l;else{t.fail(`${s}.style`,`is ${JSON.stringify(p)}, which the schema does not offer`);return}let y=u==="bullet"||u==="number";o.length>0&&o.push(y&&i?`
|
|
2
2
|
`:`
|
|
3
3
|
|
|
4
|
-
`),o.push(
|
|
4
|
+
`),o.push(d),i=y}),o.join("")}var Nn={strong:"**",em:"*",code:"`"};function Pn(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 c=a;if(c._type!=="span"||typeof c.text!="string")return t.fail(`${e}.children[${String(s)}]`,"is not a text span"),"";let l=c.text,u=Array.isArray(c.marks)?c.marks:[];if(!t.dense(u,`${e}.children[${String(s)}].marks`))return"";let p=null;for(let d of u){if(typeof d!="string")continue;let y=Nn[d];y!==void 0?l=`${y}${l}${y}`:o.has(d)?p=o.get(d)??null:t.fail(`${e}.children[${String(s)}].marks`,`names ${JSON.stringify(d)}, which is neither a style nor a link`)}return p===null?l:`[${l}](${p})`}).join(""):""}function Sn(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"),C=t.copy(a.lead,"hero.lead"),b=t.action(a.primaryAction,"hero.primaryAction"),An=t.action(a.secondaryAction,"hero.secondaryAction");g!==null&&(r={heading:g,subline:m,intro:C,image:f[0]??null,inset:f[1]??null,cta:b,secondaryCta:An})}let s=[],c=[],l="",u=Sn(o.campaign,e.now);if(u==="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 C=on(f.body,"campaign.body",t);C===""&&t.fail("campaign.body","is empty; a shown campaign needs its text"),f.bodyCopySource==="proposed"&&t.proposed.push({where:"campaign.body",text:C});let b=t.action(f.action,"campaign.action");b!==null&&c.push({where:"campaign.action.href",href:b.href}),g!==null&&(l=`# ${Y(g)}
|
|
5
5
|
|
|
6
|
-
${S}`),a.push({kind:"campaign",action:h,images:C})}}let u=[],c=o.blocks??[];Array.isArray(c)?t.dense(c,"blocks")&&c.forEach((d,g)=>{let C=t.object(d,`blocks[${String(g)}]`);if(C===null)return;let S=J("blocks",C,g),h=cn(C,S,t);h!==null&&(l.push(...pn(h,C,S)),h.kind==="locations"&&h.anchor!==null&&(u.includes(h.anchor)&&t.fail(`${S}.jumpLink`,`repeats "${h.anchor}", already used by another section`),u.push(h.anchor)),a.push(h))}):t.fail("blocks","is not a list");let f=[];i?.cta&&f.push({where:"hero.primaryAction.href",href:i.cta.href}),i?.secondaryCta&&f.push({where:"hero.secondaryAction.href",href:i.secondaryCta.href}),f.push(...l);for(let{where:d,href:g}of f)g.startsWith("#")&&!u.includes(g.slice(1))&&t.fail(d,`jumps to ${g}, which no section on the page is named`);if(t.problems.length>0)throw new m(s,t.problems);return{composition:{intro:null,photo:null,hero:i,blocks:a},body:p,campaign:y,proposedCopy:t.proposed}}function pn(e,n,t){switch(e.kind){case"feature_stories":{let o=Array.isArray(n.stories)?n.stories:[];return e.items.map((s,i)=>({where:`${J(`${t}.stories`,o[i]??{},i)}.action.href`,href:s.action.href}))}case"accent_band":return e.action===null?[]:[{where:`${t}.action.href`,href:e.action.href}];case"cta":return[{where:`${t}.action.href`,href:e.link.href}];default:return[]}}function cn(e,n,t){switch(e._type){case"featureStoriesBlock":{let o=t.requiredCopy(e.heading,`${n}.heading`),s=t.copy(e.tail,`${n}.tail`),i=e.stories;if(!Array.isArray(i)||i.length===0)return t.fail(`${n}.stories`,"has no stories");if(!t.dense(i,`${n}.stories`))return null;let r=[];return i.forEach((a,l)=>{let p=t.object(a,`${n}.stories[${String(l)}]`);if(p===null)return;let y=J(`${n}.stories`,p,l),u=t.requiredCopy(p.heading,`${y}.heading`),c=t.requiredCopy(p.body,`${y}.body`),f=t.requiredAction(p.action,`${y}.action`),d=t.photo(p.photo,`${y}.photo`),g=p.layout??"wide";if(!q.includes(g)){t.fail(`${y}.layout`,`is ${JSON.stringify(g)}, not wide, tall, round or free`);return}let C=p.onCard??!1;if(typeof C!="boolean"){t.fail(`${y}.onCard`,"is not on or off");return}u===null||c===null||f===null||r.push({heading:u,body:c,action:f,image:d,shape:g,card:C})}),o===null?null:{kind:"feature_stories",heading:o,tail:s,items:r}}case"surfaceCardBlock":{let o=t.requiredCopy(e.heading,`${n}.heading`),s=t.copy(e.body,`${n}.body`),i=t.requiredAction(e.action,`${n}.action`);return o===null||i===null?null:{kind:"cta",heading:O(o),body:s===null?null:O(s),link:{label:O(i.label),href:i.href}}}case"accentBandBlock":{let o=t.requiredCopy(e.heading,`${n}.heading`),s=t.requiredCopy(e.body,`${n}.body`),i=t.action(e.action,`${n}.action`),r=t.photo(e.photo,`${n}.photo`);return o===null||s===null?null:{kind:"accent_band",heading:o,body:s,action:i,image:r}}case"locationsBlock":{let o=e.jumpLink,s=null;o!=null&&o!==""&&(typeof o!="string"||!H.test(o)?t.fail(`${n}.jumpLink`,`is ${JSON.stringify(o)}, not lowercase words joined by hyphens`):s=o);let i=t.requiredCopy(e.heading,`${n}.heading`),r=t.copy(e.tail,`${n}.tail`),a=t.photo(e.photo,`${n}.photo`);return i===null?null:{kind:"locations",anchor:s,heading:i,tail:r,image:a}}default:return t.fail(`${n}._type`,`is ${JSON.stringify(e._type)}, not a section type this reader knows`)}}function x(e){let n=new R,t=n.object(e,"page");if(t===null)throw new m("page",n.problems);let o=typeof t._id=="string"?t._id:"page";t._type!=="page"&&n.fail("_type",`is ${JSON.stringify(t._type)}, not page`);let s=n.optionalString(t.title,"title");s===null&&n.fail("title","is missing"),t.titleCopySource==="proposed"&&s!==null&&n.proposed.push({where:"title",text:s});let i=t.slug,r=typeof i?.current=="string"&&i.current!==""?i.current:null;r===null&&n.fail("slug.current","is missing");let a=n.copy(t.lead,"lead"),l=n.photo(t.photo,"photo"),p=U(t.body,"body",n);if(t.bodyCopySource==="proposed"&&n.proposed.push({where:"body",text:p}),n.problems.length>0||s===null||r===null)throw new m(o,n.problems);return{slug:r,title:s,composition:{intro:a===null?null:O(a),photo:l,hero:null,blocks:[]},body:p,migrated:t.migrated===!0,proposedCopy:n.proposed}}function F(e){let n=new R,t=n.object(e,"siteSettings");if(t===null)throw new m(E,n.problems);let o=n.optionalString(t.title,"title");o===null&&n.fail("title","is missing; a site needs its name");let s=n.optionalString(t.description,"description"),i=t.contact===void 0?{}:n.object(t.contact,"contact")??{},r=n.optionalString(i.email,"contact.email"),a=n.optionalString(i.phone,"contact.phone"),l=[],p=t.social??[];if(Array.isArray(p)?n.dense(p,"social")&&p.forEach((y,u)=>{let c=n.object(y,`social[${String(u)}]`);if(c===null)return;let f=n.optionalString(c.network,`social[${String(u)}].network`),d=n.optionalString(c.url,`social[${String(u)}].url`);if(f===null||d===null||!/^https?:\/\//.test(d)){n.fail(`social[${String(u)}]`,"needs a network and a web address");return}l.push({network:f,url:d})}):n.fail("social","is not a list"),n.problems.length>0||o===null)throw new m(E,n.problems);return{name:o,description:s,contact:{email:r,phone:a},social:l}}var P="*[_id == $id][0]",G='*[_type == "page" && defined(slug.current)]|order(slug.current asc)',Y='*[_type == "page" && slug.current == $slug][0]';function un(e){return{home:async({now:n})=>{let t=await e.query(P,{params:{id:_}});return t==null?null:L(t,{now:n})},pages:async()=>{let n=await e.query(G);if(!Array.isArray(n))throw new m("page",["the page query did not return a list"]);if(!b(n))throw new m("page",["the page query contains missing entries"]);return n.map(t=>x(t))},pageBySlug:async n=>{let t=await e.query(Y,{params:{slug:n}});return t==null?null:x(t)},siteSettings:async()=>{let n=await e.query(P,{params:{id:E}});return n==null?null:F(n)}}}function z(e,n,t,o){if(!o(n))throw new TypeError("Invalid CMS content fallback");return e==null?{data:n,fallbackFields:["$"]}:{data:t(e),fallbackFields:[]}}function dn(e){if(!(e instanceof Date)||!Number.isFinite(e.getTime()))throw new TypeError("Invalid CMS campaign date");let n=e.getTime();return I({name:"homePage.v1",query:P,params:{id:_},dependencies:{types:["homePage"],ids:[_]},resolve:(t,o)=>z(t,o,s=>L(s,{now:new Date(n)}),X)})}function yn(e){if(typeof e!="string"||e==="")throw new TypeError("Invalid CMS page slug");return I({name:"page.v1",query:Y,params:{slug:e},dependencies:{types:["page"]},resolve:(n,t)=>z(n,t,x,Q)})}function fn(){return I({name:"pages.v1",query:G,params:{},dependencies:{types:["page"]},resolve:(e,n)=>z(e,n,t=>{if(!Array.isArray(t))throw new m("page",["the page query did not return a list"]);if(!b(t))throw new m("page",["the page query contains missing entries"]);return t.map(o=>x(o))},t=>b(t)&&t.every(o=>o!==null&&Q(o)))})}function gn(){return I({name:"siteSettings.v1",query:P,params:{id:E},dependencies:{types:["siteSettings"],ids:[E]},resolve:(e,n)=>z(e,n,F,v)})}export{G as CONTENT_PAGES_QUERY,Y as CONTENT_PAGE_BY_SLUG_QUERY,P as HOME_PAGE_DOCUMENT_QUERY,B as MALFORMED_CONTENT,m as MalformedContentError,M as READER_ACTION_HREF,_ as READER_HOME_PAGE_ID,H as READER_JUMP_LINK,N as READER_PHOTO_SLUG,E as READER_SITE_SETTINGS_ID,q as READER_STORY_LAYOUTS,nn as campaignState,yn as contentPageQuery,fn as contentPagesQuery,un as createSiteContentReader,dn as homeContentQuery,x as parseContentPage,L as parseHomePage,F as parseSiteSettings,sn as portableTextToMarkdown,gn as siteSettingsQuery};
|
|
6
|
+
${C}`),s.push({kind:"campaign",action:b,images:m})}}let p=[],d=o.blocks??[];Array.isArray(d)?t.dense(d,"blocks")&&d.forEach((f,g)=>{let m=t.object(f,`blocks[${String(g)}]`);if(m===null)return;let C=P("blocks",m,g),b=bn(m,C,t);b!==null&&(c.push(...wn(b,m,C)),b.kind==="locations"&&b.anchor!==null&&(p.includes(b.anchor)&&t.fail(`${C}.jumpLink`,`repeats "${b.anchor}", already used by another section`),p.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(...c);for(let{where:f,href:g}of y)g.startsWith("#")&&!p.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:u,proposedCopy:t.proposed}}function wn(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"||!G.test(o)?t.fail(`${e}.jumpLink`,`is ${JSON.stringify(o)}, not lowercase words joined by hyphens`):o}function bn(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,c)=>{let l=t.object(s,`${e}.stories[${String(c)}]`);if(l===null)return;let u=P(`${e}.stories`,l,c),p=t.requiredCopy(l.heading,`${u}.heading`),d=t.requiredCopy(l.body,`${u}.body`),y=t.requiredAction(l.action,`${u}.action`),f=t.photo(l.photo,`${u}.photo`),g=l.layout??"wide";if(!Z.includes(g)){t.fail(`${u}.layout`,`is ${JSON.stringify(g)}, not wide, tall, round or free`);return}let m=l.onCard??!1;if(typeof m!="boolean"){t.fail(`${u}.onCard`,"is not on or off");return}p===null||d===null||y===null||a.push({heading:p,body:d,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 c=t.optionalString(i.caption,`${e}.caption`),l=null;if(i.hotspot!==void 0&&i.hotspot!==null){let u=t.object(i.hotspot,`${e}.hotspot`),p=u?.x,d=u?.y;typeof p=="number"&&typeof d=="number"&&p>=0&&p<=1&&d>=0&&d<=1?l={x:p,y:d}:u!==null&&t.fail(`${e}.hotspot`,"is not a point inside the image")}return{asset:a,alt:s,caption:c,hotspot:l}}function Dn(n,e,t,o){switch(n._type){case"featureStoriesBlock":case"surfaceCardBlock":case"accentBandBlock":case"locationsBlock":{let i=bn(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`),c=t.action(n.action,`${e}.action`),l=en(n.photo,`${e}.photo`,t,o),u=V(n,e,E,$.Split,o);return r===null||s===null?null:{kind:"text_media",anchor:i,layout:u,heading:r,tail:a,body:s,action:c,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`),c=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 u=[];return l.forEach((p,d)=>{let y=t.object(p,`${e}.items[${String(d)}]`);if(y===null)return;let f=P(`${e}.items`,y,d);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&&u.push({question:g,answer:m})}),r===null?null:{kind:"faq",anchor:i,layout:c,heading:r,tail:a,intro:s,items:u}}case"galleryBlock":{let i=U(n,e,t),r=t.copy(n.heading,`${e}.heading`),a=V(n,e,q,$.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 c=s.flatMap((l,u)=>{let p=en(l,P(`${e}.photos`,typeof l=="object"&&l!==null?l:{},u),t,o);return p===null?[]:[p]});return c.length===0?(o.push({code:_.emptySkipped,where:e}),null):{kind:"gallery",anchor:i,layout:a,heading:r,images:c}}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)},c=s("showEmail"),l=s("showPhone"),u=t.action(n.action,`${e}.action`),p=en(n.photo,`${e}.photo`,t,o),d=V(n,e,E,$.Split,o);return r===null?null:!c&&!l&&a===null&&u===null?(o.push({code:_.emptySkipped,where:e}),null):{kind:"contact",anchor:i,layout:d,heading:r,body:a,showEmail:c,showPhone:l,action:u,image:p}}default:return o.push({code:_.unknownType,where:`${e}._type`}),null}}function jn(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 wn(n,e,t)}}function qn(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 c=e.object(a,`sections[${String(s)}]`);if(c===null)return;let l=P("sections",c,s),u=Dn(c,l,e,o);if(u===null)return;r.push(...jn(u,c,l));let p="anchor"in u?u.anchor:null;p!==null&&(i.includes(p)&&e.fail(`${l}.jumpLink`,`repeats "${p}", already used by another section`),i.push(p)),t.push(u)});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"),c=e.photo(t.photo,"photo"),l=on(t.body,"body",e);t.bodyCopySource==="proposed"&&e.proposed.push({where:"body",text:l});let u=t.sections===void 0||t.sections===null?null:qn(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:c,hero:null,blocks:[]},body:l,migrated:t.migrated===!0,proposedCopy:e.proposed,...u===null?{}:u}}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"),c=[],l=t.social??[];if(Array.isArray(l)?e.dense(l,"social")&&l.forEach((u,p)=>{let d=e.object(u,`social[${String(p)}]`);if(d===null)return;let y=e.optionalString(d.network,`social[${String(p)}].network`),f=e.optionalString(d.url,`social[${String(p)}].url`);if(y===null||f===null||!/^https?:\/\//.test(f)){e.fail(`social[${String(p)}]`,"needs a network and a web address");return}c.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:c}}var W="*[_id == $id][0]",an='*[_type == "page" && defined(slug.current)]|order(slug.current asc)',ln='*[_type == "page" && slug.current == $slug][0]';function Mn(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 Gn(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)}),hn)})}function Un(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 Yn(){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 Bn(){return A({name:"siteSettings.v1",query:W,params:{id:H},dependencies:{types:["siteSettings"],ids:[H]},resolve:(n,e)=>X(n,e,sn,mn)})}var In=["columns","rows"],_n=36,Cn="siteHero.layout.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 Wn(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=Wn(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 un(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=new Set;for(let r of n){if(!r||typeof r!="object"||Array.isArray(r))return{ok:!1,error:"Enter a key and text for each tagline."};let a=r,s=Object.hasOwn(a,"key")?a.key:void 0;if(typeof s!="string"||!/^[a-z][a-z0-9_-]{0,31}$/.test(s))return{ok:!1,error:"Use a lowercase key of 1 to 32 letters, numbers, short dashes or underscores, starting with a letter."};if(i.has(s))return{ok:!1,error:"Use each tagline key only once."};let c=cn({...D,fields:[t]},a);if(!c.ok)return{ok:!1,error:c.errors.text??"Invalid tagline."};i.add(s),o.push({key:s,text:c.value.text??""})}return{ok:!0,value:o}}function kn(n){return In.some(e=>n===e)}function Tn(n,e){let t=cn(D,e),o=un(e.taglines??[]);if(!t.ok||!o.ok||e.layout!==void 0&&!kn(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 d=a.ok?a.value[p.name]:r[p.name];typeof d=="string"&&(p.name==="heading"||p.name==="intro")&&(i[p.name]=d.trim())}let c=Object.hasOwn(r,"layout")?r.layout:void 0,l=[];kn(c)?i.layout=c:(i.layout="columns",s.push("layout"),l.push(Cn));let u=un(Object.hasOwn(r,"taglines")?r.taglines:void 0);return u.ok?i.taglines=u.value:s.push("taglines"),{data:i,fallbackFields:s.length===D.fields.length+2?["$"]:s,...l.length>0?{warnings:l}:{}}}function Fn(){return A({name:"siteHero.v1",query:'*[_id == $id && _type == "siteHero"][0]{heading,intro,layout,taglines}',params:{id:"siteHero"},dependencies:{types:["siteHero"],ids:["siteHero"]},resolve:Tn})}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,G as READER_JUMP_LINK,J as READER_PHOTO_SLUG,On 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,Cn as SITE_HERO_LAYOUT_WARNING,_n as SITE_HERO_TAGLINE_MAX_LENGTH,E as SPLIT_LAYOUTS,q as STAGGER_ROW_LAYOUTS,Sn as campaignState,Un as contentPageQuery,Yn as contentPagesQuery,Mn as createSiteContentReader,Gn as homeContentQuery,B as parseContentPage,rn as parseHomePage,Tn as parseSiteHero,sn as parseSiteSettings,Hn as portableTextToMarkdown,Fn as siteHeroQuery,Bn as siteSettingsQuery,un as validateSiteHeroTaglines};
|
|
7
7
|
//# sourceMappingURL=site-content.mjs.map
|