Skip to content
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

Add tag badge and assign color #3

Conversation

hykim-soulis
Copy link
Contributor

Added tag badges for each entry.
Assign background and text color for each tag by mapping tag and color.
Tag will be assigned same color unless the order of the entries is changed.

Copy link
Owner

@jeremyong jeremyong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great first PR :) I appreciate the contribution and I left a few suggestions

@@ -135,4 +137,4 @@
</div>
</body>

</html>
</html>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend setting your editor to automatically insert a newline at the end of files. One benefit to having a trailing \n is that if more lines are added at the end, the former last line remains unchanged, keeping the diff slightly less noisy :)

if (entry.tags) {
tags = entry.tags.map(tag => {
const color = tagColors.get(tag.toLowerCase())
return `<span class="inline-flex items-center justify-center px-2 py-1 ml-2 text-xs font-bold leading-none text-${color}-100 bg-${color}-400 rounded-full">${tag}</span>`
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using text-${color}-100 and bg-${color}-400, I wonder if we should simply use inline CSS instead. This would save you the trouble of needing to modify the tailwind.config.js file.

@@ -97,12 +100,27 @@ window.onload = async () => {
window.results = document.getElementById('results');
const template = document.getElementById('entry-template');

let tagsArr = []
window.index.forEach(entry => {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of computing the colors every page load, we may be better off computing the tag-to-color association offline in scripts/build.js. This will add a bit of additional data to the window.index structure loaded a few lines up.

window.index.forEach(entry => {
entry.tags && tagsArr.push(...entry.tags)
})
tagsArr.map((tag, i) => tagColors.get(tag.toLowerCase()) === undefined && tagColors.set(tag.toLowerCase(), colors[i % colors.length]))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One consequence of using the modulo operator here is that when tags are added, the assignment of color to tag will change. Similarly, if the color palette size increases, the assignment will change as well. I'll make a prototype in a jsfiddle or something to show how you can do a stable color assignment with a reasonable palette.

@jeremyong
Copy link
Owner

For rendering the tags, it probably makes sense to normalize the casing also (to all caps or something)

@jeremyong
Copy link
Owner

Thanks, this is now merged with additions from this commit

@jeremyong jeremyong closed this Apr 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants