summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRafi Zadanly <zadanlyr@gmail.com>2023-04-28 15:07:22 +0700
committerRafi Zadanly <zadanlyr@gmail.com>2023-04-28 15:07:22 +0700
commitd3a58c3ce7da23f29571d2c378af4984a8924dc2 (patch)
tree0a0a8f65f5bb089f6621d207818b12c1e6755534
parent9c2304361f829a8f0a28460ea8f14bebd00b2939 (diff)
add sitemap
-rw-r--r--src/pages/sitemap/brands.xml.js30
-rw-r--r--src/pages/sitemap/categories.xml.js40
-rw-r--r--src/pages/sitemap/products/[page].js2
3 files changed, 71 insertions, 1 deletions
diff --git a/src/pages/sitemap/brands.xml.js b/src/pages/sitemap/brands.xml.js
new file mode 100644
index 00000000..7d16bde3
--- /dev/null
+++ b/src/pages/sitemap/brands.xml.js
@@ -0,0 +1,30 @@
+import productSearchApi from '@/lib/product/api/productSearchApi'
+import { create } from 'xmlbuilder'
+import _ from 'lodash-contrib'
+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' })
+
+ 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', 'weekly')
+ url.ele('priority', '0.8')
+ })
+
+ res.setHeader('Content-Type', 'text/xml')
+ res.write(sitemap.end())
+ res.end()
+
+ return { props: {} }
+}
+
+export default function SitemapProducts() {
+ return null
+}
diff --git a/src/pages/sitemap/categories.xml.js b/src/pages/sitemap/categories.xml.js
new file mode 100644
index 00000000..676e7443
--- /dev/null
+++ b/src/pages/sitemap/categories.xml.js
@@ -0,0 +1,40 @@
+import productSearchApi from '@/lib/product/api/productSearchApi'
+import { create } from 'xmlbuilder'
+import _ from 'lodash-contrib'
+import { createSlug } from '@/core/utils/slug'
+import odooApi from '@/core/api/odooApi'
+
+export async function getServerSideProps({ res }) {
+ const categories = await odooApi('GET', '/api/v1/category/tree')
+ const sitemap = create('urlset', { encoding: 'UTF-8' })
+
+ categories.forEach((category) => {
+ addUrlToSitemap(sitemap, category.name, category.id)
+ category.childs.forEach((child1Category) => {
+ addUrlToSitemap(sitemap, child1Category.name, child1Category.id)
+ child1Category.childs.forEach((child2Category) => {
+ addUrlToSitemap(sitemap, child2Category.name, child2Category.id)
+ })
+ })
+ })
+
+ res.setHeader('Content-Type', 'text/xml')
+ res.write(sitemap.end())
+ res.end()
+
+ return { props: {} }
+}
+
+function addUrlToSitemap(sitemap, name, id) {
+ const baseUrl = process.env.SELF_HOST + '/shop/category/'
+ const date = new Date()
+ const url = sitemap.ele('url')
+ url.ele('loc', createSlug(baseUrl, name, id))
+ url.ele('lastmod', date.toISOString().slice(0, 10))
+ url.ele('changefreq', 'weekly')
+ url.ele('priority', '0.8')
+}
+
+export default function SitemapProducts() {
+ return null
+}
diff --git a/src/pages/sitemap/products/[page].js b/src/pages/sitemap/products/[page].js
index 6acddbaa..e465f0f5 100644
--- a/src/pages/sitemap/products/[page].js
+++ b/src/pages/sitemap/products/[page].js
@@ -28,5 +28,5 @@ export async function getServerSideProps({ query, res }) {
}
export default function SitemapProducts() {
- return <></>
+ return null
}