From 938e7a04c792c2a64ca4e723f8859eed6e79bd8a Mon Sep 17 00:00:00 2001 From: Jerry Date: Wed, 16 Sep 2020 00:12:47 +0800 Subject: [PATCH] =?UTF-8?q?improvement:=20tags=20=E8=A8=AD=E5=AE=9A?= =?UTF-8?q?=E5=BD=A9=E8=89=B2=E9=A1=AF=E7=A4=BA=E5=BE=8C=EF=BC=8C=E5=AD=97?= =?UTF-8?q?=E5=9E=8B=E5=A4=A7=E5=B0=8F=E5=B0=87=E6=A0=B9=E6=93=9Atag?= =?UTF-8?q?=E7=9A=84=E6=96=87=E7=AB=A0=E6=95=B8=E9=87=8F=E8=80=8C=E8=AE=8A?= =?UTF-8?q?=E5=8C=96=20close=20#365=20improvement:=20=E8=AA=BF=E6=95=B4tag?= =?UTF-8?q?s=E9=A0=81=E5=92=8Ccategories=E9=A0=81=E5=9C=A8=E5=AF=AC?= =?UTF-8?q?=E5=BA=A6=E5=B0=8F=E6=96=BC768=E6=99=82=E7=9A=84=E5=AD=97?= =?UTF-8?q?=E9=AB=94=E5=A4=A7=E5=B0=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- layout/page.pug | 2 +- layout/tag.pug | 2 +- package.json | 2 +- scripts/helpers/page.js | 25 +++++++++++++++++++------ source/css/_page/categories.styl | 3 +++ source/css/_page/tags.styl | 6 ++++++ 6 files changed, 31 insertions(+), 9 deletions(-) diff --git a/layout/page.pug b/layout/page.pug index 16c061e..31324e1 100644 --- a/layout/page.pug +++ b/layout/page.pug @@ -7,7 +7,7 @@ block content | - span.tag-cloud__amount= site.tags.length .tag-cloud-tags - !=cloudTags({source: site.tags, minfontsize: 1, maxfontsize: 2.1, limit: 0, unit: 'em'}) + !=cloudTags({source: site.tags, minfontsize: 1.2, maxfontsize: 2.1, limit: 0, unit: 'em'}) if page.comments !== false && theme.comments && theme.comments.use - var commentsJsLoad = true !=partial('includes/third-party/comments/index', {}, {cache:theme.fragment_cache}) diff --git a/layout/tag.pug b/layout/tag.pug index 9f39ff8..9f99658 100644 --- a/layout/tag.pug +++ b/layout/tag.pug @@ -3,7 +3,7 @@ extends includes/layout.pug block content if theme.tag_ui == 'index' include ./includes/mixins/post-ui.pug - #recent-posts.recent-posts + #recent-posts.recent-posts +postUI include includes/pagination.pug else diff --git a/package.json b/package.json index 3cca2fc..36c6e30 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hexo-theme-butterfly", - "version": "3.2.0-b3", + "version": "3.2.0-b4", "description": "A Simple and Card UI Design theme for Hexo", "main": "package.json", "scripts": { diff --git a/scripts/helpers/page.js b/scripts/helpers/page.js index dc73ef0..f83f08e 100644 --- a/scripts/helpers/page.js +++ b/scripts/helpers/page.js @@ -34,19 +34,32 @@ hexo.extend.helper.register('injectHtml', function (data) { hexo.extend.helper.register('cloudTags', function (options = {}) { const env = this - const source = options.source + let source = options.source const minfontsize = options.minfontsize const maxfontsize = options.maxfontsize const limit = options.limit const unit = options.unit || 'px' let result = '' - const tagLimit = limit === 0 ? source.length : limit - source.sort('name').limit(tagLimit).forEach(function (tags) { - const fontSizeRD = Math.random() * (maxfontsize - minfontsize) + minfontsize - const fontSize = fontSizeRD.toFixed(2) + unit + if (limit > 0) { + source = source.limit(limit) + } + + const sizes = [] + source.sort('length').forEach(tag => { + const { length } = tag + if (sizes.includes(length)) return + sizes.push(length) + }) + + const length = sizes.length - 1 + source.forEach(tag => { + const ratio = length ? sizes.indexOf(tag.length) / length : 0 + const size = minfontsize + ((maxfontsize - minfontsize) * ratio) + let style = `font-size: ${parseFloat(size.toFixed(2))}${unit};` const color = 'rgb(' + Math.floor(Math.random() * 201) + ', ' + Math.floor(Math.random() * 201) + ', ' + Math.floor(Math.random() * 201) + ')' // 0,0,0 -> 200,200,200 - result += `${tags.name}` + style += ` color: ${color}` + result += `${tag.name}` }) return result }) diff --git a/source/css/_page/categories.styl b/source/css/_page/categories.styl index 5591de4..3f668ca 100644 --- a/source/css/_page/categories.styl +++ b/source/css/_page/categories.styl @@ -9,6 +9,9 @@ text-align: center font-size: 2.57em + +maxWidth768() + font-size: 2em + .category-list a color: var(--font-color) diff --git a/source/css/_page/tags.styl b/source/css/_page/tags.styl index f3ff325..4e3eba6 100644 --- a/source/css/_page/tags.styl +++ b/source/css/_page/tags.styl @@ -10,5 +10,11 @@ color: $text-hover !important transform: scale(1.1) + +maxWidth768() + zoom: .85 + &__title font-size: 2.57em + + +maxWidth768() + font-size: 2em