Skip to content

Commit e5fd0ab

Browse files
Merge pull request #164 from Web-Dev-Path/feature/add-link-to-tags
Add Links to Blog Tags
2 parents 01d6bff + 6c0c8dd commit e5fd0ab

File tree

7 files changed

+71
-42
lines changed

7 files changed

+71
-42
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
8686
- Blog page which pulls content from dev.to
8787
- Search functionality for blog posts
8888
- Styled components to Title component
89+
- Links to blog tags to show all posts with the same tag
8990

9091
### Fixed
9192

components/blog/BlogPostsContainer.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const BlogPostsContainer = ({
1919
tag,
2020
swipe = true,
2121
viewall = true,
22+
back = false,
2223
}) => {
2324
// process posts props (e.g. insert default image)
2425
posts.map(post => {
@@ -51,7 +52,7 @@ const BlogPostsContainer = ({
5152
) : (
5253
<Container>
5354
<div className={styles.postContainer}>
54-
{posts.map((p, index) => (
55+
{posts?.map((p, index) => (
5556
<Card customClass='blog' key={index} card={p} />
5657
))}
5758
</div>
@@ -61,13 +62,23 @@ const BlogPostsContainer = ({
6162
{viewall && posts.length >= 3 ? (
6263
<Container>
6364
<Link
64-
className={styles.viewAll}
65+
className={`${styles.bottomLink} ${styles.viewAll}`}
6566
href={tag ? `/blog/category/${tag}` : '/blog/category/all'}
6667
>
6768
view all
6869
</Link>
6970
</Container>
7071
) : null}
72+
{back ? (
73+
<Container>
74+
<Link
75+
className={`${styles.bottomLink} ${styles.backLink}}`}
76+
href={`/blog`}
77+
>
78+
&#60; Back
79+
</Link>
80+
</Container>
81+
) : null}
7182
</div>
7283
</RevealContentContainer>
7384
);

components/blog/Tag.js

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,25 @@
1-
import styles from '@/styles/Blog.module.scss';
1+
import Link from 'next/link';
2+
import styled from 'styled-components';
23

3-
const Tag = ({ text }) => {
4-
return <div className={styles.tag}>{text}</div>;
5-
};
4+
export const TagContainer = styled.div`
5+
display: flex;
6+
flex-wrap: wrap;
7+
max-height: 12rem;
8+
overflow: hidden;
9+
gap: 0.5rem;
10+
margin-bottom: -1rem;
11+
a {
12+
text-decoration: none;
13+
}
14+
`;
15+
16+
const TagLink = styled(Link)`
17+
background-color: #8cd5e8;
18+
padding: 0.5rem 1rem;
19+
border-radius: 2rem;
20+
font-weight: bold;
21+
`;
622

7-
export default Tag;
23+
export const Tag = ({ text }) => {
24+
return <TagLink href={`/blog/category/${text}`}>{text}</TagLink>;
25+
};

components/containers/Card.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Image from 'next/image';
22
import Link from 'next/link';
33
import styles from '@/styles/Card.module.scss';
4-
import Tag from '@/components/blog/Tag';
4+
import { Tag, TagContainer } from '@/components/blog/Tag';
55

66
export default function Card({
77
card: { image, altTag, title, content, link, linkText, tagList },
@@ -30,11 +30,11 @@ export default function Card({
3030
{title}
3131
</h2>
3232
{tagList && tagList.length > 0 ? (
33-
<div className={styles.tagListContainer}>
33+
<TagContainer>
3434
{tagList.slice(0, 8).map((tag, i) => (
3535
<Tag key={i} text={tag} />
3636
))}
37-
</div>
37+
</TagContainer>
3838
) : null}
3939
<div className={styles.content}>
4040
<p>

pages/blog/category/[tag].js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,17 @@ import { blogRevalidate } from '@/utils/config';
66
export default function BlogCategory({ posts }) {
77
const router = useRouter();
88
const { tag } = router.query;
9+
910
return (
10-
<BlogPostsContainer
11-
posts={posts}
12-
swipe={false}
13-
heading={tagToHeading[tag]}
14-
viewall={false}
15-
/>
11+
<>
12+
<BlogPostsContainer
13+
posts={posts}
14+
swipe={false}
15+
heading={tagToHeading[tag] || `#${tag}`}
16+
viewall={false}
17+
back={true}
18+
/>
19+
</>
1620
);
1721
}
1822

@@ -41,6 +45,6 @@ export async function getStaticProps({ params }) {
4145
export async function getStaticPaths() {
4246
return {
4347
paths,
44-
fallback: false,
48+
fallback: 'blocking',
4549
};
4650
}

styles/Blog.module.scss

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,31 @@
77
margin: 3rem 0;
88
}
99

10-
.viewAll {
10+
.bottomLink {
1111
font-size: 1.5rem;
1212
font-weight: bold;
1313
position: relative;
14-
top: -3rem;
1514
display: block;
1615
text-align: center;
16+
}
1717

18+
.viewAll {
19+
top: -3rem;
1820
@include desktop {
1921
float: right;
2022
top: -5rem;
2123
}
2224
}
2325

26+
.backLink {
27+
top: -2rem;
28+
29+
@include desktop {
30+
float: left;
31+
top: -1rem;
32+
}
33+
}
34+
2435
.blogSearch {
2536
display: flex;
2637
padding-top: 2.5rem;
@@ -40,31 +51,18 @@
4051
justify-content: center;
4152
margin-bottom: 3rem;
4253

43-
@include mobile {
44-
justify-content: center;
45-
}
46-
4754
@include tablet {
48-
justify-content: space-between;
49-
}
50-
51-
@include desktop {
5255
justify-content: flex-start;
5356
}
5457
}
5558

5659
.postContainer > div {
57-
@include mobile {
58-
flex-basis: 100%;
59-
}
60-
61-
@include tablet {
62-
flex-basis: 43%;
60+
@include desktop {
61+
flex-basis: 48%;
6362
}
6463

65-
@include desktop {
64+
@include large-desktop {
6665
flex-basis: 32%;
67-
max-width: 200px;
6866
}
6967
}
7068

@@ -78,10 +76,3 @@
7876
content: unset;
7977
}
8078
}
81-
82-
.tag {
83-
background-color: $light-bg-color;
84-
padding: 0.5rem 1rem;
85-
border-radius: 2rem;
86-
font-weight: bold;
87-
}

styles/Card.module.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@
117117

118118
&.blog {
119119
margin: 1rem 0.5rem 0 0.5rem;
120+
@include tablet {
121+
height: 40rem;
122+
}
123+
120124
.card__image {
121125
height: 12rem;
122126
}

0 commit comments

Comments
 (0)