ponepaste/js/utils.js

24 lines
793 B
JavaScript
Raw Normal View History

2022-03-26 23:48:19 -04:00
import { escape } from "./dom";
const tagsToHtml = (tags) => {
return tags.map(tagData => {
let tagColorClass;
const tagLower = tagData.name.toLowerCase();
if (tagLower === 'nsfw' || tagLower === 'explicit') {
2022-03-26 23:48:19 -04:00
tagColorClass = 'is-danger';
} else if (tagLower === 'safe') {
2022-03-26 23:48:19 -04:00
tagColorClass = 'is-success';
} else if (tagLower.charAt(0) === '/' && tagLower.charAt(tagLower.length - 1) === '/') {
2022-03-26 23:48:19 -04:00
tagColorClass = 'is-primary';
} else {
tagColorClass = 'is-info';
}
return `<a href="/archive?q=${tagData.slug}">
<span class="tag ${tagColorClass}">${escape(tagData.name)}</span>
</a>`;
}).join('');
};
export { tagsToHtml };