Skip to content

Commit 7175730

Browse files
committed
working og images fonts
1 parent e3206ae commit 7175730

File tree

9 files changed

+57
-25
lines changed

9 files changed

+57
-25
lines changed

.vscode/settings.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"testing.automaticallyOpenPeekView": "never"
3+
}

Dockerfile

+11-7
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
1-
FROM node:20-bullseye AS build
1+
# Use an official Node runtime as a parent image
2+
FROM node:latest
23

34
ENV PNPM_HOME="/pnpm"
45
ENV PATH="$PNPM_HOME:$PATH"
56

67
WORKDIR /app
78
COPY . .
89

10+
# Remove the node_modules folder to avoid wrong binaries
11+
RUN rm -rf node_modules
12+
13+
# Install fontconfig
14+
COPY ./local-fonts /usr/share/fonts
15+
RUN apt-get update; apt-get install -y fontconfig
16+
RUN fc-cache -f -v
17+
918
RUN corepack enable
10-
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install
19+
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install
1120
RUN NODE_OPTIONS=--max_old_space_size=4096 pnpm run build
1221

13-
# Node alpine image to serve the generated static files
14-
FROM node:20-alpine AS serve
15-
16-
WORKDIR /app
17-
COPY --from=build /app .
1822

1923
EXPOSE 3000
2024
CMD [ "node", "server/main.js"]

local-fonts/AeonikFono-Regular.ttf

77.9 KB
Binary file not shown.

local-fonts/AeonikPro-Regular.ttf

138 KB
Binary file not shown.

package.json

+8-1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
"@appwrite.io/pink": "0.1.0-next.9",
6161
"@appwrite.io/pink-icons": "0.1.0-next.9",
6262
"@appwrite.io/repo": "github:appwrite/appwrite#main",
63+
"@resvg/resvg-js": "^2.6.0",
6364
"@splinetool/viewer": "0.9.455",
6465
"appwrite": "^13.0.1",
6566
"compression": "^1.7.4",
@@ -75,11 +76,17 @@
7576
"os": [
7677
"win32",
7778
"darwin",
78-
"current"
79+
"current",
80+
"linux",
81+
"linuxmusl"
7982
],
8083
"cpu": [
8184
"x64",
8285
"arm64"
86+
],
87+
"libc": [
88+
"musl",
89+
"glibc"
8390
]
8491
}
8592
}

pnpm-lock.yaml

+3-13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
File renamed without changes.

src/routes/init/ticket/+layout.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export const ssr = false;
2+
export const prerender = false;

src/routes/init/ticket/[id]/og/+server.ts

+31-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { PUBLIC_APPWRITE_COL_INIT_ID, PUBLIC_APPWRITE_DB_INIT_ID } from '$env/static/public';
22
import { appwriteInit } from '$lib/appwrite/init.js';
33
import sharp from 'sharp';
4+
45
import type { Ticket } from '../../constants.js';
56

6-
const getSvg = (
7-
ticket: Ticket
8-
) => `<svg width="438" height="249" viewBox="0 0 438 249" fill="none" xmlns="http://www.w3.org/2000/svg">
7+
const getSvg = (ticket: Ticket) => `
8+
<svg width="876" height="498" viewBox="0 0 438 249" fill="none" xmlns="http://www.w3.org/2000/svg">
99
<g filter="url(#filter0_b_327_1972)">
1010
<g clip-path="url(#clip0_327_1972)">
1111
<rect width="438" height="249" rx="18" fill="#19191C" />
@@ -820,6 +820,33 @@ const getSvg = (
820820
</svg>
821821
`;
822822

823+
// export async function GET({ params, url }) {
824+
// const ticket = (await appwriteInit.database.getDocument(
825+
// PUBLIC_APPWRITE_DB_INIT_ID,
826+
// PUBLIC_APPWRITE_COL_INIT_ID,
827+
// params.id
828+
// )) as unknown as Ticket;
829+
// const svg = getSvg(ticket);
830+
831+
// const resvg = new Resvg(svg, {
832+
// font: {
833+
// fontFiles: [
834+
// `${url.origin}/static/fonts/AeonikPro-Regular.woff2`,
835+
// `${url.origin}/static/fonts/AeonikPro-Bold.woff2`,
836+
// `${url.origin}/static/fonts/AeonikFono-Regular.woff2`
837+
// ]
838+
// }
839+
// });
840+
// const pngData = resvg.render();
841+
// const pngBuffer = pngData.asPng();
842+
843+
// return new Response(pngBuffer, {
844+
// headers: {
845+
// 'Content-Type': 'image/png'
846+
// }
847+
// });
848+
// }
849+
823850
export async function GET({ params }) {
824851
const ticket = (await appwriteInit.database.getDocument(
825852
PUBLIC_APPWRITE_DB_INIT_ID,
@@ -829,7 +856,7 @@ export async function GET({ params }) {
829856
const svg = getSvg(ticket);
830857

831858
const svgBuffer = Buffer.from(svg);
832-
const pngBuffer = await sharp(svgBuffer)
859+
const pngBuffer = await sharp(svgBuffer, {})
833860
.resize({
834861
width: 1000
835862
})

0 commit comments

Comments
 (0)