Skip to content
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

Feature Request: Add custom languages #4000

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
38 changes: 32 additions & 6 deletions api/top-langs.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export default async (req, res) => {
border_color,
disable_animations,
hide_progress,
lang,
} = req.query;
res.setHeader("Content-Type", "image/svg+xml");

Expand Down Expand Up @@ -62,12 +63,37 @@ export default async (req, res) => {
}

try {
const topLangs = await fetchTopLanguages(
username,
parseArray(exclude_repo),
size_weight,
count_weight,
);
// Check if `lang` parameter is provided
let topLangs;
if (lang) {
// If lang is provided, split the string into an array
const customLangs = lang.split(",");
// Map custom languages to a format similar to the fetched language data
topLangs = customLangs.reduce((acc, curr) => {
acc[curr] = {
name: curr,
color: "#000000", // Assign a default color (you can customize this later)
size: 1, // Default size
count: 1, // Default count
};
return acc;
}, {});
} else {
// Fetch the actual top languages if no custom languages are provided
topLangs = await fetchTopLanguages(
username,
parseArray(exclude_repo),
size_weight,
count_weight,
);
}

// const topLangs = await fetchTopLanguages(
// username,
// parseArray(exclude_repo),
// size_weight,
// count_weight,
// );
Comment on lines +91 to +96
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest to remove this block of dead code.


let cacheSeconds = parseInt(
cache_seconds || CONSTANTS.TOP_LANGS_CACHE_SECONDS,
Expand Down
7 changes: 7 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,13 @@ You can use the `&langs_count=` option to increase or decrease the number of lan
![Top Langs](https://github-readme-stats.vercel.app/api/top-langs/?username=anuraghazra&langs_count=8)
```

### Show Custom Languages
You can now specify custom languages to be displayed using the `&lang=` query parameter. The custom languages will override the automatically fetched top languages. The value should be a comma-separated list of language names. Note that the languages provided in the list will be shown with default settings for color, size, and count.

```md
![Top Langs](https://github-readme-stats.vercel.app/api/top-langs/?username=anuraghazra&lang=python,java,react,javascript,nextjs)
```

### Compact Language Card Layout

You can use the `&layout=compact` option to change the card design.
Expand Down