Skip to content

Commit

Permalink
fix: sitemap
Browse files Browse the repository at this point in the history
  • Loading branch information
sadmann7 committed Mar 10, 2024
1 parent 7b4028a commit 0933fe9
Show file tree
Hide file tree
Showing 19 changed files with 231 additions and 272 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
"react-medium-image-zoom": "^5.1.10",
"react-syntax-highlighter": "^15.5.0",
"react-textarea-autosize": "^8.5.3",
"remark-gfm": "^4.0.0",
"resend": "^3.2.0",
"server-only": "^0.0.1",
"sonner": "^1.4.3",
Expand Down
183 changes: 183 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/app/(dashboard)/dashboard/stores/[storeId]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import {
PageHeaderDescription,
PageHeaderHeading,
} from "@/components/page-header"
import { StoreSwitcher } from "@/components/pagers/store-switcher"
import { StoreTabs } from "@/components/pagers/store-tabs"
import { Shell } from "@/components/shell"
import { StoreSwitcher } from "@/components/store-switcher"
import { StoreTabs } from "@/components/store-tabs"

interface StoreLayoutProps extends React.PropsWithChildren {
params: {
Expand Down
2 changes: 1 addition & 1 deletion src/app/(lobby)/(content)/(helps)/[...slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import { siteConfig } from "@/config/site"
import { absoluteUrl } from "@/lib/utils"
import { Separator } from "@/components/ui/separator"
import { Mdx } from "@/components/mdx/mdx-components"
import { MdxPager } from "@/components/mdx/mdx-pager"
import {
PageHeader,
PageHeaderDescription,
PageHeaderHeading,
} from "@/components/page-header"
import { MdxPager } from "@/components/pagers/mdx-pager"
import { Shell } from "@/components/shell"

interface PageProps {
Expand Down
2 changes: 1 addition & 1 deletion src/app/(lobby)/(content)/blog/[...slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { absoluteUrl, cn, formatDate } from "@/lib/utils"
import { AspectRatio } from "@/components/ui/aspect-ratio"
import { buttonVariants } from "@/components/ui/button"
import { Separator } from "@/components/ui/separator"
import { MdxPager } from "@/components/pagers/mdx-pager"
import { MdxPager } from "@/components/mdx/mdx-pager"
import { Shell } from "@/components/shell"

interface PostPageProps {
Expand Down
28 changes: 7 additions & 21 deletions src/app/(lobby)/collections/[category]/[subcategory]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import type { Metadata } from "next"
import { type Product } from "@/db/schema"
import { env } from "@/env.js"

import { getProducts } from "@/lib/fetchers/product"
import { getStores } from "@/lib/fetchers/store"
import { getProducts } from "@/lib/actions/product"
import { getStores } from "@/lib/actions/store"
import { toTitleCase, unslugify } from "@/lib/utils"
import { productsSearchParamsSchema } from "@/lib/validations/params"
import {
Expand All @@ -16,7 +15,7 @@ import { Shell } from "@/components/shell"

interface SubcategoryPageProps {
params: {
category: Product["category"]
category: string
subcategory: string
}
searchParams: {
Expand Down Expand Up @@ -46,16 +45,7 @@ export default async function SubcategoryPage({
const limit = typeof per_page === "string" ? parseInt(per_page) : 8
const offset = typeof page === "string" ? (parseInt(page) - 1) * limit : 0

const productsTransaction = await getProducts({
limit,
offset,
sort: typeof sort === "string" ? sort : null,
categories: category,
subcategories: subcategory,
price_range: typeof price_range === "string" ? price_range : null,
store_ids: typeof store_ids === "string" ? store_ids : null,
active,
})
const productsTransaction = await getProducts(searchParams)

// Stores transaction
const storesLimit = 25
Expand All @@ -64,11 +54,7 @@ export default async function SubcategoryPage({
? (parseInt(store_page) - 1) * storesLimit
: 0

const storesTransaction = await getStores({
limit: storesLimit,
offset: storesOffset,
sort: "productCount.desc",
})
const storesTransaction = await getStores(searchParams)

return (
<Shell>
Expand All @@ -80,12 +66,12 @@ export default async function SubcategoryPage({
{`Buy the best ${unslugify(subcategory)}`}
</PageHeaderDescription>
</PageHeader>
<Products
{/* <Products
products={productsTransaction.data}
pageCount={productsTransaction.pageCount}
stores={storesTransaction.data}
storePageCount={storesTransaction.pageCount}
/>
/> */}
</Shell>
)
}
26 changes: 15 additions & 11 deletions src/app/sitemap.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { type MetadataRoute } from "next"
import { db } from "@/db"
import { products, stores } from "@/db/schema"
import { allPages, allPosts } from "contentlayer/generated"
import { desc, eq, sql } from "drizzle-orm"
import { products, stores } from "drizzle/schema"
import { count, desc, eq, sql } from "drizzle-orm"

import { productCategories } from "@/config/product"
import { getCategories, getSubcategories } from "@/lib/actions/product"
import { absoluteUrl } from "@/lib/utils"

export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
Expand All @@ -30,8 +30,8 @@ export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
.leftJoin(stores, eq(products.storeId, stores.id))
.groupBy(products.id)
.orderBy(
desc(sql<number>`count(${stores.stripeAccountId})`),
desc(sql<number>`count(${products.images})`),
desc(count(stores.stripeAccountId)),
desc(count(products.images)),
desc(products.createdAt)
)

Expand All @@ -40,15 +40,19 @@ export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
lastModified: new Date().toISOString(),
}))

const categoriesRoutes = productCategories.map((category) => ({
url: absoluteUrl(`/categories/${category.title}`),
const allCategories = await getCategories()

const categoriesRoutes = allCategories.map((category) => ({
url: absoluteUrl(`/collections/${category.slug}`),
lastModified: new Date().toISOString(),
}))

const subcategoriesRoutes = productCategories
.map((category) =>
category.subcategories.map((subcategory) => ({
url: absoluteUrl(`/categories/${category.title}/${subcategory.slug}`),
const allSubcategories = await getSubcategories()

const subcategoriesRoutes = allSubcategories
.map((s) =>
categoriesRoutes.map((c) => ({
url: absoluteUrl(`/collections/${c.url.split("/").pop()}/${s.slug}`),
lastModified: new Date().toISOString(),
}))
)
Expand Down
Loading

0 comments on commit 0933fe9

Please sign in to comment.