mirror of
https://github.com/supabase/supabase.git
synced 2026-05-06 08:56:46 -04:00
3d8e5d9cfd
Set default priority in sitemap and lower auth-helper priority
83 lines
2.3 KiB
TypeScript
83 lines
2.3 KiB
TypeScript
/*
|
|
* kudos to leerob from vercel
|
|
* https://leerob.io/blog/nextjs-sitemap-robots
|
|
*/
|
|
|
|
import fs from 'fs'
|
|
import { globby } from 'globby'
|
|
import matter from 'gray-matter'
|
|
import prettier from 'prettier'
|
|
|
|
import { generateCLIPages } from './files/cli'
|
|
import { generateReferencePages } from './files/reference-lib'
|
|
|
|
async function generate() {
|
|
const cliPages = generateCLIPages()
|
|
const referencePages = await generateReferencePages()
|
|
|
|
const contentFiles = await globby(['content/guides/**/!(_)*.mdx'])
|
|
const contentPages = await Promise.all(
|
|
contentFiles.map(async (filePath) => {
|
|
const fileContents = await fs.promises.readFile(filePath, 'utf8')
|
|
const {
|
|
data: { sitemapPriority },
|
|
} = matter(fileContents)
|
|
|
|
return {
|
|
link: filePath.replace(/^content\//, '').replace(/\.mdx$/, ''),
|
|
priority: sitemapPriority ?? 0.8,
|
|
}
|
|
})
|
|
)
|
|
|
|
const troubleshootingFiles = await globby(['content/troubleshooting/**/!(_)*.mdx'])
|
|
const troubleshootingPages = await Promise.all(
|
|
troubleshootingFiles.map(async (filePath) => {
|
|
return {
|
|
link: filePath.replace(/^content/, 'guides').replace(/\.mdx$/, ''),
|
|
priority: 1,
|
|
}
|
|
})
|
|
)
|
|
|
|
const allPages = (contentPages as Array<{ link: string; priority: number }>).concat(
|
|
troubleshootingPages,
|
|
referencePages,
|
|
cliPages
|
|
)
|
|
|
|
const sitemap = `
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
|
${allPages
|
|
.map(({ link, priority }) => {
|
|
const finalPriority = priority ?? 0.8
|
|
return `
|
|
<url>
|
|
<loc>${`https://supabase.com/docs/${link}`}</loc>
|
|
<changefreq>weekly</changefreq>
|
|
<priority>${finalPriority}</priority>
|
|
</url>
|
|
`
|
|
})
|
|
.join('')}
|
|
</urlset>
|
|
`
|
|
|
|
const prettierConfig = await prettier.resolveConfig('./.prettierrc.js')
|
|
const formatted = await prettier.format(sitemap, {
|
|
...prettierConfig,
|
|
parser: 'html',
|
|
})
|
|
|
|
const sitemapFilePath = `public/sitemap.xml`
|
|
console.log(
|
|
`Total of ${allPages.length} pages in sitemap, located at /apps/docs/${sitemapFilePath}`
|
|
)
|
|
|
|
// eslint-disable-next-line no-sync
|
|
fs.writeFileSync(sitemapFilePath, formatted)
|
|
}
|
|
|
|
generate()
|