aboutsummaryrefslogtreecommitdiff
path: root/apps/website/src/components/logos/Logo.astro
diff options
context:
space:
mode:
authorPauline <git@ethanlibs.co>2023-10-14 14:24:27 -0400
committerPauline <git@ethanlibs.co>2023-10-14 14:24:27 -0400
commit997b850967df8dc03a7321b167dc9f7b52f98c7a (patch)
tree76568b90c7b82372a720249b89193f161581f2e8 /apps/website/src/components/logos/Logo.astro
parentdcc90017baaafa74c79acaa053535d73b6222475 (diff)
downloadNexus-997b850967df8dc03a7321b167dc9f7b52f98c7a.tar.gz
Nexus-997b850967df8dc03a7321b167dc9f7b52f98c7a.tar.bz2
Nexus-997b850967df8dc03a7321b167dc9f7b52f98c7a.zip
migrate(web): migrate from website/new-website to nexus/apps/website
Diffstat (limited to 'apps/website/src/components/logos/Logo.astro')
-rw-r--r--apps/website/src/components/logos/Logo.astro52
1 files changed, 52 insertions, 0 deletions
diff --git a/apps/website/src/components/logos/Logo.astro b/apps/website/src/components/logos/Logo.astro
new file mode 100644
index 0000000..0532396
--- /dev/null
+++ b/apps/website/src/components/logos/Logo.astro
@@ -0,0 +1,52 @@
+---
+import type { LogoType } from "@webtypes/Config";
+import { dirname } from "path";
+import { fileURLToPath } from "url";
+import type { HTMLAttributes } from "astro/types";
+
+export interface Props extends HTMLAttributes<"svg"> {
+ logo: LogoType,
+ size?: number | [number, number],
+ silent?: boolean,
+}
+
+const {
+ logo,
+ silent = false,
+ size = undefined,
+ ...attr
+} = Astro.props;
+let svg: string | undefined;
+
+try {
+ if (logo == undefined) return;
+ const dir = dirname(fileURLToPath(import.meta.url)) + "/../../../public/media";
+ svg = (await import(`${dir}/${logo.replaceAll(".", "/")}.svg?raw` /* @vite-ignore */)).default;
+
+ if (svg == undefined) return;
+
+ if (typeof size == "number" || Array.isArray(size)) {
+ // SVG main element regex
+ const svgElementRegex = /<svg[^>]*>/;
+
+ svg = svg.replace(svgElementRegex, (match) => {
+ let newMatch = match;
+ if (typeof size == "number") {
+ newMatch = newMatch.replace(/width="[^"]*"/, `width="${size}"`);
+ newMatch = newMatch.replace(/height="[^"]*"/, `height="${size}"`);
+ } else if (Array.isArray(size)) {
+ newMatch = newMatch.replace(/width="[^"]*"/, `width="${size[0]}"`);
+ newMatch = newMatch.replace(/height="[^"]*"/, `height="${size[1]}"`);
+ }
+ return newMatch;
+ });
+ }
+
+ svg = svg.replace(/<svg/, `<svg ${Object.entries(attr).map(([key, value]) => `${key}="${value}"`).join(" ")}`);
+} catch (err) {
+ if (typeof silent != "boolean" || silent == false) console.error(err);
+}
+
+---
+
+<Fragment set:html={svg} />