Files
MartinandMarco Pasqualetti d476f8cbe1 extract "core" package, small improvements (#137)
This PR mainly refactors the code by extracting a "core" package which
is then used by the "backend" and "frontend" apps.

Apart from this the PR also contains several smaller changes like fixing
dependabot, upgrading dependencies, aligned "package.json" files, added
tests, ...

addresses step 1 of #32 
closes #136

---------

Co-authored-by: Marco Pasqualetti <marco.pasqualetti@live.com>
2026-04-18 10:37:26 +02:00

107 lines
3.1 KiB
JavaScript

import fs from "fs";
import { themes } from "../src/themes/index.js";
const TARGET_FILE = "./src/themes/README.md";
const REPO_CARD_LINKS_FLAG = "<!-- REPO_CARD_LINKS -->";
const STAT_CARD_LINKS_FLAG = "<!-- STATS_CARD_LINKS -->";
const STAT_CARD_TABLE_FLAG = "<!-- STATS_CARD_TABLE -->";
const REPO_CARD_TABLE_FLAG = "<!-- REPO_CARD_TABLE -->";
const THEME_TEMPLATE = `## Available Themes
<!-- DO NOT EDIT THIS FILE DIRECTLY -->
With inbuilt themes, you can customize the look of the card without doing any manual customization.
Use \`?theme=THEME_NAME\` parameter like so:
\`\`\`md
![Anurag's GitHub stats](https://github-stats-extended.vercel.app/api?username=anuraghazra&theme=dark&show_icons=true)
\`\`\`
## Stats
> These themes work with all five of our cards: Stats Card, Repo Card, Gist Card, Top Languages Card, and WakaTime Card.
| | | |
| :--: | :--: | :--: |
${STAT_CARD_TABLE_FLAG}
## Repo Card
> These themes work with all five of our cards: Stats Card, Repo Card, Gist Card, Top Languages Card, and WakaTime Card.
| | | |
| :--: | :--: | :--: |
${REPO_CARD_TABLE_FLAG}
${STAT_CARD_LINKS_FLAG}
${REPO_CARD_LINKS_FLAG}
`;
const createRepoMdLink = (theme) => {
return `\n[${theme}_repo]: https://github-stats-extended.vercel.app/api/pin/?username=anuraghazra&repo=github-readme-stats&cache_seconds=86400&theme=${theme}`;
};
const createStatMdLink = (theme) => {
return `\n[${theme}]: https://github-stats-extended.vercel.app/api?username=anuraghazra&show_icons=true&hide=contribs,prs&cache_seconds=86400&theme=${theme}`;
};
const generateLinks = (fn) => {
return Object.keys(themes)
.map((name) => fn(name))
.join("");
};
const createTableItem = ({ link, label, isRepoCard }) => {
if (!link || !label) {
return "";
}
return `\`${label}\` ![${link}][${link}${isRepoCard ? "_repo" : ""}]`;
};
const generateTable = ({ isRepoCard }) => {
const rows = [];
const themesFiltered = Object.keys(themes).filter(
(name) => name !== (isRepoCard ? "default" : "default_repocard"),
);
for (let i = 0; i < themesFiltered.length; i += 3) {
const one = themesFiltered[i];
const two = themesFiltered[i + 1];
const three = themesFiltered[i + 2];
let tableItem1 = createTableItem({ link: one, label: one, isRepoCard });
let tableItem2 = createTableItem({ link: two, label: two, isRepoCard });
let tableItem3 = createTableItem({ link: three, label: three, isRepoCard });
rows.push(`| ${tableItem1} | ${tableItem2} | ${tableItem3} |`);
}
return rows.join("\n");
};
const buildReadme = () => {
return THEME_TEMPLATE.split("\n")
.map((line) => {
if (line.includes(REPO_CARD_LINKS_FLAG)) {
return generateLinks(createRepoMdLink);
}
if (line.includes(STAT_CARD_LINKS_FLAG)) {
return generateLinks(createStatMdLink);
}
if (line.includes(REPO_CARD_TABLE_FLAG)) {
return generateTable({ isRepoCard: true });
}
if (line.includes(STAT_CARD_TABLE_FLAG)) {
return generateTable({ isRepoCard: false });
}
return line;
})
.join("\n");
};
fs.writeFileSync(TARGET_FILE, buildReadme());