import{readFileSync as S}from"fs";import{join as d}from"path";import{isLocalLink as a}from"../../../utils/path/is-local-link.js";import{copyStaticFile as g}from"../../utils/fs.js";async function b(r,t){return l(r,"src",(n,o)=>`<script ${n}>${o}</script>`,t)}async function v(r,t){return l(r,"href",n=>`<link ${n} />`,{...t,defaultAttrs:{rel:"stylesheet"}})}async function l(r=[],t,n,{contentDir:o,outdir:m,defaultAttrs:p={}}){if(!Array.isArray(r)||!r.length)return"";const f=[];for(const s of r){const y=typeof s=="string"?{[t]:s}:{...s},{src:h,href:C,inline:c,...$}=y;let e=t==="href"?C:h,u="";if(a(e)&&!c){const i=await g(o,e,m);if(!i)continue;e=i}else a(e)&&c&&(u=S(d(o,e),"utf-8"),e=!1);const k=j({...p,...$,[t]:e});f.push(n(k,u))}return f.join("")}function j(r){const t=[];for(let n in r){const o=r[n];o!==!1&&(o===!0?t.push(n):t.push(`${n}="${o}"`))}return t.join(" ")}export{v as formatCustomLinks,b as formatCustomScripts};
