Skip to content

Commit

Permalink
feat: limit langs shown on wakatime card (anuraghazra#988)
Browse files Browse the repository at this point in the history
  • Loading branch information
florianbussmann authored Apr 26, 2021
1 parent 9551f1c commit 9773d92
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions api/wakatime.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ module.exports = async (req, res) => {
custom_title,
locale,
layout,
langs_count,
api_domain,
range,
border_radius,
Expand Down Expand Up @@ -66,6 +67,7 @@ module.exports = async (req, res) => {
border_radius,
locale: locale ? locale.toLowerCase() : null,
layout,
langs_count,
}),
);
} catch (err) {
Expand Down
1 change: 1 addition & 0 deletions docs/readme_de.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ Du kannst mehrere, mit Kommas separierte, Werte in der bg_color Option angeben,
- `hide_progress` - Verbirgt die Fortschrittanzeige und Prozentzahl _(boolean)_
- `custom_title` - Legt einen benutzerdefinierten Titel fest
- `layout` - Wechselt zwischen zwei verschiedenen Layouts: `default` & `compact`
- `langs_count` - Begrenzt die Anzahl der angezeigten Sprachen auf der Karte
- `api_domain` - Legt eine benutzerdefinierte API Domain fest, z.B. für [Hakatime](https://github.com/mujx/hakatime) oder [Wakapi](https://github.com/muety/wakapi)
- `range` – Fragt eine eine Zeitspanne an, als die standardmäßig in WakaTime hinterlegte, z.B. `last_7_days`. Siehe [WakaTime API Dokumentation](https://wakatime.com/developers#stats).

Expand Down
1 change: 1 addition & 0 deletions docs/readme_es.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ Puedes pasar mútliples valores separados por coma en la opción `bg_color` para
- `hide_progress` - Oculta la barra de progreso y el porcentaje _(booleano)_
- `custom_title` - Establece un título personalizado
- `layout` - Cambia entre los dos diseños disponibles `default` & `compact`
- `langs_count` - Limita el número de idiomas que aparecen en el mapa
- `api_domain` - Establece un dominio de API personalizado para la tarjeta

---
Expand Down
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ You can provide multiple comma-separated values in bg_color option to render a g
- `hide_progress` - Hides the progress bar and percentage _(boolean)_
- `custom_title` - Sets a custom title for the card
- `layout` - Switch between two available layouts `default` & `compact`
- `langs_count` - Limit number of languages on the card, defaults to all reported langauges
- `api_domain` - Set a custom API domain for the card, e.g. to use services like [Hakatime](https://github.com/mujx/hakatime) or [Wakapi](https://github.com/muety/wakapi)
- `range` – Request a range different from your WakaTime default, e.g. `last_7_days`. See [WakaTime API docs](https://wakatime.com/developers#stats) for list of available options.

Expand Down
6 changes: 5 additions & 1 deletion src/cards/wakatime-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const Card = require("../common/Card");
const I18n = require("../common/I18n");
const { getStyles } = require("../getStyles");
const { wakatimeCardLocales } = require("../translations");
const { getCardColors, FlexLayout } = require("../common/utils");
const { clampValue, getCardColors, FlexLayout } = require("../common/utils");
const { createProgressNode } = require("../common/createProgressNode");
const languageColors = require("../common/languageColors.json");

Expand Down Expand Up @@ -99,6 +99,7 @@ const renderWakatimeCard = (stats = {}, options = { hide: [] }) => {
custom_title,
locale,
layout,
langs_count = languages ? languages.length : 0,
border_radius
} = options;

Expand All @@ -109,6 +110,8 @@ const renderWakatimeCard = (stats = {}, options = { hide: [] }) => {

const lheight = parseInt(line_height, 10);

langsCount = clampValue(parseInt(langs_count), 1, langs_count);

// returns theme based colors with proper overrides and defaults
const { titleColor, textColor, iconColor, bgColor } = getCardColors({
title_color,
Expand All @@ -121,6 +124,7 @@ const renderWakatimeCard = (stats = {}, options = { hide: [] }) => {
const statItems = languages
? languages
.filter((language) => language.hours || language.minutes)
.slice(0, langsCount)
.map((language) => {
return createTextNode({
id: language.name,
Expand Down

0 comments on commit 9773d92

Please sign in to comment.