Skip to content

Commit

Permalink
Use sitemap index path for all sitemaps
Browse files Browse the repository at this point in the history
  • Loading branch information
josephfusco committed Sep 18, 2024
1 parent 90547e1 commit e639208
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions packages/faustwp-core/src/server/sitemaps/createSitemaps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ export async function createRootSitemapIndex(
throw new Error('Request object must have URL');
}

// get sitemapIndexPath config param
// fetch sitemap from WP
// Get the trimmed sitemap index path
const trimmedWpUrl = trim(getWpUrl(), '/');
const trimmedFrontendUrl = trim(frontendUrl, '/');
const trimmedSitemapIndexPath = trim(
Expand All @@ -75,10 +74,10 @@ export async function createRootSitemapIndex(
let sitemaps: SitemapSchemaSitemapElement[] = [];

if (!isUndefined(pages) && isArray(pages) && pages.length) {
const trimmedFaustPagesPart = `${trim(
SITEMAP_INDEX_PATH,
const trimmedFaustPagesPart = `${trimmedSitemapIndexPath}?sitemap=${trim(
FAUST_PAGES_PATHNAME,
'/',
)}?sitemap=${trim(FAUST_PAGES_PATHNAME, '/')}`;
)}`;
const sitemapFaustPagesUrl = `${trimmedFrontendUrl}/${trimmedFaustPagesPart}`;

sitemaps = [
Expand Down Expand Up @@ -170,11 +169,11 @@ export async function createRootSitemapIndex(
*
* @example
* Replaces http://headless.local/wp-sitemap-posts-page-1.xml with
* http://localhost:3000/wp-sitemap-posts-page-1.xml
* http://localhost:3000/sitemap_index.xml?sitemap=wp-sitemap-posts-page-1.xml
*/
wpSitemaps.forEach((sitemap) => {
const url = new URL(sitemap.loc);
const sitemapUrl = `${trim(frontendUrl, '/')}/sitemap.xml?sitemap=${trim(
const sitemapUrl = `${trimmedFrontendUrl}/${trimmedSitemapIndexPath}?sitemap=${trim(
url.pathname,
'/',
)}`;
Expand Down Expand Up @@ -293,11 +292,11 @@ export async function handleSitemapPath(
let urls: SitemapSchemaUrlElement[] = [];

/**
* Replace the existing WordPress URL in each "loc" with the headless URL
* Replace the existing WordPress URL in each "loc" with the frontend URL
*
* @example
* Replaces http://headless.local/wp-sitemap-posts-page-1.xml with
* http://localhost:3000/wp-sitemap-posts-page-1.xml
* Replaces http://headless.local/page-1/ with
* http://localhost:3000/page-1/
*/
wpSitemapUrls.forEach((url) => {
urls = [
Expand Down

0 comments on commit e639208

Please sign in to comment.