Skip to content

Commit

Permalink
fix: update script for generate theme readme (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
FajarKim authored Nov 12, 2023
1 parent 0998463 commit 620e03e
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions scripts/generate-theme-doc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@ import fs from "fs";
import { themes } from '../themes/index';

const TARGET_FILE = "./themes/README.md";

// Function to generate the markdown for themes
function generateThemeMarkdown(username: string, theme: string, itemsPerRow: number = 3): string {
return `\`${theme}\` [![${theme}](https://github-readme-profile-alpha.vercel.app/api?username=${username}&theme=${theme})](https://github-readme-profile-alpha.vercel.app/api?username=${username}&theme=${theme})`;
function generateThemeMarkdown(theme: string): string {
return `\`${theme}\` ![${theme}][${theme}]`;
}

// Function to generate themes preview link
function generateThemeLink(username: string, theme: string): string {
return `[${theme}]: https://github-readme-profile-alpha.vercel.app/api?username=${username}&theme=${theme}`
}

// Function to generate README.md content
Expand All @@ -15,10 +21,17 @@ function generateReadme(username: string): string {
let themesPreviewTable = '';
for (let i = 0; i < availableThemes.length; i += itemsPerRow) {
const themesSlice = availableThemes.slice(i, i + itemsPerRow);
const row = themesSlice.map(theme => generateThemeMarkdown(username, theme)).join(' | ');
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 readmeContent = `<!-- DO NOT EDIT THIS FILE DIRECTLY -->
## Available Themes
Expand All @@ -27,7 +40,7 @@ With inbuilt themes, you can customize the look of the card without doing any ma
Use \`?theme=THEME_NAME\` parameter like so :-
\`\`\`md
![GitHub Profile](https://github-readme-profile-alpha.vercel.app/api?username=${username}&theme=dark)
![GitHub Profile](https://gh-readme-profile.vercel.app/api?username=${username}&theme=dark)
\`\`\`
## Themes Preview
Expand All @@ -37,7 +50,8 @@ Use \`?theme=THEME_NAME\` parameter like so :-
${themesPreviewTable}
Want to add a new theme? Consider reading the [contribution guidelines](/CONTRIBUTING.md#-themes-contribution) :D
`;
${themesPreviewLink}`;

return readmeContent;
}
Expand Down

0 comments on commit 620e03e

Please sign in to comment.