Skip to content

Commit 7c1730e

Browse files
refactor: README theme generation logic (#485)
Co-authored-by: Ansh_sharma <[email protected]>
1 parent b35cbfe commit 7c1730e

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

scripts/generate-theme-doc.ts

+19-13
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,29 @@ function generateThemeLink(username: string, theme: string): string {
1111
return `[${theme}]: https://github-readme-profile-alpha.vercel.app/api?username=${username}&theme=${theme}`;
1212
}
1313

14+
function createThemeRows(
15+
themesArray: string[],
16+
itemsPerRow: number,
17+
username: string
18+
): { themesPreviewTable: string; themesPreviewLink: string } {
19+
let themesPreviewTable = "";
20+
let themesPreviewLink = "";
21+
22+
for (let i = 0; i < themesArray.length; i += itemsPerRow) {
23+
const rowThemes = themesArray.slice(i, i + itemsPerRow);
24+
25+
themesPreviewTable += `| ${rowThemes.map(generateThemeMarkdown).join(" | ")} |\n`;
26+
themesPreviewLink += rowThemes.map(theme => generateThemeLink(username, theme)).join("\n") + "\n";
27+
}
28+
29+
return { themesPreviewTable, themesPreviewLink };
30+
}
31+
1432
export function generateReadmeThemes(username: string): string {
1533
const availableThemes = Object.keys(themes);
1634
const itemsPerRow = 3;
1735

18-
let themesPreviewTable = "";
19-
for (let i = 0; i < availableThemes.length; i += itemsPerRow) {
20-
const themesSlice = availableThemes.slice(i, i + itemsPerRow);
21-
const row = themesSlice.map(theme => generateThemeMarkdown(theme)).join(" | ");
22-
themesPreviewTable += `| ${row} |\n`;
23-
}
24-
25-
let themesPreviewLink = "";
26-
for (let i = 0; i < availableThemes.length; i += 1) {
27-
const themesSlice = availableThemes.slice(i, i + 1);
28-
const row = themesSlice.map(theme => generateThemeLink(username, theme)).join("\n");
29-
themesPreviewLink += `${row}\n`;
30-
}
36+
const { themesPreviewTable, themesPreviewLink } = createThemeRows(availableThemes, itemsPerRow, username);
3137

3238
const readmeContent = `<!-- DO NOT EDIT THIS FILE DIRECTLY -->
3339
## Available Themes

0 commit comments

Comments
 (0)