Skip to content

Commit

Permalink
working og images fonts
Browse files Browse the repository at this point in the history
  • Loading branch information
TGlide committed Jan 11, 2024
1 parent e3206ae commit 7175730
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 25 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"testing.automaticallyOpenPeekView": "never"
}
18 changes: 11 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
FROM node:20-bullseye AS build
# Use an official Node runtime as a parent image
FROM node:latest

ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"

WORKDIR /app
COPY . .

# Remove the node_modules folder to avoid wrong binaries
RUN rm -rf node_modules

# Install fontconfig
COPY ./local-fonts /usr/share/fonts
RUN apt-get update; apt-get install -y fontconfig
RUN fc-cache -f -v

RUN corepack enable
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install
RUN NODE_OPTIONS=--max_old_space_size=4096 pnpm run build

# Node alpine image to serve the generated static files
FROM node:20-alpine AS serve

WORKDIR /app
COPY --from=build /app .

EXPOSE 3000
CMD [ "node", "server/main.js"]
Binary file added local-fonts/AeonikFono-Regular.ttf
Binary file not shown.
Binary file added local-fonts/AeonikPro-Regular.ttf
Binary file not shown.
9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"@appwrite.io/pink": "0.1.0-next.9",
"@appwrite.io/pink-icons": "0.1.0-next.9",
"@appwrite.io/repo": "github:appwrite/appwrite#main",
"@resvg/resvg-js": "^2.6.0",
"@splinetool/viewer": "0.9.455",
"appwrite": "^13.0.1",
"compression": "^1.7.4",
Expand All @@ -75,11 +76,17 @@
"os": [
"win32",
"darwin",
"current"
"current",
"linux",
"linuxmusl"
],
"cpu": [
"x64",
"arm64"
],
"libc": [
"musl",
"glibc"
]
}
}
Expand Down
16 changes: 3 additions & 13 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
1 change: 1 addition & 0 deletions src/routes/init/ticket/+layout.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export const ssr = false;
export const prerender = false;
35 changes: 31 additions & 4 deletions src/routes/init/ticket/[id]/og/+server.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { PUBLIC_APPWRITE_COL_INIT_ID, PUBLIC_APPWRITE_DB_INIT_ID } from '$env/static/public';
import { appwriteInit } from '$lib/appwrite/init.js';
import sharp from 'sharp';

import type { Ticket } from '../../constants.js';

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

// export async function GET({ params, url }) {
// const ticket = (await appwriteInit.database.getDocument(
// PUBLIC_APPWRITE_DB_INIT_ID,
// PUBLIC_APPWRITE_COL_INIT_ID,
// params.id
// )) as unknown as Ticket;
// const svg = getSvg(ticket);

// const resvg = new Resvg(svg, {
// font: {
// fontFiles: [
// `${url.origin}/static/fonts/AeonikPro-Regular.woff2`,
// `${url.origin}/static/fonts/AeonikPro-Bold.woff2`,
// `${url.origin}/static/fonts/AeonikFono-Regular.woff2`
// ]
// }
// });
// const pngData = resvg.render();
// const pngBuffer = pngData.asPng();

// return new Response(pngBuffer, {
// headers: {
// 'Content-Type': 'image/png'
// }
// });
// }

export async function GET({ params }) {
const ticket = (await appwriteInit.database.getDocument(
PUBLIC_APPWRITE_DB_INIT_ID,
Expand All @@ -829,7 +856,7 @@ export async function GET({ params }) {
const svg = getSvg(ticket);

const svgBuffer = Buffer.from(svg);
const pngBuffer = await sharp(svgBuffer)
const pngBuffer = await sharp(svgBuffer, {})
.resize({
width: 1000
})
Expand Down

0 comments on commit 7175730

Please sign in to comment.