Skip to content

Commit

Permalink
chore: upgrade to astro@4
Browse files Browse the repository at this point in the history
  • Loading branch information
jtsang4 committed Dec 12, 2023
1 parent 23c6a76 commit 9730eee
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 31 deletions.
1 change: 0 additions & 1 deletion astro.config.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// import { defineConfig, squooshImageService } from "astro/config"
import { defineConfig, squooshImageService } from "astro/config"
import tailwind from "@astrojs/tailwind"
import react from "@astrojs/react"
Expand Down
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion lib/remark-mermaid.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// source: https://github.com/JuanM04/portfolio/blob/983b0ed0eabdac37bf8b7912d3e8128a443192b9/src/plugins/mermaid.ts
import type { RemarkPlugin } from "@astrojs/markdown-remark"
import { visit } from "unist-util-visit"
import dedent from "ts-dedent"
import { dedent } from "ts-dedent"

const escapeMap: Record<string, string> = {
"&": "&amp;",
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
"lint": "eslint ."
},
"dependencies": {
"@astrojs/mdx": "^1.0.3",
"@astrojs/rss": "^3.0.0",
"@astrojs/mdx": "2.0.1",
"@astrojs/rss": "4.0.1",
"@resvg/resvg-js": "^2.4.1",
"artalk": "^2.6.3",
"astro": "^3.1.3",
"astro": "4.0.4",
"astro-icon": "^0.8.1",
"fuse.js": "^6.6.2",
"github-slugger": "^2.0.0",
Expand All @@ -33,9 +33,9 @@
"tailwindcss": "^3.3.3"
},
"devDependencies": {
"@astrojs/react": "^3.0.2",
"@astrojs/sitemap": "^3.0.0",
"@astrojs/tailwind": "^5.0.0",
"@astrojs/react": "3.0.7",
"@astrojs/sitemap": "3.0.3",
"@astrojs/tailwind": "5.0.3",
"@tailwindcss/typography": "^0.5.9",
"@types/github-slugger": "^2.0.0",
"@types/react": "^18.2.18",
Expand Down
47 changes: 24 additions & 23 deletions src/utils/generateOgImage.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
import satori, { SatoriOptions } from "satori";
import { SITE } from "@config";
import { writeFile } from "node:fs/promises";
import { Resvg } from "@resvg/resvg-js";
import satori from "satori"
import type { SatoriOptions } from "satori"
import { SITE } from "@config"
import { writeFile } from "node:fs/promises"
import { Resvg } from "@resvg/resvg-js"

const fetchFonts = async () => {
// Regular Font
const fontFileRegular = await fetch(
"https://www.1001fonts.com/download/font/ibm-plex-mono.regular.ttf"
);
const fontRegular: ArrayBuffer = await fontFileRegular.arrayBuffer();
)
const fontRegular: ArrayBuffer = await fontFileRegular.arrayBuffer()

// Bold Font
const fontFileBold = await fetch(
"https://www.1001fonts.com/download/font/ibm-plex-mono.bold.ttf"
);
const fontBold: ArrayBuffer = await fontFileBold.arrayBuffer();
)
const fontBold: ArrayBuffer = await fontFileBold.arrayBuffer()

return { fontRegular, fontBold };
};
return { fontRegular, fontBold }
}

const { fontRegular, fontBold } = await fetchFonts();
const { fontRegular, fontBold } = await fetchFonts()

const ogImage = (text: string) => {
return (
Expand Down Expand Up @@ -112,8 +113,8 @@ const ogImage = (text: string) => {
</div>
</div>
</div>
);
};
)
}

const options: SatoriOptions = {
width: 1200,
Expand All @@ -133,23 +134,23 @@ const options: SatoriOptions = {
style: "normal",
},
],
};
}

const generateOgImage = async (mytext = SITE.title) => {
const svg = await satori(ogImage(mytext), options);
const svg = await satori(ogImage(mytext), options)

// render png in production mode
if (import.meta.env.MODE === "production") {
const resvg = new Resvg(svg);
const pngData = resvg.render();
const pngBuffer = pngData.asPng();
const resvg = new Resvg(svg)
const pngData = resvg.render()
const pngBuffer = pngData.asPng()

console.info("Output PNG Image :", `${mytext}.png`);
console.info("Output PNG Image :", `${mytext}.png`)

await writeFile(`./dist/${mytext}.png`, pngBuffer);
await writeFile(`./dist/${mytext}.png`, pngBuffer)
}

return svg;
};
return svg
}

export default generateOgImage;
export default generateOgImage

0 comments on commit 9730eee

Please sign in to comment.