Home / Function/ generate() — supabase Function Reference

generate() — supabase Function Reference

Architecture documentation for the generate() function in generate-sitemap.ts from the supabase codebase.

Entity Profile

Dependency Diagram

graph TD
  73e1e3ea_8013_e415_5220_f8b3aaddba40["generate()"]
  79f786a3_419e_5b22_8aee_72f0fa0dadce["generateCLIPages()"]
  73e1e3ea_8013_e415_5220_f8b3aaddba40 -->|calls| 79f786a3_419e_5b22_8aee_72f0fa0dadce
  9513cc95_c002_d396_cdf4_a7b1f4ba7328["generateReferencePages()"]
  73e1e3ea_8013_e415_5220_f8b3aaddba40 -->|calls| 9513cc95_c002_d396_cdf4_a7b1f4ba7328
  style 73e1e3ea_8013_e415_5220_f8b3aaddba40 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

apps/docs/internals/generate-sitemap.ts lines 14–80

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

Subdomains

Frequently Asked Questions

What does generate() do?
generate() is a function in the supabase codebase.
What does generate() call?
generate() calls 2 function(s): generateCLIPages, generateReferencePages.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free