badges: refactoring frontend plugin.

Signed-off-by: Andreas Stenius <git@astekk.se>
This commit is contained in:
Andreas Stenius
2021-02-22 16:23:53 +01:00
committed by Fredrik Adelöw
parent 323ec6f7ca
commit 8bf248799d
16 changed files with 213 additions and 417 deletions
+25
View File
@@ -72,6 +72,31 @@ export interface Config {
* 'for-the-badge' or 'social'.
*/
style?: 'plastic' | 'flat' | 'flat-square' | 'for-the-badge' | 'social';
/**
* Badge title, used as tooltip text in the markdown code.
*
* @visibility frontend
*/
title?: string;
/**
* Badge description, used as alt text in the markdown code.
* Defaults to badge id.
*
* @visibility frontend
*/
description?: string;
/**
* Badge link URL, turns badge into a link in the markdown code.
*
* For `entity` badges, there is a `entity_url` in the context
* that could be appropriate to use here.
*
* @visibility frontend
*/
link?: string;
};
};
}
@@ -54,6 +54,15 @@ export class DefaultBadgeBuilder implements BadgeBuilder {
switch (options.format) {
case 'json':
if (badge.title) {
params.title = this.render(badge.title, context);
}
if (badge.description) {
params.description = this.render(badge.description, context);
}
if (badge.link) {
params.link = this.render(badge.link, context);
}
return JSON.stringify(
{
badge: params,
@@ -21,7 +21,9 @@ export interface BadgeConfig {
color?: string;
labelColor?: string;
style?: 'plastic' | 'flat' | 'flat-square' | 'for-the-badge' | 'social';
links?: [string, string];
title?: string;
description?: string;
link?: string;
}
export type BadgeOptions = {