1. 效果预览

2. 教程
如何自定义CSS请看
第一步:在路径BlogRoot\themes\butterfly\scripts\helpers下找到page.js文件,在文件中找到函数cloudTags进行修改:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| hexo.extend.helper.register('cloudTags', function(options = {}) { const env = this let source = options.source source = source.sort('length').reverse() const limit = options.limit if (limit > 0) source = source.limit(limit) let result = '' source.forEach(tag => { const color = 'rgb(' + Math.floor(Math.random()*156+100) + ', ' + Math.floor(Math.random()*156+100) + ', ' + Math.floor(Math.random()*156+100) + ')' result += `<a href="${env.url_for(tag.path)}" style="color: ${color}">${tag.name} (${tag.length})</a>` }) return result })
|
第二步:在路径BlogRoot\source\css下新建文件tag.css,添加内容
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| #aside-content .card-tag-cloud a { border: 1px solid; line-height: 1.5; border-radius: 6px; margin: 3px; padding: 0 5px; }
.tag-cloud-list a { border: 1px solid; line-height: 1.5; border-radius: 6px; padding: 5px 15px; font-size: 1.2rem; margin: 5px; }
|
3. 补充
3.1 自定义文章数目格式
修改函数cloudTags
1 2 3 4 5 6
| result += `<a href="${env.url_for(tag.path)}" style="color: ${color}">${tag.name} (${tag.length})</a>`
result += `<a href="${env.url_for(tag.path)}" style="color: ${color}">${tag.name} <sup>${tag.length}</sup></a>`
result += `<a href="${env.url_for(tag.path)}" style="color: ${color}">${tag.name} <sub>${tag.length}</sub></a>`
|
3.2 自定义标签颜色
修改函数cloudTags
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| const colors = [ 'rgb(255, 0, 0)', 'rgb(0, 255, 0)', 'rgb(255, 165, 0)' ];
let result = '' source.forEach(tag => { const color = colors[Math.floor(Math.random() * colors.length)]; result += `<a href="${env.url_for(tag.path)}" style="color: ${color}">${tag.name} (${tag.length})</a>` }) return result
|
4. 参考链接