diff --git a/src/back/icons.ts b/src/back/icons.ts new file mode 100644 index 0000000..140bee5 --- /dev/null +++ b/src/back/icons.ts @@ -0,0 +1,28 @@ +import { promises as fs } from "fs"; +import path from "path"; +import _locreq from "locreq"; + +const locreq = _locreq(import.meta.dirname); + +const cache = {} as Record | undefined>; + +export const svg_icon_path = "src/icons"; + +async function getIconUncached(icon_name: string): Promise { + return fs.readFile( + locreq.resolve(path.resolve(svg_icon_path, icon_name + ".svg")), + "utf-8" + ); +} + +export async function icon(icon_name: string) { + if (!cache[icon_name]) { + cache[icon_name] = getIconUncached(icon_name); + } + try { + return cache[icon_name]; + } catch (e) { + console.error(e); + return ""; + } +} diff --git a/src/back/routes/common/footer.tsx b/src/back/routes/common/footer.tsx index 14a46e0..141e918 100644 --- a/src/back/routes/common/footer.tsx +++ b/src/back/routes/common/footer.tsx @@ -6,6 +6,7 @@ import { TempstreamJSX } from "tempstream"; const icons = [ { name: "mastodon", url: "https://mastodon.com.pl" }, { name: "peertube", url: "https://joinpeertube.org/pl" }, + { name: "matrix", url: "https://matrix.org/" }, ]; export default async function footer(ctx: Context) { diff --git a/src/icons/mastodon.svg b/src/icons/mastodon.svg new file mode 100644 index 0000000..fdf682c --- /dev/null +++ b/src/icons/mastodon.svg @@ -0,0 +1,11 @@ + + + + + + + diff --git a/src/icons/matrix.svg b/src/icons/matrix.svg new file mode 100644 index 0000000..b2150ce --- /dev/null +++ b/src/icons/matrix.svg @@ -0,0 +1,28 @@ + + + + + Matrix (protocol) logo + + + + + + diff --git a/src/icons/peertube.svg b/src/icons/peertube.svg new file mode 100644 index 0000000..5637e42 --- /dev/null +++ b/src/icons/peertube.svg @@ -0,0 +1,16 @@ + + + + + +