Skip to content

Commit

Permalink
rename blog to post
Browse files Browse the repository at this point in the history
  • Loading branch information
tidvn committed Oct 27, 2024
1 parent e31f57f commit 5fb2b91
Show file tree
Hide file tree
Showing 19 changed files with 65 additions and 65 deletions.
6 changes: 3 additions & 3 deletions app/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default function Home({ posts }) {
<div>
<h2 className="text-2xl font-bold leading-8 tracking-tight">
<Link
href={`/blog/${slug}`}
href={`/posts/${slug}`}
className="text-gray-900 dark:text-gray-100"
>
{title}
Expand All @@ -55,7 +55,7 @@ export default function Home({ posts }) {
</div>
<div className="text-base font-medium leading-6">
<Link
href={`/blog/${slug}`}
href={`/posts/${slug}`}
className="text-primary-500 hover:text-primary-600 dark:hover:text-primary-400"
aria-label={`Read more: "${title}"`}
>
Expand All @@ -73,7 +73,7 @@ export default function Home({ posts }) {
{posts.length > MAX_DISPLAY && (
<div className="flex justify-end text-base font-medium leading-6">
<Link
href="/blog"
href="/posts"
className="text-primary-500 hover:text-primary-600 dark:hover:text-primary-400"
aria-label="All posts"
>
Expand Down
4 changes: 2 additions & 2 deletions app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { sortPosts, allCoreContent } from 'pliny/utils/contentlayer'
import { allBlogs } from 'contentlayer/generated'
import { allPosts } from 'contentlayer/generated'
import HomePage from 'components/app/HomePage'

export default async function Page() {
const sortedPosts = sortPosts(allBlogs)
const sortedPosts = sortPosts(allPosts)
const posts = allCoreContent(sortedPosts)
return <HomePage posts={posts} />
}
12 changes: 6 additions & 6 deletions app/blog/[...slug]/page.tsx → app/posts/[...slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import 'katex/dist/katex.css'
import { components } from '@/components/common/MDXComponents'
import { MDXLayoutRenderer } from 'pliny/mdx-components'
import { sortPosts, coreContent, allCoreContent } from 'pliny/utils/contentlayer'
import { allBlogs } from 'contentlayer/generated'
import type { Blog } from 'contentlayer/generated'
import { allPosts } from 'contentlayer/generated'
import type { Post } from 'contentlayer/generated'
import PostSimple from '@/layouts/PostSimple'
import PostLayout from '@/layouts/PostLayout'
import PostBanner from '@/layouts/PostBanner'
Expand All @@ -26,7 +26,7 @@ export async function generateMetadata({
params: { slug: string[] }
}): Promise<Metadata | undefined> {
const slug = decodeURI(params.slug.join('/'))
const post = allBlogs.find((p) => p.slug === slug)
const post = allPosts.find((p) => p.slug === slug)
const authorList = post?.authors || ['default']
if (!post) {
return
Expand Down Expand Up @@ -69,21 +69,21 @@ export async function generateMetadata({
}

export const generateStaticParams = async () => {
return allBlogs.map((p) => ({ slug: p.slug.split('/').map((name) => decodeURI(name)) }))
return allPosts.map((p) => ({ slug: p.slug.split('/').map((name) => decodeURI(name)) }))
}

export default async function Page({ params }: { params: { slug: string[] } }) {
const slug = decodeURI(params.slug.join('/'))
// Filter out drafts in production
const sortedCoreContents = allCoreContent(sortPosts(allBlogs))
const sortedCoreContents = allCoreContent(sortPosts(allPosts))
const postIndex = sortedCoreContents.findIndex((p) => p.slug === slug)
if (postIndex === -1) {
return notFound()
}

const prev = sortedCoreContents[postIndex + 1]
const next = sortedCoreContents[postIndex - 1]
const post = allBlogs.find((p) => p.slug === slug) as Blog
const post = allPosts.find((p) => p.slug === slug) as Post
const authorList = post?.authors || ['default']
const mainContent = coreContent(post)
const jsonLd = post.structuredData
Expand Down
4 changes: 2 additions & 2 deletions app/blog/page.tsx → app/posts/page.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import ListLayout from '@/layouts/ListLayoutWithTags'
import { allCoreContent, sortPosts } from 'pliny/utils/contentlayer'
import { allBlogs } from 'contentlayer/generated'
import { allPosts } from 'contentlayer/generated'
import { genPageMetadata } from 'app/seo'

const POSTS_PER_PAGE = 5

export const metadata = genPageMetadata({ title: 'Blog' })

export default function BlogPage() {
const posts = allCoreContent(sortPosts(allBlogs))
const posts = allCoreContent(sortPosts(allPosts))
const pageNumber = 1
const initialDisplayPosts = posts.slice(
POSTS_PER_PAGE * (pageNumber - 1),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import ListLayout from '@/layouts/ListLayoutWithTags'
import { allCoreContent, sortPosts } from 'pliny/utils/contentlayer'
import { allBlogs } from 'contentlayer/generated'
import { allPosts } from 'contentlayer/generated'

const POSTS_PER_PAGE = 5

export const generateStaticParams = async () => {
const totalPages = Math.ceil(allBlogs.length / POSTS_PER_PAGE)
const totalPages = Math.ceil(allPosts.length / POSTS_PER_PAGE)
const paths = Array.from({ length: totalPages }, (_, i) => ({ page: (i + 1).toString() }))

return paths
}

export default function Page({ params }: { params: { page: string } }) {
const posts = allCoreContent(sortPosts(allBlogs))
const posts = allCoreContent(sortPosts(allPosts))
const pageNumber = parseInt(params.page as string)
const initialDisplayPosts = posts.slice(
POSTS_PER_PAGE * (pageNumber - 1),
Expand Down
6 changes: 3 additions & 3 deletions app/sitemap.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { MetadataRoute } from 'next'
import { allBlogs } from 'contentlayer/generated'
import { allPosts } from 'contentlayer/generated'
import siteMetadata from '@/data/siteMetadata'

export default function sitemap(): MetadataRoute.Sitemap {
const siteUrl = siteMetadata.siteUrl

const blogRoutes = allBlogs
const blogRoutes = allPosts
.filter((post) => !post.draft)
.map((post) => ({
url: `${siteUrl}/${post.path}`,
lastModified: post.lastmod || post.date,
}))

const routes = ['', 'blog', 'projects', 'tags', 'members'].map((route) => ({
const routes = ['', 'posts', 'projects', 'tags', 'members'].map((route) => ({
url: `${siteUrl}/${route}`,
lastModified: new Date().toISOString().split('T')[0],
}))
Expand Down
4 changes: 2 additions & 2 deletions app/tags/[tag]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { slug } from 'github-slugger'
import { allCoreContent, sortPosts } from 'pliny/utils/contentlayer'
import siteMetadata from '@/data/siteMetadata'
import ListLayout from '@/layouts/ListLayoutWithTags'
import { allBlogs } from 'contentlayer/generated'
import { allPosts } from 'contentlayer/generated'
import tagData from 'app/tag-data.json'
import { genPageMetadata } from 'app/seo'
import { Metadata } from 'next'
Expand Down Expand Up @@ -36,7 +36,7 @@ export default function TagPage({ params }: { params: { tag: string } }) {
// Capitalize first letter and convert space to dash
const title = tag[0].toUpperCase() + tag.split(' ').join('-').slice(1)
const filteredPosts = allCoreContent(
sortPosts(allBlogs.filter((post) => post.tags && post.tags.map((t) => slug(t)).includes(tag)))
sortPosts(allPosts.filter((post) => post.tags && post.tags.map((t) => slug(t)).includes(tag)))
)
if (filteredPosts.length === 0) {
return notFound()
Expand Down
2 changes: 1 addition & 1 deletion app/tags/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { slug } from 'github-slugger'
import tagData from 'app/tag-data.json'
import { genPageMetadata } from 'app/seo'

export const metadata = genPageMetadata({ title: 'Tags', description: 'Things I blog about' })
export const metadata = genPageMetadata({ title: 'Tags', description: 'Things This blog about' })

export default async function Page() {
const tagCounts = tagData as Record<string, number>
Expand Down
22 changes: 11 additions & 11 deletions contentlayer.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ const computedFields: ComputedFields = {
/**
* Count the occurrences of all tags across blog posts and write to json file
*/
function createTagCount(allBlogs) {
function createTagCount(allPosts) {
const tagCount: Record<string, number> = {}
allBlogs.forEach((file) => {
allPosts.forEach((file) => {
if (file.tags && (!isProduction || file.draft !== true)) {
file.tags.forEach((tag) => {
const formattedTag = slug(tag)
Expand All @@ -77,22 +77,22 @@ function createTagCount(allBlogs) {
writeFileSync('./app/tag-data.json', JSON.stringify(tagCount))
}

function createSearchIndex(allBlogs) {
function createSearchIndex(allPosts) {
if (
siteMetadata?.search?.provider === 'kbar' &&
siteMetadata.search.kbarConfig.searchDocumentsPath
) {
writeFileSync(
`public/${path.basename(siteMetadata.search.kbarConfig.searchDocumentsPath)}`,
JSON.stringify(allCoreContent(sortPosts(allBlogs)))
JSON.stringify(allCoreContent(sortPosts(allPosts)))
)
console.log('Local search index generated...')
}
}

export const Blog = defineDocumentType(() => ({
name: 'Blog',
filePathPattern: 'blog/**/*.mdx',
export const Post = defineDocumentType(() => ({
name: 'Post',
filePathPattern: 'posts/**/*.mdx',
contentType: 'mdx',
fields: {
title: { type: 'string', required: true },
Expand Down Expand Up @@ -162,7 +162,7 @@ export const Project = defineDocumentType(() => ({

export default makeSource({
contentDirPath: 'data',
documentTypes: [Blog, Project],
documentTypes: [Post, Project],
mdx: {
cwd: process.cwd(),
remarkPlugins: [
Expand Down Expand Up @@ -192,8 +192,8 @@ export default makeSource({
],
},
onSuccess: async (importData) => {
const { allBlogs } = await importData()
createTagCount(allBlogs)
createSearchIndex(allBlogs)
const { allPosts } = await importData()
createTagCount(allPosts)
createSearchIndex(allPosts)
},
})
2 changes: 1 addition & 1 deletion data/headerNavLinks.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const headerNavLinks = [
{ href: '/', title: 'Home' },
// { href: '/blog', title: 'Blog' },
{ href: '/posts', title: 'Posts' },
{ href: '/ideascale', title: 'Ideascale' },
{ href: '/projects', title: 'Projects' },
{ href: '/members', title: 'Members' },
Expand Down
6 changes: 3 additions & 3 deletions data/memberData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Member } from '@/app/type'

const membersData: Member[] = [
{
name: 'Phùng Tiến Dũng | Founder',
name: 'Phùng Tiến Dũng',
github: 'tidvn',
avatar: 'https://avatars.githubusercontent.com/u/74198018?v=4',
company: '',
Expand All @@ -29,7 +29,7 @@ const membersData: Member[] = [
],
},
{
name: 'Nguyễn Duy Khánh | Co-Founder',
name: 'Nguyễn Duy Khánh',
github: 'independenceee',
avatar: 'https://avatars.githubusercontent.com/u/108068667?v=4',
email: 'nguyenkhanh17112003@gmail.com',
Expand All @@ -51,7 +51,7 @@ const membersData: Member[] = [
},

{
name: 'Nguyễn Hồng Sơn | Co-Founder',
name: 'Nguyễn Hồng Sơn',
github: 'sonson0910',
avatar: 'https://avatars.githubusercontent.com/u/91943651?v=4',
email: '',
Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions faq/customize-kbar-search.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Add a `SearchProvider` component such as the one shown below and use it in place
import { KBarSearchProvider } from 'pliny/search/KBar'
import { useRouter } from 'next/navigation'
import { CoreContent } from 'pliny/utils/contentlayer'
import { Blog } from 'contentlayer/generated'
import { Post } from 'contentlayer/generated'

export const SearchProvider = ({ children }) => {
const router = useRouter()
Expand Down Expand Up @@ -59,21 +59,21 @@ export const SearchProvider = ({ children }) => {
You can even choose to do a full text search over the entire generated blog content though this would come at the expense of a larger search index file by modifying the `createSearchIndex` function in `contentlayer.config.ts` to:

```tsx
function createSearchIndex(allBlogs) {
function createSearchIndex(allPosts) {
if (
siteMetadata?.search?.provider === 'kbar' &&
siteMetadata.search.kbarConfig.searchDocumentsPath
) {
writeFileSync(
`public/${siteMetadata.search.kbarConfig.searchDocumentsPath}`,
JSON.stringify((sortPosts(allBlogs)))
JSON.stringify(sortPosts(allPosts))
)
console.log('Local search index generated...')
}
}
```

Note the change from `JSON.stringify(allCoreContent(sortPosts(allBlogs)))` to `JSON.stringify((sortPosts(allBlogs)))`.
Note the change from `JSON.stringify(allCoreContent(sortPosts(allPosts)))` to `JSON.stringify((sortPosts(allPosts)))`.

Next, in the modified `SearchProvider`, dump the raw content to the `keywords` field in the `onSearchDocumentsLoad` prop:

Expand Down
6 changes: 3 additions & 3 deletions layouts/ListLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useState } from 'react'
import { usePathname } from 'next/navigation'
import { formatDate } from 'pliny/utils/formatDate'
import { CoreContent } from 'pliny/utils/contentlayer'
import type { Blog } from 'contentlayer/generated'
import type { Post } from 'contentlayer/generated'
import Link from '@/components/common/Link'
import Tag from '@/components/common/Tag'
import siteMetadata from '@/data/siteMetadata'
Expand All @@ -14,9 +14,9 @@ interface PaginationProps {
currentPage: number
}
interface ListLayoutProps {
posts: CoreContent<Blog>[]
posts: CoreContent<Post>[]
title: string
initialDisplayPosts?: CoreContent<Blog>[]
initialDisplayPosts?: CoreContent<Post>[]
pagination?: PaginationProps
}

Expand Down
10 changes: 5 additions & 5 deletions layouts/ListLayoutWithTags.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { usePathname } from 'next/navigation'
import { slug } from 'github-slugger'
import { formatDate } from 'pliny/utils/formatDate'
import { CoreContent } from 'pliny/utils/contentlayer'
import type { Blog } from 'contentlayer/generated'
import type { Post } from 'contentlayer/generated'
import Link from '@/components/common/Link'
import Tag from '@/components/common/Tag'
import siteMetadata from '@/data/siteMetadata'
Expand All @@ -16,9 +16,9 @@ interface PaginationProps {
currentPage: number
}
interface ListLayoutProps {
posts: CoreContent<Blog>[]
posts: CoreContent<Post>[]
title: string
initialDisplayPosts?: CoreContent<Blog>[]
initialDisplayPosts?: CoreContent<Post>[]
pagination?: PaginationProps
}

Expand Down Expand Up @@ -86,11 +86,11 @@ export default function ListLayoutWithTags({
<div className="flex sm:space-x-24">
<div className="hidden h-full max-h-screen min-w-[280px] max-w-[280px] flex-wrap overflow-auto rounded bg-gray-50 pt-5 shadow-md dark:bg-gray-900/70 dark:shadow-gray-800/40 sm:flex">
<div className="px-6 py-4">
{pathname.startsWith('/blog') ? (
{pathname.startsWith('/posts') ? (
<h3 className="font-bold uppercase text-primary-500">All Posts</h3>
) : (
<Link
href={`/blog`}
href={`/posts`}
className="font-bold uppercase text-gray-700 hover:text-primary-500 dark:text-gray-300 dark:hover:text-primary-500"
>
All Posts
Expand Down
4 changes: 2 additions & 2 deletions layouts/PostBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ReactNode } from 'react'
import Image from 'next/image'
import Bleed from 'pliny/ui/Bleed'
import { CoreContent } from 'pliny/utils/contentlayer'
import type { Blog } from 'contentlayer/generated'
import type { Post } from 'contentlayer/generated'
import Comments from '@/components/common/Comments'
import Link from '@/components/common/Link'
import PageTitle from '@/components/common/PageTitle'
Expand All @@ -11,7 +11,7 @@ import siteMetadata from '@/data/siteMetadata'
import ScrollTopAndComment from '@/components/common/ScrollTopAndComment'

interface LayoutProps {
content: CoreContent<Blog>
content: CoreContent<Post>
children: ReactNode
next?: { path: string; title: string }
prev?: { path: string; title: string }
Expand Down
Loading

0 comments on commit 5fb2b91

Please sign in to comment.