Prefix decorate category badges with '#'.

This commit is contained in:
Guo Xiang Tan 2016-01-20 12:42:57 +08:00
parent 9652c3df4f
commit c6697e2c14
2 changed files with 14 additions and 1 deletions

View file

@ -9,6 +9,17 @@ function categoryStripe(color, classes) {
return "<span class='" + classes + "' " + style + "></span>"; return "<span class='" + classes + "' " + style + "></span>";
} }
/**
Generates category badge HTML
@param {Object} category The category to generate the badge for.
@param {Object} opts
@param {String} [opts.url] The url that we want the category badge to link to.
@param {Boolean} [opts.allowUncategorized] If false, returns an empty string for the uncategorized category.
@param {Boolean} [opts.link] If false, the category badge will not be a link.
@param {Boolean} [opts.hideParaent] If true, parent category will be hidden in the badge.
@param {String} [opts.prefix] Prefix the string onto the category name.
**/
export function categoryBadgeHTML(category, opts) { export function categoryBadgeHTML(category, opts) {
opts = opts || {}; opts = opts || {};
@ -50,6 +61,8 @@ export function categoryBadgeHTML(category, opts) {
">"; ">";
var name = escapeExpression(get(category, 'name')); var name = escapeExpression(get(category, 'name'));
if (opts.prefix) name = `${opts.prefix}${name}`;
if (restricted) { if (restricted) {
html += iconHTML('lock') + " " + name; html += iconHTML('lock') + " " + name;
} else { } else {

View file

@ -15,7 +15,7 @@ export function replaceSpan($elem, categorySlug, categoryLink) {
$elem.replaceWith(categorySlug); $elem.replaceWith(categorySlug);
} else { } else {
$elem.replaceWith(categoryBadgeHTML( $elem.replaceWith(categoryBadgeHTML(
category, { url: categoryLink, allowUncategorized: true } category, { url: categoryLink, allowUncategorized: true, prefix: '#' }
)); ));
} }
}; };