@@ -87,45 +87,57 @@ window.addEventListener('resize', fitAllText);
8787
8888<script is:inline define:vars ={ {slug: sponsor .id }} >
8989 document.addEventListener('DOMContentLoaded', () => {
90- document.querySelectorAll('.social').forEach((socialDiv, index) => {
90+ // Get base URL from document
91+ const baseUrl = document.baseURI || document.location.origin;
9192
92- socialDiv.addEventListener('click', () => {
93- const svgs = socialDiv.querySelectorAll('svg');
94-
95- if (svgs.length === 0) {
96- alert('No SVGs found!');
97- return;
98- }
99-
100- const xmlns = "http://www.w3.org/2000/svg";
101- const combinedSvg = document.createElementNS(xmlns, "svg");
102- combinedSvg.setAttribute("xmlns", xmlns);
103- combinedSvg.setAttribute("width", "900");
104- combinedSvg.setAttribute("height", "900");
105- combinedSvg.setAttribute("viewBox", "0 0 900 900");
106-
107- svgs.forEach(svg => {
108- const g = document.createElementNS(xmlns, "g");
109- g.innerHTML = svg.innerHTML;
110- combinedSvg.appendChild(g);
93+ document.querySelectorAll('.social').forEach((socialDiv, index) => {
94+ socialDiv.addEventListener('click', () => {
95+ const svgs = socialDiv.querySelectorAll('svg');
96+ if (svgs.length === 0) {
97+ alert('No SVGs found!');
98+ return;
99+ }
100+ const xmlns = "http://www.w3.org/2000/svg";
101+ const combinedSvg = document.createElementNS(xmlns, "svg");
102+ combinedSvg.setAttribute("xmlns", xmlns);
103+ combinedSvg.setAttribute("width", "900");
104+ combinedSvg.setAttribute("height", "900");
105+ combinedSvg.setAttribute("viewBox", "0 0 900 900");
106+
107+ svgs.forEach(svg => {
108+ const g = document.createElementNS(xmlns, "g");
109+ // Clone the SVG content and resolve relative URLs
110+ const clonedContent = svg.innerHTML;
111+ // Replace relative URLs with absolute URLs
112+ const resolvedContent = clonedContent.replace(
113+ /href="([^"]*(?:\.png|\.jpg|\.jpeg|\.gif|\.svg|\.webp)[^"]*)"/gi,
114+ (match, url) => {
115+ // If URL is already absolute, keep it as is
116+ if (url.startsWith('http') || url.startsWith('//')) {
117+ return match;
118+ }
119+ // Convert relative URL to absolute
120+ const absoluteUrl = new URL(url, baseUrl).href;
121+ return `href="${absoluteUrl}"`;
122+ }
123+ );
124+ g.innerHTML = resolvedContent;
125+ combinedSvg.appendChild(g);
126+ });
127+
128+ const serializer = new XMLSerializer();
129+ const svgString = serializer.serializeToString(combinedSvg);
130+ const blob = new Blob([svgString], {type: "image/svg+xml"});
131+ const url = URL.createObjectURL(blob);
132+ const a = document.createElement('a');
133+ a.href = url;
134+ a.download = slug ? `social-${slug}.svg` : `social-${index + 1}.svg`;
135+ a.style.display = "none";
136+ document.body.appendChild(a);
137+ a.click();
138+ URL.revokeObjectURL(url);
139+ document.body.removeChild(a);
140+ });
111141 });
112-
113- const serializer = new XMLSerializer();
114- const svgString = serializer.serializeToString(combinedSvg);
115-
116- const blob = new Blob([svgString], {type: "image/svg+xml"});
117- const url = URL.createObjectURL(blob);
118-
119- const a = document.createElement('a');
120- a.href = url;
121- a.download = slug ? `social-${slug}.svg` : `social-${index +1}.svg`;
122- a.style.display = "none";
123- document.body.appendChild(a);
124- a.click();
125-
126- URL.revokeObjectURL(url);
127- document.body.removeChild(a);
128142 });
129- });
130- });
131143</script >
0 commit comments