-
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(tagcloud): new option class & level #4370
Conversation
lib/plugins/helper/tagcloud.js
Outdated
@@ -57,14 +58,15 @@ function tagcloudHelper(tags, options) { | |||
const ratio = length ? sizes.indexOf(tag.length) / length : 0; | |||
const size = min + ((max - min) * ratio); | |||
let style = `font-size: ${parseFloat(size.toFixed(2))}${unit};`; | |||
const name = className ? ` class="${className}-${Math.round(ratio * 10)}"` : ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I perfer ceil
if use round
Level | 0 | 1 | ... | 9 | 10 |
---|---|---|---|---|---|
Probability | 5% | 10% | ... | 10% | 5% |
if use ceil
Level | 1 | 2 | ... | 9 | 10 |
---|---|---|---|---|---|
Probability | 10% | 10% | ... | 10% | 10% |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But how about level 0? Math.ceil(0) == 0
, but there is no level 0 in your Math.ceil
table.
Your theory seems to describe the case where tag.length approaches infinity
Level | 0 | 1 | 2 | ... | 9 | 10 |
---|---|---|---|---|---|---|
Probability | 0% | 10% | 10% | ... | 10% | 10% |
However, the actual situation is that tag.length is finite (and ratio is discrete), so the probability of level 0 must be greater than 0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const name = className ? ` class="${className}-${Math.round(ratio * 10)}"` : ''; | |
let level = Math.ceil(ratio * 10); | |
if (level === 0) level ++; | |
const name = className ? ` class="${className}-${level}"` : ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In fact the asymmetry of level 0 and level 10 comes from this line
const ratio = length ? sizes.indexOf(tag.length) / length : 0;
const ratio = length ? (sizes.indexOf(tag.length) + 0.5) / length : 0;
Of course, I don't think this change is necessary. We are designing a blog system instead of some sort of scientific computing. Such an error (0.5 / length) is acceptable.
My conclusion is that there is no big difference between Math.ceil
and Math.round
in this situation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
name
could be replaced with attr
.
const name = className ? ` class="${className}-${Math.round(ratio * 10)}"` : ''; | |
const attr = className ? ` class="${className}-${Math.round(ratio * 10)}"` : ''; |
Co-authored-by: Sukka <[email protected]>
Co-authored-by: Sukka <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
What does it do?
The color of the tag in the tag-cloud is defined by the inline style, e.g.
However, for themes that support the dark mode, it's necessary to display different tag colors for different background colors. Class name will be a better choice.
See also next-theme/hexo-theme-next@cbcd3f0
Usage:
How to test
Screenshots
Pull request tasks