summaryrefslogtreecommitdiff
path: root/src/pages/sitemap/brands.xml.js
blob: 65a84e979b89dd0fbebf32d49dd280b8e2238f19 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { create } from 'xmlbuilder'
import { createSlug } from '@/core/utils/slug'
import odooApi from '@/core/api/odooApi'

export async function getServerSideProps({ res }) {
  const baseUrl = process.env.SELF_HOST + '/shop/brands/'
  const brands = await odooApi('GET', `/api/v1/manufacture?limit=0`)
  const sitemap = create('urlset', { encoding: 'utf-8' }).att(
    'xmlns',
    'http://www.sitemaps.org/schemas/sitemap/0.9'
  )

  const date = new Date()
  brands.manufactures.forEach((brand) => {
    const url = sitemap.ele('url')
    url.ele('loc', createSlug(baseUrl, brand.name, brand.id))
    url.ele('lastmod', date.toISOString().slice(0, 10))
    url.ele('changefreq', 'daily')
    url.ele('priority', '1.0')
  })

  res.setHeader('Content-Type', 'text/xml')
  res.write(sitemap.end())
  res.end()

  return { props: {} }
}

export default function SitemapProducts() {
  return null
}