add ability to set title of all cards

This commit is contained in:
Domai 2023-06-13 12:30:37 +02:00
parent 9168dc0ff8
commit c3bac21c32
No known key found for this signature in database
GPG key ID: 8F0CBA9FA6CBDB53
4 changed files with 14 additions and 9 deletions

View file

@ -15,6 +15,7 @@ export interface query {
icon_color?: string icon_color?: string
text_color?: string text_color?: string
cache_seconds?: string cache_seconds?: string
title?: string
// Mater // Mater
bg_color?: string bg_color?: string
@ -34,6 +35,7 @@ export default async (req: Request<unknown, unknown, unknown, query>, res: Respo
icon_color, icon_color,
text_color, text_color,
cache_seconds, cache_seconds,
title,
// Master // Master
bg_color, bg_color,
@ -59,11 +61,12 @@ export default async (req: Request<unknown, unknown, unknown, query>, res: Respo
hide_border: parseBoolean(hide_border), hide_border: parseBoolean(hide_border),
hide_rank: parseBoolean(hide_rank), hide_rank: parseBoolean(hide_rank),
line_height: parseNumber(line_height), line_height: parseNumber(line_height),
title,
title_color, title_color,
icon_color, icon_color,
text_color, text_color,
bg_color, bg_color,
theme theme,
}).render() }).render()
)) ))
} catch (err) { } catch (err) {

View file

@ -20,6 +20,7 @@ export interface query {
theme?: keyof typeof themes theme?: keyof typeof themes
cache_seconds?: string cache_seconds?: string
layout?: string layout?: string
title?: string
} }
export default async (req: Request<unknown, unknown, unknown, query>, res: Response) => { export default async (req: Request<unknown, unknown, unknown, query>, res: Response) => {
@ -35,7 +36,8 @@ export default async (req: Request<unknown, unknown, unknown, query>, res: Respo
language_count, language_count,
theme, theme,
cache_seconds, cache_seconds,
layout layout,
title,
} = req.query } = req.query
prepareResponse(res) prepareResponse(res)
@ -53,6 +55,7 @@ export default async (req: Request<unknown, unknown, unknown, query>, res: Respo
layout, layout,
text_color, text_color,
theme, theme,
title,
title_color, title_color,
bg_color, bg_color,
hide_border: parseBoolean(hide_border), hide_border: parseBoolean(hide_border),

View file

@ -18,6 +18,7 @@ interface ProfileCardOptions extends CardOptions {
line_height?: number line_height?: number
icon_color?: string icon_color?: string
text_color?: string text_color?: string
title?: string
} }
export default class ProfileCard extends Card { export default class ProfileCard extends Card {
@ -39,9 +40,8 @@ export default class ProfileCard extends Card {
private recentXp: number, private recentXp: number,
private options: ProfileCardOptions private options: ProfileCardOptions
) { ) {
super(
options super(options)
)
// This Element // This Element
this.stats = { this.stats = {
@ -64,7 +64,7 @@ export default class ProfileCard extends Card {
options.hide_rank ? 0 : 120 options.hide_rank ? 0 : 120
) )
this.title = `${encodeHTML(this.username)}${ this.title = this.options.title ?? `${encodeHTML(this.username)}${
['x', 's'].includes(this.username.slice(-1)) ? '\'' : '\'s' ['x', 's'].includes(this.username.slice(-1)) ? '\'' : '\'s'
} Code::Stats Profile` } Code::Stats Profile`

View file

@ -10,6 +10,7 @@ interface TopLanguagesOptions extends CardOptions {
card_width?: number card_width?: number
layout?: string layout?: string
text_color?: string text_color?: string
title?: string
} }
export default class TopLanguagesCard extends Card { export default class TopLanguagesCard extends Card {
@ -21,12 +22,10 @@ export default class TopLanguagesCard extends Card {
) { ) {
super(options) super(options)
this.langs = this.langs this.langs = this.langs
.filter((item) => !(options.hide || []).includes(item.name)) .filter((item) => !(options.hide || []).includes(item.name))
.slice(0, options.language_count || 5) .slice(0, options.language_count || 5)
this.height = 45 + (this.langs.length + 1) * 40 this.height = 45 + (this.langs.length + 1) * 40
this.width = 300 this.width = 300
if (options.card_width && !isNaN(options.card_width)) { if (options.card_width && !isNaN(options.card_width)) {
@ -34,7 +33,7 @@ export default class TopLanguagesCard extends Card {
} }
const textColor = getColor('text_color', options.text_color, options.theme) const textColor = getColor('text_color', options.text_color, options.theme)
this.title = 'Most Used Languages' this.title = this.options.title ?? 'Most Used Languages'
this.css = CompactTextNode.getCSS(textColor as string) this.css = CompactTextNode.getCSS(textColor as string)
} }