refactor: update buildCategoryLabel

This commit is contained in:
Barış Soner Uşaklı
2023-10-02 10:38:47 -04:00
parent 56b31674e1
commit 82ea91920a

View File

@@ -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) {