Skip to content

Commit 2aa5396

Browse files
committed
changed tag color and background color
1 parent 995ba6b commit 2aa5396

File tree

6 files changed

+42
-30
lines changed

6 files changed

+42
-30
lines changed

Diff for: components/Tag.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
import Link from 'next/link'
22
import kebabCase from '@/lib/utils/kebabCase'
33

4-
const Tag = ({ text, selected }) => {
4+
const Tag = ({ text, selected, count }) => {
55
return (
6-
<Link href={`/tags/${kebabCase(text)}`}>
6+
<Link href={text === 'all' ? '/' : `/tags/${kebabCase(text)}`}>
77
<a
88
className={
9-
'mr-3 text-sm font-medium text-blue-500 uppercase hover:text-blue-600 dark:hover:text-blue-400 ' +
10-
(selected
11-
? 'p-1 border-2 border-solid border-blue-500 hover:border-blue-600 dark:hover:border-blue-400'
12-
: '')
9+
'py-1 px-2 rounded-full mr-3 text-sm font-medium uppercase text-gray-900 dark:text-gray-300 hover:text-white dark:hover:text-gray-900 hover:bg-gray-900 dark:hover:bg-gray-300 ' +
10+
(selected ? 'bg-gray-900 dark:bg-gray-300 text-white dark:text-gray-900' : '')
1311
}
1412
>
1513
{text.split(' ').join('-')}
14+
{selected && count && (
15+
<span className="ml-2 px-1 ring-1 rounded h-24 w-24 bg-blue-500 text-white">{count}</span>
16+
)}
1617
</a>
1718
</Link>
1819
)

Diff for: components/TagList.js

+21-17
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,29 @@ import Tag from '@/components/Tag'
33
import kebabCase from '@/lib/utils/kebabCase'
44

55
const TagList = ({ tags, title }) => {
6-
const sortedTags = tags && Object.keys(tags).sort((a, b) => tags[b] - tags[a])
6+
let status = 'No tags found.'
7+
let tagList = null
8+
9+
if (tags) {
10+
status = null
11+
let sortedTags = Object.keys(tags).sort((a, b) => tags[b] - tags[a])
12+
tagList = sortedTags.map((t) => {
13+
return (
14+
<div key={t} className="mt-2 mb-2 mr-1">
15+
<Tag
16+
text={t}
17+
selected={title && t.toLowerCase() === title.toLowerCase()}
18+
count={tags[t]}
19+
/>
20+
</div>
21+
)
22+
})
23+
}
724

825
return (
9-
<div className="flex flex-wrap max-w-lg">
10-
{tags && Object.keys(tags).length === 0 && 'No tags found.'}
11-
{tags &&
12-
sortedTags.map((t) => {
13-
return (
14-
<div key={t} className="mt-2 mb-2 mr-5">
15-
<Tag text={t} selected={title && t.toLowerCase() === title.toLowerCase()} />
16-
<Link
17-
href={`/tags/${kebabCase(t)}`}
18-
className="-ml-2 text-sm font-semibold text-gray-600 uppercase dark:text-gray-300"
19-
>
20-
{` (${tags[t]})`}
21-
</Link>
22-
</div>
23-
)
24-
})}
26+
<div className="flex flex-wrap">
27+
{status && <div className="text-center">{status}</div>}
28+
{tagList}
2529
</div>
2630
)
2731
}

Diff for: data/blog/codesignal-add.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
date: ! '2021/07/01 '
33
title: Codesignal - add
44
tags:
5-
- codesignal
5+
- codesignal
66
summary: ''
77
link: https://app.codesignal.com/arcade/intro/level-1/jwr339Kq6e3LQTsfa
88
draft: false
9-
109
---
10+
1111
```python
1212
def add(param1, param2):
1313
return param1 + param2

Diff for: layouts/ListLayout.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export default function ListLayout({ posts, tags, title, initialDisplayPosts = [
3030
</div>
3131
</div>
3232

33-
<TagList tags={tags} title={title} />
33+
<TagList tags={tags} title={title} total={posts.length} />
3434

3535
<div className="relative max-w-lg">
3636
<input
@@ -67,7 +67,10 @@ export default function ListLayout({ posts, tags, title, initialDisplayPosts = [
6767
<div className="space-y-3 xl:col-span-3">
6868
<div>
6969
<h3 className="text-2xl font-bold leading-8 tracking-tight">
70-
<Link href={`/${slug}`} className="text-gray-900 dark:text-gray-100">
70+
<Link
71+
href={`/${slug}`}
72+
className="text-blue-500 hover:text-blue-600 dark:hover:text-blue-400"
73+
>
7174
{title}
7275
</Link>
7376
</h3>

Diff for: pages/index.js

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ export async function getStaticProps() {
1919
}
2020

2121
export default function Blog({ posts, tags, initialDisplayPosts, pagination }) {
22+
tags['all'] = posts.length
23+
2224
return (
2325
<>
2426
<PageSeo
@@ -31,6 +33,7 @@ export default function Blog({ posts, tags, initialDisplayPosts, pagination }) {
3133
tags={tags}
3234
initialDisplayPosts={initialDisplayPosts}
3335
pagination={pagination}
36+
title={'all'}
3437
/>
3538
</>
3639
)

Diff for: pages/tags/[tag].js

+4-3
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,17 @@ export async function getStaticProps({ params }) {
3535
fs.mkdirSync(rssPath, { recursive: true })
3636
fs.writeFileSync(path.join(rssPath, 'index.xml'), rss)
3737

38-
return { props: { posts: filteredPosts, tags, tag: params.tag } }
38+
return { props: { posts: filteredPosts, tags, tag: params.tag, total: allPosts.length } }
3939
}
4040

4141
function capitalize(s) {
4242
return s[0].toUpperCase() + s.slice(1).toLowerCase()
4343
}
4444

45-
export default function Tag({ posts, tags, tag }) {
45+
export default function Tag({ posts, tags, tag, total }) {
4646
// Capitalize first letter and convert space to dash
4747
const title = tag[0].toUpperCase() + tag.split(' ').join('-').slice(1)
48+
tags['all'] = total
4849

4950
return (
5051
<>
@@ -53,7 +54,7 @@ export default function Tag({ posts, tags, tag }) {
5354
description={`${siteMetadata.description}`}
5455
url={`${siteMetadata.siteUrl}/tags/${tag}`}
5556
/>
56-
<ListLayout posts={posts} tags={tags} title={title} />
57+
<ListLayout posts={posts} tags={tags} title={title} total={total} />
5758
</>
5859
)
5960
}

0 commit comments

Comments
 (0)