<script type="text/javascript"> var alltags = document.getElementsByClassName('tag-cloud-tags'); var tags = alltags[0].getElementsByTagName('a'); for (var i = tags.length - 1; i >= 0; i--) { var golden_ratio = 0.618033988749895; var s = 0.5; var v = 0.999; var h = golden_ratio + Math.random()*0.8 - 0.5; var h_i = parseInt(h * 6); var f = h * 6 - h_i; var p = v * (1 - s); var q = v * (1 - f * s); var t = v * (1 - (1 - f) * s); var r, g, b; switch (h_i) { case0: r = v; g = t; b = p; break; case1: r = q; g = v; b = p; break; case2: r = p; g = v; b = t; break; case3 : r = p; g = q; b = v; break; case4: r = t; g = p; b = v; break; case5: r = v; g = p; b = q; break; default: r = 1; g = 1; b = 1; } tags[i].style.background = "rgba("+parseInt(r*255)+","+parseInt(g*255)+","+parseInt(b*255)+","+0.7+")"; } </script> <style> .tag-cloud-tags{ text-align: center; counter-reset: tags; } .tag-cloud-tagsa{ display: inline-block; border: 0px; border-radius: 10px; padding: 0px10px; margin: 8px; color: rgba(34, 34, 34, 0.8); } /* 文字前添加相应的符号,content后的Unicode可以自定义*/ .tag-cloud-tagsa:before{ font-family: 'Font Awesome 5 Free'; content: "\f02b"; font-weight: 900; } .tag-cloud-tagsa:hover{ box-shadow: 0px5px15px0pxrgba(0,0,0,.4); transform: scale(1.1); transition-duration: 0.15s; } </style>
然后在node_modules\hexo-theme-next\layout\page.njk中以下位置添加{% include 'tag-color.njk' %}
1 2 3 4 5 6 7 8 9 10 11 12 13
<div class="post-body{% if page.direction and page.direction.toLowerCase() === 'rtl' %} rtl{% endif %}"> {%- if page.type === 'tags' %} {%- include '_partials/page/tags.njk' -%} {% elif page.type === 'categories' %} {%- include '_partials/page/categories.njk' -%} {% elif page.type === 'schedule' %} {%- include '_partials/page/schedule.njk' -%} {% else %} {{ page.content }} {%- endif %} </div>
{%- set tag_indicate = '<i class="fa fa-tag"></i>'if theme.tag_iconelse'#' %} <div class="post-tags"> {%- for tag in post.tags.toArray() %} <a href="{{ url_for(tag.path) }}" rel="tag">{{ tag_indicate }} {{ tag.name }}</a> {%- endfor %} </div> <scripttype="text/javascript"> var tagsall=document.getElementsByClassName("post-tags") for (var i = tagsall.length - 1; i >= 0; i--){ var tags=tagsall[i].getElementsByTagName("a"); for (var j = tags.length - 1; j >= 0; j--) { var golden_ratio = 0.618033988749895; var s = 0.5; var v = 0.999; var h = golden_ratio + Math.random()*0.8 - 0.5; var h_i = parseInt(h * 6); var f = h * 6 - h_i; var p = v * (1 - s); var q = v * (1 - f * s); var t = v * (1 - (1 - f) * s); var r, g, b; switch (h_i) { case0: r = v; g = t; b = p; break; case1: r = q; g = v; b = p; break; case2: r = p; g = v; b = t; break; case3 : r = p; g = q; b = v; break; case4: r = t; g = p; b = v; break; case5: r = v; g = p; b = q; break; default: r = 1; g = 1; b = 1; } tags[j].style.background = "rgba("+parseInt(r*255)+","+parseInt(g*255)+","+parseInt(b*255)+","+0.7+")"; } } </script> <style> .post-tagsa { display: inline-block; font-size: 0.8em; padding: 0px10px; border-radius: 8px; color: rgb(85, 85, 85); border: 0px; } .post-tagsa:hover{ box-shadow: 0px5px15px0pxrgba(0,0,0,.4); transform: scale(1.1); transition-duration: 0.15s; } </style>