Skip to content

Commit

Permalink
sort tags
Browse files Browse the repository at this point in the history
  • Loading branch information
tuan2311 committed Aug 17, 2020
1 parent fdebed2 commit 53f2d11
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 14 deletions.
20 changes: 12 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"github-calendar": "^2.2.1",
"lodash.get": "^4.4.2",
"lodash.groupby": "^4.6.0",
"lodash.sortby": "^4.7.0",
"netlify-cms-app": "^2.12.19",
"prism-react-renderer": "^1.1.1",
"prop-types": "^15.7.2",
Expand Down
3 changes: 2 additions & 1 deletion src/components/blogs/BlogEntry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Button } from '~/components/ui/controls/Button';
import { Card } from '~/components/ui/containers/Card';
import React from 'react';
import { Link } from 'gatsby';
import sort from 'lodash.sortby';
import { ColorBadge } from '~/components/ui/misc/ColorBadge';
import { Groups } from '~/components/ui/groups/Groups';

Expand All @@ -30,7 +31,7 @@ export function BlogEntry({ blog }: { blog: Blog }) {
</time>
</header>
<Groups size={2} className={`mb-4 mt-2`}>
{blog.tags.map((tag) => (
{sort(blog.tags).map((tag) => (
<Link to={`/tags/${tag.toLowerCase()}`} key={tag}>
<ColorBadge text={tag} />
</Link>
Expand Down
3 changes: 2 additions & 1 deletion src/components/projects/ProjectMain.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import userProfile from '~/profile';
import { Groups } from '~/components/ui/groups/Groups';
import { Icon } from '~/components/ui/icons/Icon';
import { ColorBadge } from '~/components/ui/misc/ColorBadge';
import sort from 'lodash.sortby';

export function ProjectMain({
projects,
Expand Down Expand Up @@ -53,7 +54,7 @@ export function ProjectMain({
</div>
<p tw={'flex-grow'}>{project.description}</p>
<Groups size={2} className={`mt-3`}>
{project.tags.map((tag) => (
{sort(project.tags).map((tag) => (
<ColorBadge key={tag} text={tag} className={'mb-2'} />
))}
</Groups>
Expand Down
3 changes: 2 additions & 1 deletion src/templates/BlogTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { Groups } from '~/components/ui/groups/Groups';
import { SEO } from '~/components/common/SEO';
import { DisqusComments } from '~/components/blogs/DisqusComments';
import { flattenBlogNode } from '~/types/blog';
import sort from 'lodash.sortby';

export const query = graphql`
query($slug: String!) {
Expand Down Expand Up @@ -78,7 +79,7 @@ const BlogTemplate = ({ data: { mdx: node } }) => {
</time>
</header>
<Groups size={2} className={`mb-6 mt-2`}>
{blog.tags.map((tag) => (
{sort(blog.tags).map((tag) => (
<Link to={`/tags/${tag.toLowerCase()}`} key={tag}>
<ColorBadge text={tag} />
</Link>
Expand Down
8 changes: 5 additions & 3 deletions src/utils/colors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ export function getRandomizedColor(text: string) {
'red',
'green',
'teal',
'indigo',
'pink',
'orange',
'yellow',
'purple',
];
let total = 0;
for (const ch of text) {
total += ch.charCodeAt(0);
}
Array.from(text).forEach((ch, index) => {
total += ch.charCodeAt(0) * Math.pow(2, index);
});
return randomColors[total % randomColors.length];
}

0 comments on commit 53f2d11

Please sign in to comment.