Skip to content

Commit d728445

Browse files
authored
Fixed some issues
1 parent 8b67068 commit d728445

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
lines changed

assets/contributors/contributor.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ main {
9494
text-decoration: none;
9595
}
9696

97-
button {
97+
.certificate-button {
9898
font-size: 13px;
9999
padding: 7px 10px;
100100
display: flex;

assets/contributors/contributor.js

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ async function fetchContributors() {
4848

4949
// Generate Certificate Button
5050
const button = document.createElement("button");
51+
button.className = "certificate-button";
5152
button.textContent = "Certificate";
5253
button.addEventListener("click", () => {
5354
generateCertificate(contributor.login, contributor.avatar_url);
@@ -76,8 +77,11 @@ async function fetchContributors() {
7677
ctx.fillStyle = gradient;
7778
ctx.fillRect(0, 0, canvas.width, canvas.height);
7879

80+
// Get the value of the CSS variable
81+
const primaryColor = getComputedStyle(document.documentElement).getPropertyValue('--primary-color').trim();
82+
7983
// Decorative border
80-
ctx.strokeStyle = "#1da1f2";
84+
ctx.strokeStyle = primaryColor;
8185
ctx.lineWidth = 20;
8286
ctx.strokeRect(50, 50, canvas.width - 100, canvas.height - 100);
8387

@@ -113,12 +117,39 @@ async function fetchContributors() {
113117
ctx.fillStyle = "white";
114118
ctx.fillText(username, canvas.width / 2, 500);
115119

120+
// Function to wrap text
121+
function wrapText(ctx, text, x, y, maxWidth, lineHeight) {
122+
const words = text.split(" ");
123+
let line = "";
124+
for (let i = 0; i < words.length; i++) {
125+
const testLine = line + words[i] + " ";
126+
const metrics = ctx.measureText(testLine);
127+
const testWidth = metrics.width;
128+
129+
if (testWidth > maxWidth && i > 0) {
130+
ctx.fillText(line, x, y);
131+
line = words[i] + " ";
132+
y += lineHeight;
133+
} else {
134+
line = testLine;
135+
}
136+
}
137+
ctx.fillText(line, x, y);
138+
}
139+
116140
// Certificate content
117141
ctx.font = "35px Arial";
118142
const content = `This certificate is proudly presented to ${username} for their valuable contribution to planetoid. Keep contributing. Best wishes for their future endeavors.`;
119-
content.split("\n").forEach((line, index) => {
120-
ctx.fillText(line.trim(), canvas.width / 2, 600 + index * 40);
121-
});
143+
144+
// Call the wrapText function to render wrapped text
145+
const contentX = canvas.width / 2;
146+
const contentY = 600;
147+
const maxWidth = canvas.width - 500;
148+
const lineHeight = 40;
149+
150+
ctx.textAlign = "center";
151+
wrapText(ctx, content, contentX, contentY, maxWidth, lineHeight);
152+
122153

123154
// Signature with decorative underline
124155
ctx.font = "italic 30px Georgia";

0 commit comments

Comments
 (0)