UNPKG

0x1

Version:

0x1: Lightning-fast web framework for JavaScript/TypeScript with zero overhead and maximum performance, powered by Bun

24 lines (23 loc) 12.2 kB
var R={title:{template:"%s | 0x1 App",default:"0x1 App"},description:"Built with 0x1 - the ultra-minimal framework",viewport:{width:"device-width",initialScale:1,maximumScale:5,userScalable:!0,shrinkToFit:!1},themeColor:"#7c3aed",colorScheme:"light dark",robots:{index:!0,follow:!0,"max-image-preview":"large","max-snippet":-1,"max-video-preview":-1},openGraph:{type:"website",locale:"en_US",siteName:"0x1 App"},twitter:{card:"summary_large_image"},icons:{icon:"/favicon.svg",apple:"/icons/apple-touch-icon.png"},manifest:"/manifest.json"};function q(K,J=R){return{...J,...K,openGraph:{...J.openGraph||{},...K.openGraph||{}},twitter:K.twitter?{...J.twitter||{},...K.twitter,card:K.twitter.card||J.twitter?.card||"summary"}:J.twitter,icons:{...J.icons||{},...K.icons||{}},viewport:typeof K.viewport==="object"&&typeof J.viewport==="object"?{...J.viewport,...K.viewport}:K.viewport||J.viewport,appleWebApp:{...J.appleWebApp||{},...K.appleWebApp||{}},verification:{...J.verification||{},...K.verification||{}},analytics:{...J.analytics||{},...K.analytics||{}},alternates:{...J.alternates||{},...K.alternates||{}},appLinks:{...J.appLinks||{},...K.appLinks||{}},other:{...J.other||{},...K.other||{}}}}function F(K,J){let G=K.title;if(!G)return J||"Untitled";if(typeof G==="string")return G;let{template:Q,default:W,absolute:X}=G;if(X)return X;if(J&&Q)return Q.replace("%s",J);return J||W||"Untitled"}function V(K){let J={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#039;"};return K.replace(/[&<>"']/g,(G)=>J[G])}function x(K){let J=[];if(K.description)J.push(`<meta name="description" content="${V(K.description)}">`);if(K.keywords){let G=Array.isArray(K.keywords)?K.keywords.join(", "):K.keywords;J.push(`<meta name="keywords" content="${V(G)}">`)}if(K.viewport)if(typeof K.viewport==="string")J.push(`<meta name="viewport" content="${V(K.viewport)}">`);else{let G=[],Q=K.viewport;if(Q.width)G.push(`width=${Q.width}`);if(Q.height)G.push(`height=${Q.height}`);if(Q.initialScale)G.push(`initial-scale=${Q.initialScale}`);if(Q.minimumScale)G.push(`minimum-scale=${Q.minimumScale}`);if(Q.maximumScale)G.push(`maximum-scale=${Q.maximumScale}`);if(Q.userScalable!==void 0)G.push(`user-scalable=${Q.userScalable?"yes":"no"}`);if(Q.shrinkToFit!==void 0)G.push(`shrink-to-fit=${Q.shrinkToFit?"yes":"no"}`);if(Q.viewportFit)G.push(`viewport-fit=${Q.viewportFit}`);if(G.length>0)J.push(`<meta name="viewport" content="${G.join(", ")}">`)}if(K.themeColor)if(typeof K.themeColor==="string")J.push(`<meta name="theme-color" content="${V(K.themeColor)}">`);else K.themeColor.forEach((G)=>{let Q=G.media?` media="${V(G.media)}"`:"";J.push(`<meta name="theme-color" content="${V(G.color)}"${Q}>`)});if(K.colorScheme)J.push(`<meta name="color-scheme" content="${V(K.colorScheme)}">`);if(K.robots)if(typeof K.robots==="string")J.push(`<meta name="robots" content="${V(K.robots)}">`);else{let G=[],Q=K.robots;if(Q.index!==void 0)G.push(Q.index?"index":"noindex");if(Q.follow!==void 0)G.push(Q.follow?"follow":"nofollow");if(Q.noarchive)G.push("noarchive");if(Q.nosnippet)G.push("nosnippet");if(Q.noimageindex)G.push("noimageindex");if(Q.nocache)G.push("nocache");if(Q.notranslate)G.push("notranslate");if(Q.indexifembedded)G.push("indexifembedded");if(Q.nositelinkssearchbox)G.push("nositelinkssearchbox");if(Q.unavailable_after)G.push(`unavailable_after:${Q.unavailable_after}`);if(Q["max-video-preview"]!==void 0)G.push(`max-video-preview:${Q["max-video-preview"]}`);if(Q["max-image-preview"])G.push(`max-image-preview:${Q["max-image-preview"]}`);if(Q["max-snippet"]!==void 0)G.push(`max-snippet:${Q["max-snippet"]}`);if(G.length>0)J.push(`<meta name="robots" content="${G.join(", ")}">`)}if(K.openGraph){let G=K.openGraph;if(G.title)J.push(`<meta property="og:title" content="${V(G.title)}">`);if(G.description)J.push(`<meta property="og:description" content="${V(G.description)}">`);if(G.url)J.push(`<meta property="og:url" content="${V(G.url)}">`);if(G.siteName)J.push(`<meta property="og:site_name" content="${V(G.siteName)}">`);if(G.locale)J.push(`<meta property="og:locale" content="${V(G.locale)}">`);if(G.type)J.push(`<meta property="og:type" content="${V(G.type)}">`);if(G.images)(Array.isArray(G.images)?G.images:[G.images]).forEach((W)=>{if(J.push(`<meta property="og:image" content="${V(W.url)}">`),W.width)J.push(`<meta property="og:image:width" content="${W.width}">`);if(W.height)J.push(`<meta property="og:image:height" content="${W.height}">`);if(W.alt)J.push(`<meta property="og:image:alt" content="${V(W.alt)}">`);if(W.type)J.push(`<meta property="og:image:type" content="${V(W.type)}">`)})}if(K.twitter){let G=K.twitter;if(J.push(`<meta name="twitter:card" content="${V(G.card)}">`),G.site)J.push(`<meta name="twitter:site" content="${V(G.site)}">`);if(G.creator)J.push(`<meta name="twitter:creator" content="${V(G.creator)}">`);if(G.title)J.push(`<meta name="twitter:title" content="${V(G.title)}">`);if(G.description)J.push(`<meta name="twitter:description" content="${V(G.description)}">`);if(G.image){if(typeof G.image==="string")J.push(`<meta name="twitter:image" content="${V(G.image)}">`);else if(J.push(`<meta name="twitter:image" content="${V(G.image.url)}">`),G.image.alt)J.push(`<meta name="twitter:image:alt" content="${V(G.image.alt)}">`)}}if(K.appleWebApp){let G=K.appleWebApp;if(G.capable)J.push('<meta name="apple-mobile-web-app-capable" content="yes">');if(G.title)J.push(`<meta name="apple-mobile-web-app-title" content="${V(G.title)}">`);if(G.statusBarStyle)J.push(`<meta name="apple-mobile-web-app-status-bar-style" content="${V(G.statusBarStyle)}">`)}if(K.formatDetection){let G=K.formatDetection,Q=[];if(G.telephone!==void 0)Q.push(`telephone=${G.telephone?"yes":"no"}`);if(G.email!==void 0)Q.push(`email=${G.email?"yes":"no"}`);if(G.address!==void 0)Q.push(`address=${G.address?"yes":"no"}`);if(Q.length>0)J.push(`<meta name="format-detection" content="${Q.join(", ")}">`)}if(K.verification){let G=K.verification;if(G.google)J.push(`<meta name="google-site-verification" content="${V(G.google)}">`);if(G.yandex)J.push(`<meta name="yandex-verification" content="${V(G.yandex)}">`);if(G.yahoo)J.push(`<meta name="y_key" content="${V(G.yahoo)}">`);if(G.other)Object.entries(G.other).forEach(([Q,W])=>{J.push(`<meta name="${V(Q)}" content="${V(W)}">`)})}if(K.authors)K.authors.forEach((G)=>{if(G.name)J.push(`<meta name="author" content="${V(G.name)}">`)});if(K.creator)J.push(`<meta name="creator" content="${V(K.creator)}">`);if(K.publisher)J.push(`<meta name="publisher" content="${V(K.publisher)}">`);if(K.other)Object.entries(K.other).forEach(([G,Q])=>{J.push(`<meta name="${V(G)}" content="${V(String(Q))}">`)});return J.length>0?` `+J.join(` `):""}function E(K){let J=[];if(K.manifest)J.push(`<link rel="manifest" href="${V(K.manifest)}">`);if(K.icons){let G=K.icons;if(G.icon)(Array.isArray(G.icon)?G.icon:[G.icon]).forEach((W)=>{if(typeof W==="string")J.push(`<link rel="icon" href="${V(W)}">`);else{let X=W.type?` type="${V(W.type)}"`:"",Y=W.sizes?` sizes="${V(W.sizes)}"`:"";J.push(`<link rel="icon" href="${V(W.url)}"${X}${Y}>`)}});if(G.shortcut)(Array.isArray(G.shortcut)?G.shortcut:[G.shortcut]).forEach((W)=>{if(typeof W==="string")J.push(`<link rel="shortcut icon" href="${V(W)}">`);else{let X=W.type?` type="${V(W.type)}"`:"",Y=W.sizes?` sizes="${V(W.sizes)}"`:"";J.push(`<link rel="shortcut icon" href="${V(W.url)}"${X}${Y}>`)}});if(G.apple)(Array.isArray(G.apple)?G.apple:[G.apple]).forEach((W)=>{if(typeof W==="string")J.push(`<link rel="apple-touch-icon" href="${V(W)}">`);else{let X=W.sizes?` sizes="${V(W.sizes)}"`:"";J.push(`<link rel="apple-touch-icon" href="${V(W.url)}"${X}>`)}});if(G.other)G.other.forEach((Q)=>{let W=Q.type?` type="${V(Q.type)}"`:"",X=Q.sizes?` sizes="${V(Q.sizes)}"`:"";J.push(`<link rel="${V(Q.rel)}" href="${V(Q.url)}"${W}${X}>`)})}if(K.alternates?.canonical){let G=typeof K.alternates.canonical==="string"?K.alternates.canonical:K.alternates.canonical.toString();J.push(`<link rel="canonical" href="${V(G)}">`)}if(K.alternates?.languages)if(Array.isArray(K.alternates.languages))K.alternates.languages.forEach((G)=>{J.push(`<link rel="alternate" hreflang="${V(G.hrefLang)}" href="${V(G.href)}">`)});else Object.entries(K.alternates.languages).forEach(([G,Q])=>{let W=typeof Q==="string"?Q:Q.toString();J.push(`<link rel="alternate" hreflang="${V(G)}" href="${V(W)}">`)});return J.length>0?` `+J.join(` `):""}function C(K){if(!K.analytics)return"";let J=[],G=K.analytics;if(G.googleAnalytics)J.push(` <script async src="https://www.googletagmanager.com/gtag/js?id=${V(G.googleAnalytics)}"></script> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', '${V(G.googleAnalytics)}'); </script>`);if(G.googleTagManager)J.push(` <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); })(window,document,'script','dataLayer','${V(G.googleTagManager)}');</script>`);if(G.plausible){let Q=G.plausible.domain,W=G.plausible.trackLocalhost?' data-include-localhost="true"':"";J.push(` <script defer data-domain="${V(Q)}"${W} src="https://plausible.io/js/script.js"></script>`)}if(G.fathom){let Q=G.fathom.siteId,W=G.fathom.honorDNT?' honor-dnt="true"':"";J.push(` <script src="https://cdn.usefathom.com/script.js" data-site="${V(Q)}"${W} defer></script>`)}if(G.custom)G.custom.forEach((Q)=>{let W=Q.async?" async":"",X=Q.defer?" defer":"";J.push(` <script src="${V(Q.src)}"${W}${X}></script>`)});return J.join("")}function O(K,J){let G=F(K,J),Q=x(K),W=E(K),X=C(K);return` <meta charset="utf-8"> <title>${V(G)}</title> ${Q}${W}${X}`.trim()}var I={...R};function A(K){I=q(K,R)}function y(){return I}function U(K,J){if(typeof document==="undefined")return;let G=q(K,I),Q=O(G,J),W=document.head;W.querySelectorAll("[data-0x1-meta]").forEach((Z)=>Z.remove());let Y=document.createElement("div");Y.innerHTML=Q,Array.from(Y.children).forEach((Z)=>{let N=Z.cloneNode(!0);N.setAttribute("data-0x1-meta","true"),W.appendChild(N)});let B=Y.querySelector("title");if(B)document.title=B.textContent||""}function P(K){let{title:J,metadata:G={},children:Q}=K;if(typeof document!=="undefined")setTimeout(()=>{if(U(G,J),Q)D(Q)},0);return null}function D(K){if(!K||typeof document==="undefined")return;(Array.isArray(K)?K:[K]).forEach((G)=>{if(!G||typeof G!=="object")return;if(G.type&&typeof G.type==="string"){let Q=L(G);if(Q)Q.setAttribute("data-0x1-meta","true"),document.head.appendChild(Q)}})}function L(K){if(!K.type||typeof K.type!=="string")return null;let J=document.createElement(K.type);if(K.props)Object.entries(K.props).forEach(([G,Q])=>{if(G==="children"){if(typeof Q==="string")J.textContent=Q}else if(G==="dangerouslySetInnerHTML"&&Q&&typeof Q==="object"&&"__html"in Q)J.innerHTML=Q.__html;else if(Q!==null&&Q!==void 0)J.setAttribute(G,String(Q))});return J}function M(K,J){if(typeof document!=="undefined")setTimeout(()=>{U(K,J)},0)}function T(K){let{title:J,description:G,keywords:Q,image:W,url:X,type:Y="website",publishedTime:B,modifiedTime:Z,authors:N,section:_,tags:z}=K,$={};if(J)$.title=J;if(G)$.description=G;if(Q)$.keywords=Q;return $.openGraph={type:Y,title:J,description:G,url:X,...W&&{images:[{url:W,width:1200,height:630,alt:J||"Image"}]},...B&&{publishedTime:B},...Z&&{modifiedTime:Z},...N&&{authors:N},..._&&{section:_},...z&&{tags:z}},$.twitter={card:"summary_large_image",title:J,description:G,...W&&{image:W}},$}function w(K,J){let G=q(K,I);return O(G,J)}function v(){if(typeof document!=="undefined"){if(!document.querySelector("meta[charset]")){let K=document.createElement("meta");K.setAttribute("charset","utf-8"),K.setAttribute("data-0x1-meta","true"),document.head.insertBefore(K,document.head.firstChild)}}}export{M as useMetadata,U as updateDocumentHead,A as setGlobalMetadata,v as initializeHeadManagement,y as getGlobalMetadata,w as generateServerHead,T as generateMetadata,P as Head};