badges: cleanup. enforce all template fields to be lower case. thanx @adamdmharvey

Signed-off-by: Andreas Stenius <git@astekk.se>
This commit is contained in:
Andreas Stenius
2021-02-23 13:43:55 +01:00
committed by Fredrik Adelöw
parent 38cc67e551
commit 0f30b99bc2
3 changed files with 8 additions and 17 deletions
-10
View File
@@ -401,13 +401,3 @@ homepage:
timezone: 'Asia/Tokyo'
pagerduty:
eventsBaseUrl: 'https://events.pagerduty.com/v2'
# sample badges
badges:
lifecycle:
kind: 'entity'
description: 'Entity lifecycle badge'
link: '_{entity_url}'
label: 'lifecycle'
message: '_{entity.spec.lifecycle}'
style: for-the-badge
+3 -5
View File
@@ -20,9 +20,9 @@ export const badges: Badge[] = [
{
id: 'pingback',
kind: 'entity',
description: 'Link back to _{app.title}',
label: '_{app.title}',
message: '_{entity.kind}: _{entity.metadata.name}',
description: 'Link to _{entity.metadata.name} in _{app.title}',
label: '_{entity.kind}',
message: '_{entity.metadata.name}',
style: 'flat-square',
},
{
@@ -39,7 +39,6 @@ export const badges: Badge[] = [
description: 'Entity owner badge',
label: 'owner',
message: '_{entity.spec.owner}',
color: 'blue',
style: 'flat-square',
},
{
@@ -48,7 +47,6 @@ export const badges: Badge[] = [
link: '_{entity_url}/docs',
label: 'docs',
message: '_{entity.metadata.name}',
color: 'navyblue',
style: 'flat-square',
},
];
@@ -100,7 +100,7 @@ export class DefaultBadgeBuilder implements BadgeBuilder {
private render(template: string, context: object): string {
try {
return interpolate(template.replace(/_{/g, '${'), context);
return interpolate(template.replace(/_{/g, '${'), context).toLowerCase();
} catch (err) {
this.logger.info(
`badge template error: ${err}. In template: "${template}"`,
@@ -110,7 +110,10 @@ export class DefaultBadgeBuilder implements BadgeBuilder {
}
private getMarkdownCode(params: Badge, badge_url: string): string {
const alt_text = `${params.description}, ${params.label}: ${params.message}`;
let alt_text = `${params.label}: ${params.message}`;
if (params.description !== params.label) {
alt_text = `${params.description}, ${alt_text}`;
}
const tooltip = params.description ? ` "${params.description}"` : '';
const img = `![${alt_text}](${badge_url}${tooltip})`;
return params.link ? `[${img}](${params.link})` : img;