Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit 5de8ab1

Browse files
committed
allow sitemaps to be tested
1 parent 43ef9f9 commit 5de8ab1

File tree

4 files changed

+10
-12
lines changed

4 files changed

+10
-12
lines changed

scripts/build-sitemap.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ const fs = require('fs/promises')
33
const excludedDirectories = ['[[...slug]]'] // ignore dynamic routes
44
const pages = []
55

6-
const URL = 'https://nitric.io/docs'
7-
86
const readDirRecursive = async (dir) => {
97
const files = await fs.readdir(dir)
108

@@ -14,11 +12,12 @@ const readDirRecursive = async (dir) => {
1412
if (stats.isDirectory() && !excludedDirectories.includes(file)) {
1513
await readDirRecursive(filePath)
1614
} else if (file.startsWith('page.')) {
17-
const loc = `${URL}${filePath
15+
const loc = filePath
1816
.replace('src/app', '')
1917
.replace('.tsx', '')
2018
.replace('.mdx', '')
21-
.replace('page', '')}`.replace(/\/$/, '')
19+
.replace('page', '')
20+
.replace(/\/$/, '')
2221

2322
pages.push(loc)
2423
}

scripts/cypress-fixtures.mjs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,14 @@ import { XMLParser } from 'fast-xml-parser'
44
const parser = new XMLParser()
55

66
import { allDocs } from '../.contentlayer/generated/index.mjs'
7-
import pages from '../src/assets/sitemap.json' with { type: 'json' }
7+
import basePages from '../src/assets/sitemap.json' with { type: 'json' }
88

99
const FIXTURE_PATH = 'cypress/fixtures/pages.json'
1010

1111
const PROD_PAGES_PATH = 'cypress/fixtures/prod_pages.json'
1212

1313
async function run() {
1414
try {
15-
const basePages = pages.map((p) => p.replace('https://nitric.io', ''))
16-
1715
const docPages = allDocs.map((doc) => {
1816
return doc.slug === '/' ? '/docs' : `/docs/${doc.slug}`
1917
})

src/app/(sitemaps)/sitemap-0.xml/route.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { allDocs } from '@/content'
22
import staticPaths from '@/assets/sitemap.json'
3+
import { BASE_URL } from '@/lib/constants'
34

4-
const URL = 'https://nitric.io/docs'
5+
const URL = `${BASE_URL}/docs`
56

67
interface SitemapItem {
78
loc: string
@@ -15,7 +16,7 @@ const lastmod = new Date().toISOString()
1516
// Function to construct the XML structure of the sitemap index.
1617
export async function GET() {
1718
const pages = staticPaths.map((page) => ({
18-
loc: page,
19+
loc: `${URL}${page}`,
1920
lastmod,
2021
changefreq: 'daily',
2122
priority: 0.7,

src/app/(sitemaps)/sitemap.xml/route.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
import { BASE_URL } from '@/lib/constants'
2+
13
// Function to construct the XML structure of the sitemap index.
24
export async function GET() {
3-
const sitemapIndexXML = buildSitemapIndex([
4-
'https://nitric.io/docs/sitemap-0.xml',
5-
])
5+
const sitemapIndexXML = buildSitemapIndex([`${BASE_URL}/docs/sitemap-0.xml`])
66

77
// Return the sitemap index XML with the appropriate content type.
88
return new Response(sitemapIndexXML, {

0 commit comments

Comments
 (0)