Skip to content

refactor: README theme generation logic #485

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

Merged
merged 2 commits into from
Oct 26, 2024
Merged
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
32 changes: 19 additions & 13 deletions scripts/generate-theme-doc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,29 @@ function generateThemeLink(username: string, theme: string): string {
return `[${theme}]: https://github-readme-profile-alpha.vercel.app/api?username=${username}&theme=${theme}`;
}

function createThemeRows(
themesArray: string[],
itemsPerRow: number,
username: string
): { themesPreviewTable: string; themesPreviewLink: string } {
let themesPreviewTable = "";
let themesPreviewLink = "";

for (let i = 0; i < themesArray.length; i += itemsPerRow) {
const rowThemes = themesArray.slice(i, i + itemsPerRow);

themesPreviewTable += `| ${rowThemes.map(generateThemeMarkdown).join(" | ")} |\n`;
themesPreviewLink += rowThemes.map(theme => generateThemeLink(username, theme)).join("\n") + "\n";
}

return { themesPreviewTable, themesPreviewLink };
}

export function generateReadmeThemes(username: string): string {
const availableThemes = Object.keys(themes);
const itemsPerRow = 3;

let themesPreviewTable = "";
for (let i = 0; i < availableThemes.length; i += itemsPerRow) {
const themesSlice = availableThemes.slice(i, i + itemsPerRow);
const row = themesSlice.map(theme => generateThemeMarkdown(theme)).join(" | ");
themesPreviewTable += `| ${row} |\n`;
}

let themesPreviewLink = "";
for (let i = 0; i < availableThemes.length; i += 1) {
const themesSlice = availableThemes.slice(i, i + 1);
const row = themesSlice.map(theme => generateThemeLink(username, theme)).join("\n");
themesPreviewLink += `${row}\n`;
}
const { themesPreviewTable, themesPreviewLink } = createThemeRows(availableThemes, itemsPerRow, username);

const readmeContent = `<!-- DO NOT EDIT THIS FILE DIRECTLY -->
## Available Themes
Expand Down
Loading