Skip to content

Commit

Permalink
fix: adapt tag page to new tag lib
Browse files Browse the repository at this point in the history
  • Loading branch information
mateusfg7 committed Dec 2, 2022
1 parent 8040209 commit f3189bb
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions src/pages/tag/[tag].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,41 @@ import React from 'react'
import { GetStaticPaths, GetStaticProps } from 'next'
import Head from 'next/head'

import { getSortedKnowledgeData } from '../../lib/knowledgeFunctions'
import { getTagListFromPosts, getKnowledgeListOfTag } from '../../lib/tags'
import { KnowledgeData } from '../../lib/types'
import {
getUniqueTagListFromPosts,
getPostListBasedOnTag
} from '../../lib/tags'

import { Container } from '../../components/Container'
import { Header } from '../../components/Header'
import { KnowledgeLink } from '../../components/KnowledgeLink'
import { Post } from 'contentlayer/generated'

interface Props {
tag: string
knowledgeList: KnowledgeData[]
postList: Post[]
}

const Tag: React.FC<Props> = ({ tag, knowledgeList }) => {
const Tag: React.FC<Props> = ({ tag, postList }) => {
return (
<div>
<Head>
<title>{tag}</title>
<title>{tag} | mfg-b</title>
</Head>
<Container>
<Header
imageUrl="https://avatars1.githubusercontent.com/u/40613276?v=4"
title={tag}
/>
<main>
{knowledgeList.map((knowledge, key) => {
{postList.map((post, key) => {
return (
<KnowledgeLink
key={key}
id={knowledge.id}
title={knowledge.title}
date={knowledge.date}
description={knowledge.description}
id={post.id}
title={post.title}
date={post.date}
description={post.description}
/>
)
})}
Expand All @@ -47,8 +49,7 @@ const Tag: React.FC<Props> = ({ tag, knowledgeList }) => {
export default Tag

export const getStaticPaths: GetStaticPaths = async () => {
const knowledgeList = getSortedKnowledgeData()
const tagList = getTagListFromPosts(knowledgeList)
const tagList = getUniqueTagListFromPosts()

const paths = tagList.map(tag => ({ params: { tag } }))

Expand All @@ -61,15 +62,13 @@ export const getStaticPaths: GetStaticPaths = async () => {
export const getStaticProps: GetStaticProps = async ({ params }) => {
const tag = params.tag

const allKnowledgeData = getSortedKnowledgeData()

if (typeof tag === 'string') {
const knowledgeList = getKnowledgeListOfTag(allKnowledgeData, tag)
const postList = getPostListBasedOnTag(tag)

return {
props: {
tag,
knowledgeList
postList
}
}
}
Expand Down

0 comments on commit f3189bb

Please sign in to comment.