From c6697e2c14c363b4e7940a8bc2e2e4d898535147 Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Wed, 20 Jan 2016 12:42:57 +0800 Subject: [PATCH] Prefix decorate category badges with '#'. --- .../discourse/helpers/category-link.js.es6 | 13 +++++++++++++ .../discourse/lib/category-hashtags.js.es6 | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/discourse/helpers/category-link.js.es6 b/app/assets/javascripts/discourse/helpers/category-link.js.es6 index bd517eabf81..8d71de3ad80 100644 --- a/app/assets/javascripts/discourse/helpers/category-link.js.es6 +++ b/app/assets/javascripts/discourse/helpers/category-link.js.es6 @@ -9,6 +9,17 @@ function categoryStripe(color, classes) { return ""; } +/** + 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) { opts = opts || {}; @@ -50,6 +61,8 @@ export function categoryBadgeHTML(category, opts) { ">"; var name = escapeExpression(get(category, 'name')); + if (opts.prefix) name = `${opts.prefix}${name}`; + if (restricted) { html += iconHTML('lock') + " " + name; } else { diff --git a/app/assets/javascripts/discourse/lib/category-hashtags.js.es6 b/app/assets/javascripts/discourse/lib/category-hashtags.js.es6 index 2e06ac523a3..9572793c59f 100644 --- a/app/assets/javascripts/discourse/lib/category-hashtags.js.es6 +++ b/app/assets/javascripts/discourse/lib/category-hashtags.js.es6 @@ -15,7 +15,7 @@ export function replaceSpan($elem, categorySlug, categoryLink) { $elem.replaceWith(categorySlug); } else { $elem.replaceWith(categoryBadgeHTML( - category, { url: categoryLink, allowUncategorized: true } + category, { url: categoryLink, allowUncategorized: true, prefix: '#' } )); } };