Skip to content

[FEAT] Add Plant Theme #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,4 @@ export default function Home() {
);
}

const TAGS = [{ label: "hair" }, { label: "fire" }];
const TAGS = [{ label: "hair" }, { label: "fire" }, { label: "plant" }];
14 changes: 13 additions & 1 deletion lib/svg-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ export async function generateThemedSVG(username: string, themeKey: string) {
const cellSize = 14;

const background = theme.background || "#ffffff";
const backgroundPattern = theme.backgroundPattern;
const patternId = `pattern_${themeKey}`;

const baseDot = theme.showBaseDot ?? false;

const elements = weeks.flatMap((week, weekIndex) =>
Expand Down Expand Up @@ -44,9 +47,18 @@ export async function generateThemedSVG(username: string, themeKey: string) {
}),
);

const defs = backgroundPattern
? `<defs>${backgroundPattern.replace(
/<pattern([^>]*?)>/g,
`<pattern id="${patternId}"$1>`
)}</defs>`
: "";
const fillValue = backgroundPattern ? `url(#${patternId})` : background;

const svg = `
<svg xmlns="http://www.w3.org/2000/svg" width="${weeks.length * cellSize + 40}" height="180">
<rect width="100%" height="100%" fill="${background}" />
${defs}
<rect width="100%" height="100%" fill="${fillValue}" />
<text x="20" y="30" font-size="16" fill="#333">${theme.emoji || ""} ${username}'s ${theme.label}</text>
${elements.join("\n")}
</svg>
Expand Down
39 changes: 39 additions & 0 deletions lib/themes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export interface ThemeStyle {
label: string;
emoji?: string;
background?: string;
backgroundPattern?: string;
showBaseDot?: boolean;
}

Expand Down Expand Up @@ -61,9 +62,47 @@ export const FireTheme: ThemeStyle = {
},
};

export const PlantTheme: ThemeStyle = {
label: "Plant",
emoji: "๐ŸŒฟ",
background: "#f0fdf4",
backgroundPattern: `
<pattern patternUnits="userSpaceOnUse" width="40" height="40">
<rect width="40" height="40" fill="#7B4A22" />
<ellipse cx="8.2" cy="7.1" rx="5.1" ry="2.2" fill="#A97C50" opacity="0.65"/>
<ellipse cx="30.5" cy="15.7" rx="3.8" ry="2.9" fill="#C69C6D" opacity="0.55"/>
<ellipse cx="20.1" cy="35.2" rx="4.2" ry="1.7" fill="#8D6748" opacity="0.60"/>
<ellipse cx="12.7" cy="28.3" rx="2.9" ry="1.2" fill="#BCA17A" opacity="0.70"/>
<circle cx="5.2" cy="5.8" r="1.7" fill="#F9E4B7" opacity="0.80"/>
<circle cx="13.1" cy="11.2" r="1.1" fill="#F6D28B" opacity="0.60"/>
<circle cx="32.3" cy="8.4" r="1.3" fill="#F9E4B7" opacity="0.90"/>
<circle cx="18.7" cy="25.6" r="1.2" fill="#BCA17A" opacity="0.70"/>
<circle cx="36.2" cy="36.1" r="1.5" fill="#A97C50" opacity="0.80"/>
</pattern>
`,
showBaseDot: true,
getEmoji: (level: CommitLevel): string | null => {
switch (level) {
case "none":
return null;
case "low":
return "๐Ÿซ˜"; // ์”จ์•—
case "medium":
return "๐ŸŒฑ"; // ์ƒˆ์‹น
case "high":
return "๐ŸŒฟ"; // ํ’€์žŽ
case "max":
return "๐ŸŒป"; // ๊ฝƒ
default:
return null;
}
},
};

export const themes: Record<string, ThemeStyle> = {
hair: HairTheme,
fire: FireTheme,
plant: PlantTheme,
};

export function getCommitLevel(commitCount: number): CommitLevel {
Expand Down