post.url);
return {
- paths,
+ paths: allPostPaths,
fallback: false,
};
}
export async function getStaticProps({ params }) {
- const post: Post = allPosts.find(
- (post) => post._raw.flattenedPath === params.slug
- );
+ const post: Post = getPostBySlug(params.slug);
return {
props: {
post,
@@ -22,6 +20,8 @@ export async function getStaticProps({ params }) {
}
const PostLayout = ({ post }: { post: Post }) => {
+ const formattedDate: string = formatDate(post.date);
+
return (
<>
@@ -30,9 +30,12 @@ const PostLayout = ({ post }: { post: Post }) => {
{post.title}
+
+
+
diff --git a/pages/tags/[tag].tsx b/pages/tags/[tag].tsx
new file mode 100644
index 0000000..9c58291
--- /dev/null
+++ b/pages/tags/[tag].tsx
@@ -0,0 +1,54 @@
+import { Tags } from "components/Tags";
+import { Post } from "contentlayer/generated";
+import { allOtherTags, allTagPaths, postsWithTag } from "lib/content";
+import Head from "next/head";
+import { PostCard } from "pages";
+
+export async function getStaticPaths() {
+ return {
+ paths: allTagPaths,
+ fallback: false,
+ };
+}
+
+export async function getStaticProps({ params }) {
+ const posts: Post[] | undefined = postsWithTag(params.tag);
+
+ return {
+ props: {
+ posts,
+ tag: params.tag,
+ },
+ };
+}
+
+const TagLayout = ({ posts, tag }: { posts: Post[]; tag: string }) => {
+ const otherTags: string[] = allOtherTags(tag);
+
+ return (
+ <>
+
+
Posts with the tag {tag}
+
+
+
+ Posts with the tag {tag}
+
+
+
+ {posts.map((post, idx) => (
+
+ ))}
+
+
+
+
Other available tags
+
+
+
+
+ >
+ );
+};
+
+export default TagLayout;
diff --git a/pages/tags/index.tsx b/pages/tags/index.tsx
new file mode 100644
index 0000000..6414097
--- /dev/null
+++ b/pages/tags/index.tsx
@@ -0,0 +1,12 @@
+import { Tags } from "components/Tags";
+import { allTags } from "lib/content";
+
+export default function AllTags() {
+ return (
+
+
All tags used on the blog
+
+
+
+ );
+}
diff --git a/posts/change-me.md b/posts/change-me.md
index 398ddec..91f5821 100644
--- a/posts/change-me.md
+++ b/posts/change-me.md
@@ -1,6 +1,7 @@
---
title: Change me!
date: 2022-03-11
+tags: [cache, how-to]
---
When you change a source file, Contentlayer automatically updates the content cache, which prompts Next.js to reload the content on screen.
diff --git a/posts/click-me.md b/posts/click-me.md
index 606cbd3..1ff4798 100644
--- a/posts/click-me.md
+++ b/posts/click-me.md
@@ -1,6 +1,7 @@
---
title: Click me!
date: 2022-02-28
+tags: [html, how-to]
---
Blog posts have their own pages. The content source is a markdown file, parsed to HTML by Contentlayer.
diff --git a/posts/what-is-contentlayer.md b/posts/what-is-contentlayer.md
index 07eef20..fa8d850 100644
--- a/posts/what-is-contentlayer.md
+++ b/posts/what-is-contentlayer.md
@@ -1,6 +1,7 @@
---
title: What is Contentlayer?
date: 2022-02-22
+tags: [content, technical]
---
**Contentlayer makes working with content easy.** It is a content preprocessor that validates and transforms your content into type-safe JSON you can easily import into your application.