mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-27 17:16:14 +01:00
refactor: update buildCategoryLabel
This commit is contained in:
@@ -97,15 +97,16 @@ module.exports = function (utils, Benchpress, relative_path) {
|
||||
return `<span class="icon d-inline-flex justify-content-center align-items-center align-middle ${rounded}" style="${generateCategoryBackground(category)} width:${size}; height: ${size}; font-size: ${parseInt(size, 10) / 2}px;">${category.icon ? `<i class="fa fa-fw ${category.icon}"></i>` : ''}</span>`;
|
||||
}
|
||||
|
||||
function buildCategoryLabel(category, className = '') {
|
||||
function buildCategoryLabel(category, tag = 'a', className = '') {
|
||||
if (!category) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return `<span class="badge px-1 ${className} text-truncate" style="color: ${category.color};background-color: ${category.bgColor};border-color: ${category.bgColor}!important; max-width: 70vw;">
|
||||
const href = tag === 'a' ? `href="${relative_path}/category/${category.slug}"` : '';
|
||||
return `<${tag} ${href} class="badge px-1 text-truncate text-decoration-none ${className}" style="color: ${category.color};background-color: ${category.bgColor};border-color: ${category.bgColor}!important; max-width: 70vw;">
|
||||
${category.icon && category.icon !== 'fa-nbb-none' ? `<i class="fa fa-fw ${category.icon}"></i>` : ''}
|
||||
${category.name}
|
||||
</span>`;
|
||||
</${tag}>`;
|
||||
}
|
||||
|
||||
function generateCategoryBackground(category) {
|
||||
|
||||
Reference in New Issue
Block a user