getSitemapProps Reference
getSitemapProps
is a server side helper function that facilitates the proxying of sitemaps from your WordPress site to your Faust frontend. It is a function that is returned from inside of a getServerSideProps
Next.js function.
Usage
The following code must be added to a sitemap.xml.js
or sitemap.xml.tsx
file in your pages
directory:
pages/sitemap.xml.js
import { getSitemapProps } from '@faustwp/core';
export default function Sitemap() {}
export function getServerSideProps(ctx) {
return getSitemapProps(ctx, {
frontendUrl: process.env.FRONTEND_URL, // Define your frontend URL as an env var
});
}
Config
Below is the getSitemapProps
config object defined as a TypeScript type:
type GetSitemapPropsConfig = {
/**
* REQUIRED: The URL of your Faust site.
*
* @example http://localhost:3000
* @example https://my-site.com
*/
frontendUrl: string;
/**
* A list of relative URLs to ignore when proxying sitemaps.
* Wild cards can be used to exclude certain types of sitemaps.
*
* @example ["/author-sitemap.xml"]
* @example ["/sitemap-tags-*"]
*/
sitemapPathsToIgnore?: string[];
/**
* Next.js pages you want included in you sitemap. When provided, an index
* will be created specifically for these pages.
*
* @example [ { path: "/about" } ]
*/
pages?: NextJSPage[];
};
And the shape of a NextJSPage
:
type NextJSPage = {
/**
* The relative URL of the Next.js page.
*
* @example /about
*/
path: string;
lastmod?: string;
changefreq?:
| 'always'
| 'hourly'
| 'daily'
| 'weekly'
| 'monthly'
| 'yearly'
| 'never';
priority?: number;
};