mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
[bun-landing] inline via data uri
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import Head from "next/head";
|
||||
import { dataURI } from "macro:./dataURI";
|
||||
|
||||
export default function Layout({ children }) {
|
||||
return (
|
||||
@@ -52,13 +53,18 @@ export default function Layout({ children }) {
|
||||
<div id="header-wrap">
|
||||
<header>
|
||||
<a href="/" id="logo-link" aria-label="home">
|
||||
<img height="61px" src="/logo.svg" alt="Bun logo" id="logo" />
|
||||
<img
|
||||
height="31.65px"
|
||||
src="/Bun.png"
|
||||
srcSet="/Bun.png 1x, /Bun@2x.png 2x"
|
||||
height="61px"
|
||||
src={dataURI("../public/logo.svg", "components/Layout.tsx")}
|
||||
alt="Bun logo"
|
||||
id="logo"
|
||||
/>
|
||||
|
||||
<img
|
||||
alt="Bun"
|
||||
id="logo-text"
|
||||
height="31.65px"
|
||||
src={dataURI("../public/Bun@2x.png", "components/Layout.tsx")}
|
||||
/>
|
||||
</a>
|
||||
|
||||
|
||||
19
packages/bun-landing/components/dataURI.ts
Normal file
19
packages/bun-landing/components/dataURI.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { readFileSync } from "fs";
|
||||
import { resolve } from "path";
|
||||
|
||||
export function dataURI(expr) {
|
||||
const [pathNode, relativeNode] = expr.arguments;
|
||||
const path = pathNode.toString();
|
||||
const relative = relativeNode.toString();
|
||||
try {
|
||||
const toLoad = resolve(process.cwd(), relative, "../", path);
|
||||
const data = readFileSync(toLoad);
|
||||
|
||||
return `data:${Bun.file(toLoad).type};base64, ${btoa(
|
||||
String.fromCharCode(...new Uint8Array(data.buffer))
|
||||
)}`;
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
return "";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user