Skip to content

Commit

Permalink
feat: add sentenceCase and fix potential errors
Browse files Browse the repository at this point in the history
  • Loading branch information
avitorio committed Oct 4, 2024
1 parent c8c2163 commit 57c16c4
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 85 deletions.
1 change: 1 addition & 0 deletions examples/advanced-blog/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"@radix-ui/react-dialog": "^1.0.5",
"@radix-ui/react-slot": "^1.0.2",
"@vercel/og": "^0.6.1",
"change-case": "^5.4.2",
"class-variance-authority": "^0.7.0",
"clsx": "^2.0.0",
"date-fns": "^2.30.0",
Expand Down
5 changes: 3 additions & 2 deletions examples/advanced-blog/src/app/(web)/[...slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import DocHero from '@/components/doc-hero'
import MDXComponent from '@/components/mdx/mdx-component'
import MDXServer from '@/lib/mdx-server'
import { absoluteUrl, ogUrl } from '@/lib/utils'
import { sentenceCase } from 'change-case'
import { Metadata } from 'next'
import { notFound } from 'next/navigation'
import { OstDocument } from 'outstatic'
Expand All @@ -23,8 +24,8 @@ export async function generateMetadata(params: Params): Promise<Metadata> {

if (!doc) {
return {
title: `All ${moreDocs.collection}`,
description: `All ${moreDocs.collection}`
title: `All ${sentenceCase(moreDocs.collection)}`,
description: `All ${sentenceCase(moreDocs.collection)}`
}
}

Expand Down
4 changes: 2 additions & 2 deletions examples/advanced-blog/src/components/content-grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ const ContentGrid = ({
posts.forEach((post) => {
if (post.status === "published" && post.collection === collection) {
if (
post.title.toLowerCase().includes(searchQuery) ||
post.description.toLowerCase().includes(searchQuery)
post?.title?.toLowerCase().includes(searchQuery) ||
post?.description?.toLowerCase().includes(searchQuery)
) {
searchResults.push(post);
}
Expand Down
61 changes: 31 additions & 30 deletions examples/advanced-blog/src/components/header.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import Link from "next/link";
import { getCollections, load } from "outstatic/server";
import { MobileMenu } from "./mobile-menu";
import { ThemeToggle } from "./theme-toggle";
import { buttonVariants } from "./ui/button";
import Link from 'next/link'
import { getCollections, load } from 'outstatic/server'
import { MobileMenu } from './mobile-menu'
import { ThemeToggle } from './theme-toggle'
import { buttonVariants } from './ui/button'
import { sentenceCase } from 'change-case'

export type MenuProps = {
pages: {
title: string;
slug: string;
}[];
collections: string[];
};
title: string
slug: string
}[]
collections: string[]
}

const Header = async () => {
const data = await getData();
const { pages, collections } = data;
const data = await getData()
const { pages, collections } = data

return (
<header className="py-4 fixed bottom-0 border-t md:bottom-auto md:top-0 w-full z-20 border-b bg-background">
Expand All @@ -31,8 +32,8 @@ const Header = async () => {
<Link
href={`/${slug}`}
className={
buttonVariants({ variant: "ghost", size: "sm" }) +
" capitalize"
buttonVariants({ variant: 'ghost', size: 'sm' }) +
' capitalize'
}
>
{title}
Expand All @@ -44,11 +45,11 @@ const Header = async () => {
<Link
href={`/${collection}`}
className={
buttonVariants({ variant: "ghost", size: "sm" }) +
" capitalize"
buttonVariants({ variant: 'ghost', size: 'sm' }) +
' capitalize'
}
>
{collection}
{sentenceCase(collection)}
</Link>
</li>
))}
Expand All @@ -57,32 +58,32 @@ const Header = async () => {
<MobileMenu pages={pages} collections={collections} />
</nav>
</header>
);
};
)
}

async function getData() {
const db = await load();
const db = await load()

// get all pages
const pages = await db
.find(
{
collection: "pages",
slug: { $nin: ["home"] },
status: "published",
collection: 'pages',
slug: { $nin: ['home'] },
status: 'published'
},
["title", "slug"]
['title', 'slug']
)
.toArray();
.toArray()

const collections = getCollections().filter(
(collection) => collection !== "pages"
);
(collection) => collection !== 'pages'
)

return {
pages,
collections,
} as MenuProps;
collections
} as MenuProps
}

export default Header;
export default Header
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@
"prettier": "^2.8.8",
"prettier-plugin-tailwindcss": "^0.1.13",
"turbo": "latest"
}
},
"packageManager": "[email protected]+sha512.73a29afa36a0d092ece5271de5177ecbf8318d454ecd701343131b8ebc0c1a91c487da46ab77c8e596d6acf1461e3594ced4becedf8921b074fbd8653ed7051c"
}
Loading

0 comments on commit 57c16c4

Please sign in to comment.