@expofp/floorplan
Version:
Interactive floor plan library for expos and events
2 lines (1 loc) • 1.5 kB
JavaScript
export const MAX_DESCRIPTION=160;export function truncateAtWord(e,t){if(e.length<=t)return e;const i=e.slice(0,t-1),n=i.lastIndexOf(" ");return(n>0?i.slice(0,n):i).replace(/[\s,.:;–—|-]+$/u,"")+"\u2026"}const c=/^[a-z]{2,3}(?:-[a-z0-9]{2,8})*$/iu;export function buildEventHead(e){const t=e.title.trim(),i=e.subtitle.trim(),n=t?`${t} interactive floor plan`:"Interactive event floor plan",o=e.hideExhibitors?0:e.exhibitors.length,a=o>0?`Browse ${o} exhibitors, find booths and get directions.`:"Find booths and get directions.",l=truncateAtWord(`${n}${i?`: ${i}`:""}. ${a}`,160),r=e.locale.trim();return{description:l,heading:t||i||void 0,lang:c.test(r)?r:void 0}}const s=["position: absolute","width: 1px","height: 1px","margin: -1px","padding: 0","overflow: hidden","clip: rect(0, 0, 0, 0)","white-space: nowrap","border: 0"].join("; ");export function applyEventHead(e,t,i){if(!e.querySelector('meta[name="description"]')){const n=e.createElement("meta");n.name="description",n.content=t.description,e.head.appendChild(n)}if(!e.querySelector('link[rel="canonical"]')){const n=e.createElement("link");n.rel="canonical",n.href=i,e.head.appendChild(n)}if(t.heading&&!e.querySelector("h1")){const n=e.createElement("h1");n.textContent=t.heading,n.style.cssText=s,e.body.prepend(n)}t.lang&&(e.documentElement.lang=t.lang)}export function markNotIndexable(e){if(e.querySelector('meta[name="robots"]'))return;const t=e.createElement("meta");t.name="robots",t.content="noindex",e.head.appendChild(t)}