Skip to content

Commit 78cde58

Browse files
committed
frontend(generate.ts): add a new UriBuilder class that generates the URL more appropriately
1 parent c87c491 commit 78cde58

File tree

10 files changed

+118
-22
lines changed

10 files changed

+118
-22
lines changed

client/build/asset-manifest.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/build/index.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/build/static/css/main.2ae52a35.css renamed to client/build/static/css/main.56bc42f2.css

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/build/static/css/main.2ae52a35.css.map renamed to client/build/static/css/main.56bc42f2.css.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/build/static/js/main.1f52111a.js renamed to client/build/static/js/main.15f7edbf.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/build/static/js/main.1f52111a.js.map renamed to client/build/static/js/main.15f7edbf.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/src/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const App = () => {
1212
<div className="bg-gh-bg w-full min-h-screen overflow-x-hidden select-none pb-5">
1313
<Header />
1414

15-
<main className="flex gap-4 mx-4 md:mx-40 mt-6 flex-col lg:flex-row">
15+
<main className="flex gap-4 mx-4 md:mx-32 lg:mx-40 mt-6 flex-col lg:flex-row">
1616
<Options setLink={(link: string) => setLink(link)} />
1717
<Preview link={link} />
1818
</main>

client/src/utils/generate.ts

Lines changed: 102 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,95 @@
1-
import { Card } from "../types/card";
1+
import { Card, newCard } from "../types/card";
2+
3+
class UrlBuilder {
4+
private url: string;
5+
private defaultCard: Card;
6+
7+
public constructor() {
8+
this.url = "https://github-readme-tech-stack.vercel.app/api/cards?";
9+
this.defaultCard = newCard();
10+
}
11+
12+
public title(title: string): UrlBuilder {
13+
if (title === this.defaultCard.title) {
14+
return this;
15+
}
16+
17+
this.url += `title=${encodeURI(title)}&`;
18+
return this;
19+
}
20+
21+
public theme(theme: string): UrlBuilder {
22+
if (theme === this.defaultCard.theme) {
23+
return this;
24+
}
25+
26+
this.url += `theme=${theme}&`;
27+
return this;
28+
}
29+
30+
public showBorder(showBorder: boolean): UrlBuilder {
31+
if (showBorder === this.defaultCard.showBorder) {
32+
return this;
33+
}
34+
35+
this.url += `showBorder=${showBorder}&`;
36+
return this;
37+
}
38+
39+
public align(align: string): UrlBuilder {
40+
if (align === this.defaultCard.align) {
41+
return this;
42+
}
43+
44+
this.url += `align=${align}&`;
45+
return this;
46+
}
47+
48+
public borderRadius(borderRadius: string): UrlBuilder {
49+
if (borderRadius === this.defaultCard.borderRadius) {
50+
return this;
51+
}
52+
53+
this.url += `borderRadius=${borderRadius}&`;
54+
return this;
55+
}
56+
57+
public fontSize(fontSize: string): UrlBuilder {
58+
if (fontSize === this.defaultCard.fontSize) {
59+
return this;
60+
}
61+
62+
this.url += `fontSize=${fontSize}&`;
63+
return this;
64+
}
65+
66+
public fontWeight(fontWeight: string): UrlBuilder {
67+
if (fontWeight === this.defaultCard.fontWeight) {
68+
return this;
69+
}
70+
71+
this.url += `fontWeight=${fontWeight}&`;
72+
return this;
73+
}
74+
75+
public fontFamily(fontFamily: string): UrlBuilder {
76+
if (fontFamily === this.defaultCard.fontFamily) {
77+
return this;
78+
}
79+
80+
this.url += `fontFamily=${encodeURI(fontFamily)}&`;
81+
return this;
82+
}
83+
84+
public build(): string {
85+
const lastChar = this.url.at(-1);
86+
if (lastChar === "?" || lastChar === "&") {
87+
this.url = this.url.slice(0, -1);
88+
}
89+
90+
return this.url;
91+
}
92+
}
293

394
export const generateLink = ({
495
title,
@@ -11,11 +102,16 @@ export const generateLink = ({
11102
fontSize,
12103
fontFamily,
13104
}: Card): string => {
14-
// replace every space with %20
15-
title = title.replace(/[ ]/g, "%20");
16-
fontFamily = fontFamily.replace(/[ ]/g, "%20");
17-
18-
let res = `https://github-readme-tech-stack.vercel.app/api/cards?title=${title}&lineCount=${lines.length}&theme=${theme}&align=${align}&showBorder=${showBorder}&borderRadius=${borderRadius}&fontSize=${fontSize}&fontWeight=${fontWeight}&fontFamily=${fontFamily}`;
105+
let res = new UrlBuilder()
106+
.title(title)
107+
.align(align)
108+
.borderRadius(borderRadius)
109+
.fontFamily(fontFamily)
110+
.fontSize(fontSize)
111+
.fontWeight(fontWeight)
112+
.showBorder(showBorder)
113+
.theme(theme)
114+
.build();
19115

20116
for (const l of lines) {
21117
// if the line doesn't contain badges

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "github-readme-tech-stack",
3-
"version": "1.2.6",
3+
"version": "1.2.7",
44
"description": "Dynamically generated, customizable technologies cards for your GitHub README.",
55
"main": "src/app.ts",
66
"scripts": {

0 commit comments

Comments
 (0)