// nsite template — renders the sovereign published page locally from the // merchant's real nsite data. This is the design surface for the generated // customer pages: changes here are what the product's generator adopts. import {mountLogo} from './ds/logo.js'; const app=document.querySelector('#app'); const base=location.pathname.split('/').slice(0,-1).join('/'); const npub=new URLSearchParams(location.search).get('npub')?.trim()||''; const esc=value=>String(value??'').replace(/[&<>"']/g,char=>({'&':'&','<':'<','>':'>','"':'"',"'":'''}[char])); const qr=text=>`${base}/api/qr?text=${encodeURIComponent(text)}`; function fail(message){ app.innerHTML=`
⌁

${esc(message)}

Use /site?npub=npub1…
`; } function fact(term,value,href){ return `
${esc(term)}
${href?`${esc(value)} ↗`:esc(value)}
`; } function render(data){ const merchant=data.merchant,about=data.about,hero=data.images[0]||''; document.title=`${merchant.name} — Just Works`; app.innerHTML=`
${hero?'
':''}
${esc([merchant.category,merchant.area].filter(Boolean).join(' · ')||'Merchant')}

${esc(merchant.name)}

${about?`

${esc(about)}

`:''}
${data.sources.length?`

${data.products.length?'This week':'What’s on'}

What’s on.

${data.sources.map((source,index)=>``).join('')}
`:''}

The place

A local place called ${esc(merchant.name)}.

${esc(about||`${merchant.name} keeps a page on the open web — photos, links and the latest info, signed by the owner.`)}

${data.images[1]?`
`:''}
${data.products.length?``:''} ${data.images.length>1?``:''} ${(merchant.address||merchant.hours||merchant.phone||merchant.website)?`

Visit

Find us.

${merchant.address?fact('Address',merchant.address):''}${merchant.hours?fact('Hours',merchant.hours):''}${merchant.phone?fact('Phone',merchant.phone,`tel:${esc(merchant.phone)}`):''}${merchant.website?fact('Website',merchant.website.replace(/^https?:\/\//,''),merchant.website):''}${merchant.rating?fact('Rating',`★ ${merchant.rating} / 5`):''}
`:''}

Stay connected

Keep the direct connection.

This page is signed by the merchant and published to Nostr relays and Blossom storage. If every platform disappears, this page still resolves.

Technical ownership details

Who owns this page.

${fact('Signed by',merchant.npub)}${data.gateway?fact('Nsite gateway',data.gateway.replace(/^https?:\/\//,''),data.gateway):''}${fact('Published via','Nostr relays · Blossom storage')}${fact('Stable page',data.links.page)}
`; document.querySelectorAll('[data-logo]').forEach(host=>mountLogo(host,{icon:true})); } if(!npub)fail('Add the merchant npub.'); else fetch(`${base}/api/nsite-page?npub=${encodeURIComponent(npub)}`,{cache:'no-store'}) .then(async response=>{const data=await response.json();if(!response.ok)throw new Error(data.error||'Site unavailable');render(data)}) .catch(error=>fail(error.message));