client/tags: fix tag categories with spaces
This commit is contained in:
parent
1c5f44a91c
commit
1a75c61f65
6 changed files with 21 additions and 9 deletions
|
@ -50,14 +50,14 @@
|
||||||
--><% for (let tag of ctx.post.tags) { %><!--
|
--><% for (let tag of ctx.post.tags) { %><!--
|
||||||
--><li><!--
|
--><li><!--
|
||||||
--><% if (ctx.canViewTags) { %><!--
|
--><% if (ctx.canViewTags) { %><!--
|
||||||
--><a href='/tag/<%= tag %>' class='tag-<%= ctx.getTagCategory(tag) %>'><!--
|
--><a href='/tag/<%= tag %>' class='<%= ctx.makeCssName(ctx.getTagCategory(tag), 'tag') %>'><!--
|
||||||
--><i class='fa fa-tag'></i><!--
|
--><i class='fa fa-tag'></i><!--
|
||||||
--><% } %><!--
|
--><% } %><!--
|
||||||
--><% if (ctx.canListPosts) { %><!--
|
--><% if (ctx.canListPosts) { %><!--
|
||||||
--></a><!--
|
--></a><!--
|
||||||
--><% } %><!--
|
--><% } %><!--
|
||||||
--><% if (ctx.canListPosts) { %><!--
|
--><% if (ctx.canListPosts) { %><!--
|
||||||
--><a href='/posts/text=<%= tag %>' class='tag-<%= ctx.getTagCategory(tag) %>'><!--
|
--><a href='/posts/text=<%= tag %>' class='<%= ctx.makeCssName(ctx.getTagCategory(tag), 'tag') %>'><!--
|
||||||
--><% } %><!--
|
--><% } %><!--
|
||||||
--><%= tag %><!--
|
--><%= tag %><!--
|
||||||
--><% if (ctx.canListPosts) { %><!--
|
--><% if (ctx.canListPosts) { %><!--
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const unindent = require('../util/misc.js').unindent;
|
|
||||||
const tags = require('../tags.js');
|
const tags = require('../tags.js');
|
||||||
|
const misc = require('../util/misc.js');
|
||||||
const AutoCompleteControl = require('./auto_complete_control.js');
|
const AutoCompleteControl = require('./auto_complete_control.js');
|
||||||
|
|
||||||
class TagAutoCompleteControl extends AutoCompleteControl {
|
class TagAutoCompleteControl extends AutoCompleteControl {
|
||||||
|
@ -31,9 +31,10 @@ class TagAutoCompleteControl extends AutoCompleteControl {
|
||||||
const category = kv[1].category;
|
const category = kv[1].category;
|
||||||
const origName = tags.getOriginalTagName(kv[0]);
|
const origName = tags.getOriginalTagName(kv[0]);
|
||||||
const usages = kv[1].usages;
|
const usages = kv[1].usages;
|
||||||
|
const cssName = misc.makeCssName(category, 'tag');
|
||||||
return {
|
return {
|
||||||
caption: unindent`
|
caption: misc.unindent`
|
||||||
<span class="tag-${category}">
|
<span class="${cssName}">
|
||||||
${origName} (${usages})
|
${origName} (${usages})
|
||||||
</span>`,
|
</span>`,
|
||||||
value: kv[0],
|
value: kv[0],
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
const api = require('../api.js');
|
const api = require('../api.js');
|
||||||
const tags = require('../tags.js');
|
const tags = require('../tags.js');
|
||||||
|
const misc = require('../util/misc.js');
|
||||||
const views = require('../util/views.js');
|
const views = require('../util/views.js');
|
||||||
const TagAutoCompleteControl = require('./tag_auto_complete_control.js');
|
const TagAutoCompleteControl = require('./tag_auto_complete_control.js');
|
||||||
|
|
||||||
|
@ -437,7 +438,9 @@ class TagInputControl {
|
||||||
views.makeNonVoidElement(
|
views.makeNonVoidElement(
|
||||||
'a',
|
'a',
|
||||||
{
|
{
|
||||||
class: actualTag ? 'tag-' + actualTag.category : '',
|
class: actualTag ?
|
||||||
|
misc.makeCssName(actualTag.category, 'tag') :
|
||||||
|
'',
|
||||||
href: '/tag/' + text,
|
href: '/tag/' + text,
|
||||||
},
|
},
|
||||||
text));
|
text));
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const misc = require('./util/misc.js');
|
||||||
const request = require('superagent');
|
const request = require('superagent');
|
||||||
|
|
||||||
let _tags = null;
|
let _tags = null;
|
||||||
|
@ -63,8 +64,9 @@ function _refreshStylesheet() {
|
||||||
_stylesheet = document.createElement('style');
|
_stylesheet = document.createElement('style');
|
||||||
document.head.appendChild(_stylesheet);
|
document.head.appendChild(_stylesheet);
|
||||||
for (let category of getAllCategories()) {
|
for (let category of getAllCategories()) {
|
||||||
|
const ruleName = misc.makeCssName(category.name, 'tag');
|
||||||
_stylesheet.sheet.insertRule(
|
_stylesheet.sheet.insertRule(
|
||||||
`.tag-${category.name} { color: ${category.color} }`,
|
`.${ruleName} { color: ${category.color} }`,
|
||||||
_stylesheet.sheet.cssRules.length);
|
_stylesheet.sheet.cssRules.length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -220,6 +220,10 @@ function confirmPageExit() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function makeCssName(text, suffix) {
|
||||||
|
return suffix + '-' + text.replace(/[^a-z0-9]/g, '_');
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
range: range,
|
range: range,
|
||||||
formatSearchQuery: formatSearchQuery,
|
formatSearchQuery: formatSearchQuery,
|
||||||
|
@ -232,4 +236,5 @@ module.exports = {
|
||||||
enableExitConfirmation: enableExitConfirmation,
|
enableExitConfirmation: enableExitConfirmation,
|
||||||
disableExitConfirmation: disableExitConfirmation,
|
disableExitConfirmation: disableExitConfirmation,
|
||||||
confirmPageExit: confirmPageExit,
|
confirmPageExit: confirmPageExit,
|
||||||
|
makeCssName: makeCssName,
|
||||||
};
|
};
|
||||||
|
|
|
@ -154,11 +154,11 @@ function makeTagLink(name) {
|
||||||
makeNonVoidElement(
|
makeNonVoidElement(
|
||||||
'a', {
|
'a', {
|
||||||
'href': '/tag/' + name,
|
'href': '/tag/' + name,
|
||||||
'class': 'tag-' + category,
|
'class': misc.makeCssName(category, 'tag'),
|
||||||
}, name) :
|
}, name) :
|
||||||
makeNonVoidElement(
|
makeNonVoidElement(
|
||||||
'span', {
|
'span', {
|
||||||
'class': 'tag-' + category,
|
'class': misc.makeCssName(category, 'tag'),
|
||||||
},
|
},
|
||||||
name);
|
name);
|
||||||
}
|
}
|
||||||
|
@ -312,6 +312,7 @@ function getTemplate(templatePath) {
|
||||||
makeUserLink: makeUserLink,
|
makeUserLink: makeUserLink,
|
||||||
makeFlexboxAlign: makeFlexboxAlign,
|
makeFlexboxAlign: makeFlexboxAlign,
|
||||||
makeAccessKey: makeAccessKey,
|
makeAccessKey: makeAccessKey,
|
||||||
|
makeCssName: misc.makeCssName,
|
||||||
});
|
});
|
||||||
return htmlToDom(templateFactory(ctx));
|
return htmlToDom(templateFactory(ctx));
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue