Skip to content

Commit

Permalink
fix(nx-dev): ensure long titles on og images have line breaks (#18619)
Browse files Browse the repository at this point in the history
  • Loading branch information
meeroslav committed Aug 14, 2023
1 parent b749b47 commit 4f67f15
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions scripts/documentation/open-graph/generate-images.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ packages.map((pkg) => {
});
});

const TITLE_LINE_HEIGHT = 60;
const SUB_LINE_HEIGHT = 38;

function createOpenGraphImage(
backgroundImagePath: string,
targetFolder: string,
Expand All @@ -115,7 +118,10 @@ function createOpenGraphImage(
context.textAlign = 'center';
context.textBaseline = 'top';
context.fillStyle = '#0F172A';
context.fillText(title.toUpperCase(), 600, 220);
const titleLines = splitLines(context, title.toUpperCase(), 1100);
titleLines.forEach((line, index) => {
context.fillText(line, 600, 220 + index * TITLE_LINE_HEIGHT);
});

context.font = 'normal 32px system-ui';
context.textAlign = 'center';
Expand All @@ -124,7 +130,11 @@ function createOpenGraphImage(

const lines = splitLines(context, content, 1100);
lines.forEach((line, index) => {
context.fillText(line, 600, 310 + index * 55);
context.fillText(
line,
600,
310 + index * SUB_LINE_HEIGHT + titleLines.length * TITLE_LINE_HEIGHT
);
});

console.log('Generating: ', `${filename}.jpg`);
Expand Down

1 comment on commit 4f67f15

@vercel
Copy link

@vercel vercel bot commented on 4f67f15 Aug 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx-dev-git-master-nrwl.vercel.app
nx-dev-nrwl.vercel.app
nx-five.vercel.app
nx.dev

Please sign in to comment.