Revert "Update generate-theme-doc.js (#3308)" (#3353)

This reverts commit 28b65928d2.
This commit is contained in:
Rick Staa 2023-10-13 17:04:42 +02:00 committed by GitHub
parent 28b65928d2
commit 7b1b78df2f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2,14 +2,11 @@ import fs from "fs";
import { themes } from "../themes/index.js";
const TARGET_FILE = "./themes/README.md";
const LINKS_FLAG_MAP = {
repo: "<!-- REPO_CARD_LINKS -->",
stats: "<!-- STATS_CARD_LINKS -->",
};
const TABLE_FLAG_MAP = {
repo: "<!-- REPO_CARD_TABLE -->",
stats: "<!-- STATS_CARD_TABLE -->",
};
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
@ -17,7 +14,7 @@ const THEME_TEMPLATE = `## Available Themes
With inbuilt themes, you can customize the look of the card without doing any manual customization.
Use \`?theme=THEME_NAME\` parameter like so:
Use \`?theme=THEME_NAME\` parameter like so :-
\`\`\`md
![Anurag's GitHub stats](https://github-readme-stats.vercel.app/api?username=anuraghazra&theme=dark&show_icons=true)
@ -29,7 +26,7 @@ Use \`?theme=THEME_NAME\` parameter like so:
| | | |
| :--: | :--: | :--: |
${TABLE_FLAG_MAP.stats}
${STAT_CARD_TABLE_FLAG}
## Repo Card
@ -37,36 +34,36 @@ ${TABLE_FLAG_MAP.stats}
| | | |
| :--: | :--: | :--: |
${TABLE_FLAG_MAP.repo}
${REPO_CARD_TABLE_FLAG}
${LINKS_FLAG_MAP.stats}
${STAT_CARD_LINKS_FLAG}
${REPO_CARD_LINKS_FLAG}
${LINKS_FLAG_MAP.repo}
[add-theme]: https://github.com/anuraghazra/github-readme-stats/edit/master/themes/index.js
Want to add a new theme? Consider reading the [contribution guidelines](../CONTRIBUTING.md#themes-contribution) :D
`;
const createMdLink = (theme, type) => {
const baseLink =
type === "repo"
? "api/pin/?username=anuraghazra&repo=github-readme-stats"
: "api?username=anuraghazra";
return `\n[${theme}]: https://github-readme-stats.vercel.app/${baseLink}&cache_seconds=86400&theme=${theme}`;
const createRepoMdLink = (theme) => {
return `\n[${theme}_repo]: https://github-readme-stats.vercel.app/api/pin/?username=anuraghazra&repo=github-readme-stats&cache_seconds=86400&theme=${theme}`;
};
const createStatMdLink = (theme) => {
return `\n[${theme}]: https://github-readme-stats.vercel.app/api?username=anuraghazra&show_icons=true&hide=contribs,prs&cache_seconds=86400&theme=${theme}`;
};
const generateLinks = (type) => {
const generateLinks = (fn) => {
return Object.keys(themes)
.map((name) => createMdLink(name, type))
.map((name) => fn(name))
.join("");
};
const createTableItem = ({ link, label }) => {
const createTableItem = ({ link, label, isRepoCard }) => {
if (!link || !label) {
return "";
}
return `\`${label}\` ![${link}][${link}]`;
return `\`${label}\` ![${link}][${link}${isRepoCard ? "_repo" : ""}]`;
};
const generateTable = ({ isRepoCard }) => {
@ -76,23 +73,22 @@ const generateTable = ({ isRepoCard }) => {
);
for (let i = 0; i < themesFiltered.length; i += 3) {
const [one, two, three] = themesFiltered.slice(i, i + 3);
const one = themesFiltered[i];
const two = themesFiltered[i + 1];
const three = themesFiltered[i + 2];
const tableItem1 = createTableItem({ link: one, label: one });
const tableItem2 = createTableItem({ link: two, label: two });
const tableItem3 = createTableItem({ link: three, label: three });
let tableItem1 = createTableItem({ link: one, label: one, isRepoCard });
let tableItem2 = createTableItem({ link: two, label: two, isRepoCard });
let tableItem3 = createTableItem({ link: three, label: three, isRepoCard });
if (i + 3 >= themesFiltered.length) {
// If last row add your theme placeholder.
if (!three) {
rows.push(
` ${tableItem1} | ${tableItem2} | [Add your theme][add-theme] |`,
);
} else {
rows.push(`| [Add your theme][add-theme] | | |`);
}
} else {
rows.push(`| ${tableItem1} | ${tableItem2} | ${tableItem3} |`);
if (three === undefined) {
tableItem3 = `[Add your theme][add-theme]`;
}
rows.push(`| ${tableItem1} | ${tableItem2} | ${tableItem3} |`);
// if it's the last row & the row has no empty space push a new row
if (three && i + 3 === themesFiltered.length) {
rows.push(`| [Add your theme][add-theme] | | |`);
}
}
@ -102,16 +98,16 @@ const generateTable = ({ isRepoCard }) => {
const buildReadme = () => {
return THEME_TEMPLATE.split("\n")
.map((line) => {
if (line.includes(LINKS_FLAG_MAP.repo)) {
return generateLinks("repo");
if (line.includes(REPO_CARD_LINKS_FLAG)) {
return generateLinks(createRepoMdLink);
}
if (line.includes(LINKS_FLAG_MAP.stats)) {
return generateLinks("stats");
if (line.includes(STAT_CARD_LINKS_FLAG)) {
return generateLinks(createStatMdLink);
}
if (line.includes(TABLE_FLAG_MAP.repo)) {
if (line.includes(REPO_CARD_TABLE_FLAG)) {
return generateTable({ isRepoCard: true });
}
if (line.includes(TABLE_FLAG_MAP.stats)) {
if (line.includes(STAT_CARD_TABLE_FLAG)) {
return generateTable({ isRepoCard: false });
}
return line;
@ -120,5 +116,3 @@ const buildReadme = () => {
};
fs.writeFileSync(TARGET_FILE, buildReadme());
console.log("README.md updated successfully!");