Skip to content
On this page

2023/05 4週目

Rust

スクラム

ラズパイ

Wasm

AI

OS

React

Frontend

  • https://github.com/vercel/satori
    • HTMLとCSSをSVGにするやつ

    • bokuwebさんのブログのOGP画像はこれで生成している

      コード
      typescript
      import satori from "satori";
      import sharp from "sharp";
      import fs from "fs";
      
      export const generateOgpImage = async (title: string) => {
        const font = fs.readFileSync("./ogp/fonts/NotoSansJP-Regular.otf");
        const svg = await satori(
          <div
            style={{
              height: "100%",
              width: "100%",
              display: "flex",
              flexDirection: "column",
              alignItems: "center",
              justifyContent: "center",
              backgroundColor: "#242424",
              fontSize: 32,
              fontWeight: 600,
              color: "#242424",
            }}
          >
            <div
              style={{
                padding: "0 50px",
                marginTop: 40,
                marginRight: 'auto',
                marginLeft: 'auto',
                fontSize: "40px",
                color: "#ccc",
                textAlign: "center",
              }}
            >
              {title}
            </div>
            <div
              style={{
                marginTop: 24,
                marginBottom: 12,
                fontSize: "20px",
                color: "#ccc",
              }}
            >
              MaybeUnInit
            </div>
            <div
              style={{
                color: "#d1d5db",
                fontSize: 16,
                display: "flex",
                alignItems: "center",
              }}
            >
              <img
                src="https://avatars.githubusercontent.com/u/10220449?v=4"
                width={32}
                height={32}
                style={{ borderRadius: 9999, marginRight: 12 }}
              />
              @bokuweb
            </div>
          </div>,
          {
            width: 800,
            height: 400,
            fonts: [
              {
                name: "Noto Sans JP",
                data: font,
                style: "normal",
              },
            ],
          }
        );
      
        const png = await sharp(Buffer.from(svg)).png().toBuffer();
        return png;
      };
  • https://github.com/vitejs/vite/blob/e3db7712657232fbb9ea2499a2c6f277d2bb96a3/docs/.vitepress/config.ts#L70-L77
    • vitepressのOGPの設定参考例

UI

Released under the MIT License.