Skip to main content

getSiteMapProps

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, 
	}); 
}

Ensure that FRONTEND_URL is defined as an environment variable so that it is accessible via process.env.FRONTEND_URL.

Configuration

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 here is the shape of a NextJSPage object:

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;
};

The following example resolves a sitemap page using a combination of configuration parameters:

sitemap.xml.js
import { getSitemapProps } from "@faustwp/core";
 
export default function Sitemap() {}
 
export function getServerSideProps(ctx) {
	return getSitemapProps(ctx, {
		frontendUrl: "http://localhost:3000",
		sitemapPathsToIgnore: ["/author-sitemap.xml"],
		pages: [
			{
				path: "/example",
				changefreq: "daily",
				priority: 0.7,
			},
		],
	});
}

Hey there! I'm an AI driven chat assistant here to help you with Faust.js! I'm trained on the documentation and can help you with coding tasks, learning, and more. What can I assist you with today?