diff --git a/modules/templates/util_render.go b/modules/templates/util_render.go index c167b32123..f593e1b897 100644 --- a/modules/templates/util_render.go +++ b/modules/templates/util_render.go @@ -105,6 +105,18 @@ func RenderCodeBlock(htmlEscapedTextToRender template.HTML) template.HTML { return template.HTML(htmlWithCodeTags) } +const ( + activeLabelOpacity = uint8(255) + archivedLabelOpacity = uint8(127) +) + +func GetLabelOpacityByte(isArchived bool) uint8 { + if isArchived { + return archivedLabelOpacity + } + return activeLabelOpacity +} + // RenderIssueTitle renders issue/pull title with defined post processors func RenderIssueTitle(ctx context.Context, text string, metas map[string]string) template.HTML { renderedText, err := markup.RenderIssueTitle(&markup.RenderContext{ @@ -126,9 +138,10 @@ func RenderLabel(ctx context.Context, locale translation.Locale, label *issues_m textColor = "#111" labelScope = label.ExclusiveScope() ) - r, g, b := util.HexToRBGColor(label.Color) + // Determine if label text should be light or dark to be readable on background color + // this doesn't account for saturation or transparency if util.UseLightTextOnBackground(r, g, b) { textColor = "#eee" } @@ -142,8 +155,10 @@ func RenderLabel(ctx context.Context, locale translation.Locale, label *issues_m if labelScope == "" { // Regular label + + labelColor := label.Color + hex.EncodeToString([]byte{GetLabelOpacityByte(label.IsArchived())}) s := fmt.Sprintf("