Skip to content

Commit

Permalink
feat(tags): include T.I.L. tags on tags list
Browse files Browse the repository at this point in the history
  • Loading branch information
mateusfg7 committed Sep 14, 2024
1 parent 86b9569 commit b4f802e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/app/_lib/all-routes.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getUniqueCategoryList } from '~/lib/categories'
import { slug } from '~/lib/slug'
import { getUniqueTagListFromPosts } from '~/lib/tags'
import { getUniqueTagList } from '~/lib/tags'
import { config } from 'global-config'
import { posts } from '#content'

Expand All @@ -15,7 +15,7 @@ const commonPaths = [
'blog/feed',
'guestbook'
]
const tagPaths = getUniqueTagListFromPosts().map(tag => `blog/tag/${slug(tag)}`)
const tagPaths = getUniqueTagList().map(tag => `blog/tag/${slug(tag)}`)
const categoryPaths = getUniqueCategoryList().map(
category => `blog/categories/${slug(category)}`
)
Expand Down
5 changes: 3 additions & 2 deletions src/app/blog/tag/[tag]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Tag } from '@phosphor-icons/react/dist/ssr'
import { PostList } from '~/components/post-list'

import {
getUniqueTagListFromPosts,
getUniqueTagList,
getPostListBasedOnTag,
getNormalTagString
} from '~/lib/tags'
Expand All @@ -25,6 +25,7 @@ export function generateMetadata({ params }: Props): Metadata {

export default function Page({ params }: Props) {
const { tag } = params

const postList = getSortedPosts(getPostListBasedOnTag(slug(tag)))

return (
Expand All @@ -41,7 +42,7 @@ export default function Page({ params }: Props) {
}

export async function generateStaticParams() {
const tagList = getUniqueTagListFromPosts()
const tagList = getUniqueTagList()

return tagList.map(tag => ({ tag: slug(tag) }))
}
4 changes: 2 additions & 2 deletions src/components/kbar/provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { getSortedPosts } from '~/lib/get-sorted-posts'
import { KBar } from '~/components/kbar'
import { slug } from '~/lib/slug'
import { getUniqueCategoryList } from '~/lib/categories'
import { getUniqueTagListFromPosts } from '~/lib/tags'
import { getUniqueTagList } from '~/lib/tags'
import { posts, projects, tils } from '#content'

export function CustomKBarProvider({ children }: { children: ReactNode }) {
Expand Down Expand Up @@ -124,7 +124,7 @@ export function CustomKBarProvider({ children }: { children: ReactNode }) {
section: 'Blog',
perform: () => push(`/blog/categories/${slug(category)}`)
}))
const tagsAsAction: Action[] = getUniqueTagListFromPosts()
const tagsAsAction: Action[] = getUniqueTagList()
.sort()
.map(tag => ({
id: slug(tag),
Expand Down
16 changes: 9 additions & 7 deletions src/lib/tags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@ import { removeRepeatedValuesFromArray } from '~/lib/remove-repeated-values-from
import { getFrequencyOfValue } from '~/lib/get-frequency-of-value'
import { Post, posts, tils } from '#content'

const getRawTagListFromPosts = () =>
posts.filter((post: Post) => !post.test).flatMap(post => post.tags)
const getRawTagList = () => [
...posts.filter((post: Post) => !post.test).flatMap(post => post.tags),
...tils.flatMap(til => til.tags)
]

export const getUniqueTagListFromPosts = () =>
removeRepeatedValuesFromArray(getRawTagListFromPosts())
export const getUniqueTagList = () =>
removeRepeatedValuesFromArray(getRawTagList())

export interface TagsAndNumberOfPosts {
tag: string
numberOfPosts: number
}
export function getTagsAndNumberOfPosts(): TagsAndNumberOfPosts[] {
const rawTagList = getRawTagListFromPosts()
const uniqueTagList = getUniqueTagListFromPosts()
const rawTagList = getRawTagList()
const uniqueTagList = getUniqueTagList()

const tagsAndNumberOfPosts = uniqueTagList.map(tag => {
const numberOfPosts = getFrequencyOfValue(rawTagList, tag)
Expand All @@ -39,7 +41,7 @@ export function getPostListBasedOnTag(tag: string) {
}

export function getNormalTagString(tag: string) {
const allTags = getUniqueTagListFromPosts()
const allTags = getUniqueTagList()

return allTags.find(currTag => slug(currTag) === slug(tag))
}
Expand Down

0 comments on commit b4f802e

Please sign in to comment.