From 00682bf83e5ccc89d307c5eefc1613b0574f329e Mon Sep 17 00:00:00 2001 From: Zicklag Date: Fri, 17 Jan 2025 12:16:34 -0600 Subject: [PATCH] feat: add SVG icon data to social links in theme templates. --- src/lib/renderer/index.ts | 38 +- src/lib/themes/weird.html.j2 | 2886 +---------------- .../[username]/theme-editor/+page.svelte | 11 +- .../(subsites)/subsite/[username]/+server.ts | 6 +- static/renderers/minijinja.wasm | Bin 1062497 -> 1070985 bytes 5 files changed, 42 insertions(+), 2899 deletions(-) diff --git a/src/lib/renderer/index.ts b/src/lib/renderer/index.ts index 537f51f2..87d99921 100644 --- a/src/lib/renderer/index.ts +++ b/src/lib/renderer/index.ts @@ -1,5 +1,7 @@ import { browser, building, dev } from '$app/environment'; import { env } from '$env/dynamic/public'; +import { getSocialMediaDetails } from '$lib/utils/social-links'; +import { buildIcon, loadIcon } from '@iconify/svelte'; type RendererExports = { memory: WebAssembly.Memory; @@ -57,19 +59,39 @@ export type ProfileData = { display_name?: string; bio?: string; tags?: string[]; - social_links?: { url: string; label?: string }[]; + social_links?: { url: string; label?: string; platform_name?: string }[]; links?: { url: string; label?: string }[]; pages?: { slug: string; name?: string }[]; }; -export function render( - profileData: Omit, +export async function render( + profile: Omit, themeData: Uint8Array -): string { - const profileDataJson = JSON.stringify({ - ...profileData, - ...{ instance_info: { url: env.PUBLIC_URL } } - } as ProfileData); +): Promise { + const data: ProfileData = { + handle: profile.handle, + bio: profile.bio, + display_name: profile.display_name, + links: profile.links, + pages: profile.pages, + social_links: await Promise.all( + profile.social_links?.map(async (x) => { + const details = getSocialMediaDetails(x.url); + const i = buildIcon(await loadIcon(details.icon)); + return { + url: x.url, + label: x.label, + platform_name: details.name.toLocaleLowerCase(), + icon: ` `${k}="${v}"`) + .join(' ')} >${i.body}` + }; + }) || [] + ), + tags: profile.tags, + instance_info: { url: env.PUBLIC_URL } + }; + const profileDataJson = JSON.stringify(data); const profileDataJsonBinary = encoder.encode(profileDataJson); const profileDataJsonBinaryLen = profileDataJsonBinary.length; const profileDataJsonPtr = wasm.wasm_alloc(profileDataJsonBinaryLen, 1); diff --git a/src/lib/themes/weird.html.j2 b/src/lib/themes/weird.html.j2 index 3ed296d6..baa58559 100644 --- a/src/lib/themes/weird.html.j2 +++ b/src/lib/themes/weird.html.j2 @@ -6,2892 +6,11 @@ - - +