# SEO

Everything you need is already pre-filled from your `/data/config/metadata.js` file:

* title
* description
* type
* url
* OpenGraph
* Twitter Card

And so on ...

You can customize these metadata by calling `genPageMetadata` function on your page:

{% code title="app//categories/\[slug]/page.tsx" lineNumbers="true" %}

```typescript
import CategoryLayout from "@/app/layouts/CategoryLayout";
import { genPageMetadata } from "@/app/seo";
import { metadata } from "@/data/config/metadata";
import prisma from "@/lib/prisma";

export async function generateMetadata({
  params,
}: {
  params: { slug: string };
}) {
  const categoryData = prisma.category.findUnique({
    where: { slug: params.slug },
    select: {
      name: true,
      slug: true,
    },
  });
  const category = await categoryData;
  if (!category) {
    return genPageMetadata({
      title: "Category not found",
    });
  }
  return genPageMetadata({
    title: `Best ${category.name} ${metadata.productLabel}s`,
    description: `Find all the best ${category.name} ${metadata.productLabel}s.`,
    url: `/categories/${category.slug}`,
  });
}

export async function generateStaticParams() {
  const categoriesData = prisma.category.findMany();
  const categories = await categoriesData;
  return categories.map((category) => ({ slug: category.slug }));
}

export default function Category({ params }: { params: { slug: string } }) {
  return <CategoryLayout slug={params.slug} />;
}
```

{% endcode %}

{% hint style="info" %}
`genPageMetadata` can't be called on a client page *("use client")*, keep your `pages` file server side rendered and build a client layout.
{% endhint %}

### Indexing

* `/app/robots.ts` file will help crawling robots (Google, Bing) understand what pages you want to be indexed or not:

{% code title="/app/robots.ts" lineNumbers="true" %}

```typescript
import { MetadataRoute } from "next";

export default function robots(): MetadataRoute.Robots {
  return {
    rules: {
      userAgent: "*",
      allow: "/",
      disallow: [
        "/dashboard*",
        "/terms",
        "/privacy",
        "/stats",
        "/opengraph-image?",
      ],
    },
    sitemap: `${process.env.NEXT_PUBLIC_APP_URL}/sitemap.xml`,
    host: process.env.NEXT_PUBLIC_APP_URL,
  };
}
```

{% endcode %}

{% hint style="info" %}
Do not forget to claim your domain ownership on [Google Search Console](https://search.google.com/search-console).
{% endhint %}

* /app/sitemap.ts file adds automatically every new product or category to the sitemap so you don't have to request them manually, you can add your own logic if you wan't more pages to be added:

{% code title="app/sitemap.ts" lineNumbers="true" %}

```typescript
import { MetadataRoute } from "next";
import prisma from "@/lib/prisma";

export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
  const siteUrl = process.env.NEXT_PUBLIC_APP_URL;

  const categories = await prisma.category.findMany({
    ...
  });

  const categoryRoutes = categories.map((category) => {
    const lastModified = category.products[0]?.createdAt || category.createdAt;
    return {
      url: `${siteUrl}/categories/${category.slug}`,
      lastModified: lastModified.toISOString().split("T")[0],
    };
  });

  ...

  const mainRoute = {
    url: `${siteUrl}/`,
    lastModified: latestproduct
      ? latestproduct.createdAt.toISOString().split("T")[0]
      : new Date().toISOString().split("T")[0],
  };

  return [mainRoute, ...categoryRoutes, ...productRoutes];
}

```

{% endcode %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.directoryfa.st/features/seo.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
