Skip to content

Commit c09c260

Browse files
committed
Merge remote-tracking branch 'upstream/main' into tweaks
2 parents af74d13 + 19a711c commit c09c260

File tree

8 files changed

+110
-57
lines changed

8 files changed

+110
-57
lines changed

package-lock.json

+5-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
"react-use-flexsearch": "^0.1.1",
6969
"react-world-flags": "^1.6.0",
7070
"remark-gfm": "^1.0.0",
71-
"sass": "1.83.4",
71+
"sass": "1.84.0",
7272
"slick-carousel": "^1.8.1",
7373
"swiper": "^11.2.2"
7474
},

src/components/AuthorBio/__tests__/__snapshots__/AuthorBio.test.tsx.snap

+18-8
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,18 @@
33
exports[`AuthorBio component > should render correctly 1`] = `
44
<div>
55
<div
6-
class="flex flex-wrap justify-center items-center gap-5 space-x-4"
6+
class="flex flex-wrap justify-center items-center gap-5 space-x-4 pb-4"
77
>
88
<img
99
alt="[object Object]"
1010
image="[object Object]"
1111
stlye="[object Object]"
12-
style="margin-left: 0.5rem; margin-bottom: 0px; min-width: 30px; border-radius: 100%;"
12+
style="margin-right: 0.5rem; margin-bottom: 0px; min-width: 50px; border-radius: 100%;"
1313
/>
14+
</div>
15+
<div
16+
class="flex flex-wrap justify-center items-center gap-5 space-x-4"
17+
>
1418
<span
1519
class="text-[16px] font-bold leading-[150%] text-white flex items-center"
1620
>
@@ -21,14 +25,16 @@ exports[`AuthorBio component > should render correctly 1`] = `
2125
aria-label="GitHub Profile"
2226
class="px-1"
2327
href="https://github.com/adoptium"
28+
rel="noopener noreferrer"
29+
target="blank"
2430
>
2531
<svg
2632
fill="currentColor"
27-
height="1em"
33+
height="25"
2834
stroke="currentColor"
2935
stroke-width="0"
3036
viewBox="0 0 496 512"
31-
width="1em"
37+
width="25"
3238
xmlns="http://www.w3.org/2000/svg"
3339
>
3440
<path
@@ -40,14 +46,16 @@ exports[`AuthorBio component > should render correctly 1`] = `
4046
aria-label="Twitter Profile"
4147
class="px-1"
4248
href="https://x.com/adoptium"
49+
rel="noopener noreferrer"
50+
target="blank"
4351
>
4452
<svg
4553
fill="currentColor"
46-
height="1em"
54+
height="25"
4755
stroke="currentColor"
4856
stroke-width="0"
4957
viewBox="0 0 512 512"
50-
width="1em"
58+
width="25"
5159
xmlns="http://www.w3.org/2000/svg"
5260
>
5361
<path
@@ -59,14 +67,16 @@ exports[`AuthorBio component > should render correctly 1`] = `
5967
aria-label="LinkedIn Profile"
6068
class="px-1"
6169
href="https://www.linkedin.com/in/adoptium"
70+
rel="noopener noreferrer"
71+
target="blank"
6272
>
6373
<svg
6474
fill="currentColor"
65-
height="1em"
75+
height="25"
6676
stroke="currentColor"
6777
stroke-width="0"
6878
viewBox="0 0 448 512"
69-
width="1em"
79+
width="25"
7080
xmlns="http://www.w3.org/2000/svg"
7181
>
7282
<path

src/components/BlogAuthor/__tests__/__snapshots__/BlogAuthor.test.tsx.snap

+12-6
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@ exports[`BlogAuthor component > GitHub link - should render correctly 1`] = `
66
aria-label="GitHub Profile"
77
class="px-1"
88
href="https://github.com/sample"
9+
rel="noopener noreferrer"
10+
target="blank"
911
>
1012
<svg
1113
fill="currentColor"
12-
height="1em"
14+
height="25"
1315
stroke="currentColor"
1416
stroke-width="0"
1517
viewBox="0 0 496 512"
16-
width="1em"
18+
width="25"
1719
xmlns="http://www.w3.org/2000/svg"
1820
>
1921
<path
@@ -30,14 +32,16 @@ exports[`BlogAuthor component > Linkedin link - should render correctly 1`] = `
3032
aria-label="LinkedIn Profile"
3133
class="px-1"
3234
href="https://www.linkedin.com/in/sample"
35+
rel="noopener noreferrer"
36+
target="blank"
3337
>
3438
<svg
3539
fill="currentColor"
36-
height="1em"
40+
height="25"
3741
stroke="currentColor"
3842
stroke-width="0"
3943
viewBox="0 0 448 512"
40-
width="1em"
44+
width="25"
4145
xmlns="http://www.w3.org/2000/svg"
4246
>
4347
<path
@@ -54,14 +58,16 @@ exports[`BlogAuthor component > Twitter link - should render correctly 1`] = `
5458
aria-label="Twitter Profile"
5559
class="px-1"
5660
href="https://x.com/sample"
61+
rel="noopener noreferrer"
62+
target="blank"
5763
>
5864
<svg
5965
fill="currentColor"
60-
height="1em"
66+
height="25"
6167
stroke="currentColor"
6268
stroke-width="0"
6369
viewBox="0 0 512 512"
64-
width="1em"
70+
width="25"
6571
xmlns="http://www.w3.org/2000/svg"
6672
>
6773
<path

src/pages/__tests__/__snapshots__/blog.test.tsx.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ exports[`News page > renders correctly 1`] = `
109109
</h3>
110110
</div>
111111
<span>
112-
...
112+
MDX Page excerpt
113113
</span>
114114
<a
115115
href="/mdx/mdx-page-title"

src/templates/__tests__/__snapshots__/authorPage.test.tsx.snap

+4-4
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ exports[`AuthorPage pages > renders correctly - with next and previous paginatio
111111
</h3>
112112
</div>
113113
<span>
114-
...
114+
MDX Page excerpt
115115
</span>
116116
<a
117117
href="/mdx/mdx-page-title"
@@ -308,7 +308,7 @@ exports[`AuthorPage pages > renders correctly - with next pagination 1`] = `
308308
</h3>
309309
</div>
310310
<span>
311-
...
311+
MDX Page excerpt
312312
</span>
313313
<a
314314
href="/mdx/mdx-page-title"
@@ -474,7 +474,7 @@ exports[`AuthorPage pages > renders correctly - with previous pagination 1`] = `
474474
</h3>
475475
</div>
476476
<span>
477-
...
477+
MDX Page excerpt
478478
</span>
479479
<a
480480
href="/mdx/mdx-page-title"
@@ -641,7 +641,7 @@ exports[`AuthorPage pages > renders correctly 1`] = `
641641
</h3>
642642
</div>
643643
<span>
644-
...
644+
MDX Page excerpt
645645
</span>
646646
<a
647647
href="/mdx/mdx-page-title"

src/templates/__tests__/__snapshots__/newsPage.test.tsx.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ exports[`News Template page > renders correctly 1`] = `
109109
</h3>
110110
</div>
111111
<span>
112-
...
112+
MDX Page excerpt
113113
</span>
114114
<a
115115
href="/mdx/mdx-page-title"

src/util/__tests__/generateFeaturedImage.test.tsx

+68-32
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,110 @@
11
import { describe, it, expect, vi, afterEach } from 'vitest';
2-
import { wrapText, generateFeaturedImage } from '../generateFeaturedImage';
2+
import { getWrappedLines, drawTitleAndSubtitle, generateFeaturedImage } from '../generateFeaturedImage';
33
import fs from 'fs-extra';
44
import path from 'path';
55

6-
describe('wrapText', () => {
6+
describe('getWrappedLines', () => {
77
it('should wrap text into multiple lines when exceeding max width', () => {
8-
// Create a fake canvas context.
9-
const fillTextMock = vi.fn();
8+
// Create a fake canvas context that simulates measureText.
109
const fakeCtx = {
11-
// Fake measureText: each character counts for 10 pixels.
1210
measureText: (text: string) => ({ width: text.length * 10 }),
13-
fillText: fillTextMock,
14-
textAlign: '', // not used by our helper
1511
} as unknown as import('canvas').CanvasRenderingContext2D;
1612

17-
const maxWidth = 100; // Allow up to 100 pixels per line
18-
const lineHeight = 20;
19-
const x = 50;
20-
const y = 50;
13+
const maxWidth = 100; // 100 pixels maximum
2114
const text = "This is a long text that should be wrapped";
2215

23-
wrapText(fakeCtx, text, x, y, maxWidth, lineHeight);
16+
// Call getWrappedLines to get an array of wrapped lines.
17+
const lines = getWrappedLines(fakeCtx, text, maxWidth);
2418

25-
// Based on our fake measureText, the helper should break the text into lines.
26-
// For this specific text and maxWidth, one possible expected split is:
19+
// Based on our fake measureText (each character = 10px), one expected split is:
2720
// 1. "This is a"
2821
// 2. "long text"
2922
// 3. "that"
3023
// 4. "should be"
3124
// 5. "wrapped"
32-
// (Depending on spacing, your exact split might vary.)
3325
const expectedLines = ["This is a", "long text", "that", "should be", "wrapped"];
26+
expect(lines).toEqual(expectedLines);
27+
});
28+
});
29+
30+
describe('drawTitleAndSubtitle', () => {
31+
it('should draw title and subtitle with correct dynamic spacing for single-line texts', () => {
32+
// Create a fake canvas context with spy functions for fillText.
33+
const fillTextMock = vi.fn();
34+
const fakeCtx = {
35+
measureText: (text: string) => ({ width: text.length * 10 }),
36+
fillText: fillTextMock,
37+
save: vi.fn(),
38+
restore: vi.fn(),
39+
font: '',
40+
} as unknown as import('canvas').CanvasRenderingContext2D;
41+
42+
const x = 50; // center x-coordinate
43+
const canvasHeight = 200; // total canvas height for vertical centering
44+
const maxWidth = 100;
45+
const titleFont = "bold 60px Nunito, sans-serif";
46+
const subtitleFont = "normal 40px Nunito, sans-serif";
47+
const titleLineHeight = 70; // approximate height for each title line
48+
const subtitleLineHeight = 50; // approximate height for each subtitle line
49+
const baseGap = 20;
50+
const gapExtraPerLine = 10;
51+
52+
// Use simple one-word texts so that each wraps into a single line.
53+
const title = "Hello";
54+
const subtitle = "World";
55+
56+
// Expected calculations:
57+
// - getWrappedLines("Hello") returns ["Hello"] → titleBlockHeight = 1 * 70 = 70.
58+
// - getWrappedLines("World") returns ["World"] → subtitleBlockHeight = 1 * 50 = 50.
59+
// - Gap = baseGap + (1 - 1) * gapExtraPerLine = 20.
60+
// - Total block height = 70 + 20 + 50 = 140.
61+
// - startY = (canvasHeight - totalBlockHeight) / 2 = (200 - 140) / 2 = 30.
62+
// Then:
63+
// Title is drawn at: 30 + (70 / 2) = 65.
64+
// Subtitle is drawn at: 30 + 70 + 20 + (50 / 2) = 145.
65+
66+
drawTitleAndSubtitle(
67+
fakeCtx,
68+
title,
69+
subtitle,
70+
x,
71+
canvasHeight,
72+
maxWidth,
73+
titleFont,
74+
subtitleFont,
75+
titleLineHeight,
76+
subtitleLineHeight,
77+
baseGap,
78+
gapExtraPerLine
79+
);
3480

35-
// Check that fillText was called the expected number of times
36-
expect(fillTextMock).toHaveBeenCalledTimes(expectedLines.length);
37-
expectedLines.forEach((line, index) => {
38-
expect(fillTextMock).toHaveBeenNthCalledWith(
39-
index + 1,
40-
line,
41-
x,
42-
y + index * lineHeight
43-
);
44-
});
81+
expect(fillTextMock).toHaveBeenCalledTimes(2);
82+
expect(fillTextMock).toHaveBeenNthCalledWith(1, "Hello", x, 65);
83+
expect(fillTextMock).toHaveBeenNthCalledWith(2, "World", x, 145);
4584
});
4685
});
4786

4887
describe('generateFeaturedImage', () => {
49-
// Use a temporary directory for output
88+
// Use a temporary directory for output during tests.
5089
const tempOutputDir = path.join(__dirname, 'temp-test-generated');
5190

5291
afterEach(async () => {
53-
// Remove the temporary directory after each test to clean up.
92+
// Clean up the temporary directory after each test.
5493
await fs.remove(tempOutputDir);
5594
});
5695

5796
it('should generate an image file', async () => {
58-
// For testing, you can either ensure that the background file exists at the
59-
// provided path or you can mock loadImage. For this example, we assume the
60-
// background image exists in the expected location.
6197
const title = "Test Title";
6298
const subtitle = "Test Subtitle";
6399
const outputPath = path.join(tempOutputDir, 'test.png');
64100

65101
await generateFeaturedImage(title, subtitle, outputPath);
66102

67-
// Check that the file was created.
103+
// Verify that the file was created.
68104
const fileExists = await fs.pathExists(outputPath);
69105
expect(fileExists).toBe(true);
70106

71-
// Optionally, verify the file is not empty.
107+
// Optionally, check that the file is not empty.
72108
const stats = await fs.stat(outputPath);
73109
expect(stats.size).toBeGreaterThan(0);
74110
});

0 commit comments

Comments
 (0)