SEO
Since version 3.4
This page contains the API reference for the SEO features.
API Reference
generateSitemap
A function that generates a Response containing the sitemap.xml file for
your site.
Route
The sitemap entries are served by default at the
/sitemap.xml
route.
The entries are generated based on:
- Static pages defined in your
app/routesor Remix config. - Dynamic pages which have implemented a
sitemap handleexport.
Params
| Name | Type | Description |
|---|---|---|
| loaderArgs | LoaderFunctionArgs | The loader arguments passed to the loader function. |
| options | SEOOptions | An object containing the options to generate the sitemap. |
Example
app/routes/sitemap[.xml].ts
import type { LoaderFunctionArgs } from "@remix-run/node";
import { FrontCommerceApp } from "@front-commerce/remix";
import { generateSitemap } from "@front-commerce/remix/seo";
export async function loader(loaderArgs: LoaderFunctionArgs) {
const app = new FrontCommerceApp(loaderArgs.context.frontCommerce);
return generateSitemap(loaderArgs, {
siteUrl: app.config.shop.url,
headers: new Headers({
"X-Example": "Acme",
}),
});
}
generateRobotsTxt
A function that generates a Response containing the robots.txt file for your
site.
Route
The robots file is served by default at the
/robots.txt
route.
The robots.txt will only allow crawling when the FRONT_COMMERCE_ENV is set
to production
Params
| Name | Type | Description |
|---|---|---|
| policies | RobotsPolicy | The entries to be included in the robots.txt file |
| config | RobotsConfig | An object containing the configuration for your robots.txt file |
Example
app/routes/robots[.txt].ts
import type { LoaderFunctionArgs } from "@remix-run/node";
import { FrontCommerceApp } from "@front-commerce/remix";
import { generateRobotsTxt } from "@front-commerce/remix/seo";
export function loader({ context }: LoaderFunctionArgs) {
const app = new FrontCommerceApp(context.frontCommerce);
return generateRobotsTxt(
[
{
type: "disallow",
value: new URL("/example", app.config.shop.url).toString(),
},
],
{
appendOnDefaultPolicies: true, // ensures that the default policies are included (default: true)
allowCrawling: app.env === "production",
headers: new Headers({
"X-Example": "Acme",
}),
}
);
}