-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* restucture /tags directory; create dynamic routes for /tags/tag/tag2 * filter posts for up to two tags; prettify * clean up comments, rename variables e.g. x/y to path * add all combinations of tag1/tag2 routes * remove dual tag UI functionality
- Loading branch information
1 parent
6cbf61e
commit e1ca776
Showing
2 changed files
with
61 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { TagSEO } from '@/components/SEO' | ||
import siteMetadata from '@/data/siteMetadata' | ||
import ListLayout from '@/layouts/ListLayout' | ||
import { kebabCase } from 'pliny/utils/kebabCase' | ||
import { getAllTags, allCoreContent } from 'pliny/utils/contentlayer' | ||
import { InferGetStaticPropsType } from 'next' | ||
import { allBlogs } from 'contentlayer/generated' | ||
|
||
export async function getStaticPaths() { | ||
const tags = await getAllTags(allBlogs) | ||
const myPaths = [] | ||
for (const tagX in tags) { | ||
for (const tagY in tags) { | ||
if (tagX != tagY) { | ||
// /tags/opensats/opensats gives 404 error | ||
myPaths.push({ | ||
params: { | ||
tag: tagX, | ||
tag2: tagY, | ||
}, | ||
}) | ||
} | ||
} | ||
} | ||
return { | ||
paths: myPaths, | ||
fallback: false, | ||
} | ||
} | ||
|
||
export const getStaticProps = async (context) => { | ||
const tag = context.params.tag as string | ||
const tag2 = context.params.tag2 as string | ||
const filteredPosts = allCoreContent( | ||
allBlogs.filter( | ||
(post) => | ||
post.draft !== true && | ||
post.tags.map((t) => kebabCase(t)).includes(tag) && | ||
post.tags.map((t) => kebabCase(t)).includes(tag2) | ||
) | ||
) | ||
return { props: { posts: filteredPosts, tag } } | ||
} | ||
|
||
export default function Tag({ | ||
posts, | ||
tag, | ||
}: InferGetStaticPropsType<typeof getStaticProps>) { | ||
// Capitalize first letter and convert space to dash | ||
// adjust title to account for multiple tags | ||
const title = tag[0].toUpperCase() + tag.split(' ').join('-').slice(1) | ||
return ( | ||
<> | ||
<TagSEO | ||
title={`${tag} - ${siteMetadata.title}`} | ||
description={`${tag} tags - ${siteMetadata.author}`} | ||
/> | ||
<ListLayout posts={posts} title={title} /> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters