2022-03-26 23:48:19 -04:00
|
|
|
import { escape } from "./dom";
|
|
|
|
|
|
|
|
const tagsToHtml = (tags) => {
|
|
|
|
return tags.map(tagData => {
|
|
|
|
let tagColorClass;
|
2023-02-27 05:22:21 -05:00
|
|
|
const tagLower = tagData.name.toLowerCase();
|
|
|
|
if (tagLower === 'nsfw' || tagLower === 'explicit') {
|
2022-03-26 23:48:19 -04:00
|
|
|
tagColorClass = 'is-danger';
|
2023-02-27 05:22:21 -05:00
|
|
|
} else if (tagLower === 'safe') {
|
2022-03-26 23:48:19 -04:00
|
|
|
tagColorClass = 'is-success';
|
2023-02-27 05:22:21 -05:00
|
|
|
} 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 };
|