From d3a58c3ce7da23f29571d2c378af4984a8924dc2 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Fri, 28 Apr 2023 15:07:22 +0700 Subject: add sitemap --- src/pages/sitemap/brands.xml.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/pages/sitemap/brands.xml.js (limited to 'src/pages/sitemap/brands.xml.js') 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 +} -- cgit v1.2.3 From 7b12c20a46e4119e9a34ad15f9109765876a265b Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Thu, 4 May 2023 09:43:57 +0700 Subject: fixing sitemap --- src/pages/sitemap/brands.xml.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/pages/sitemap/brands.xml.js') diff --git a/src/pages/sitemap/brands.xml.js b/src/pages/sitemap/brands.xml.js index 7d16bde3..bfd21dba 100644 --- a/src/pages/sitemap/brands.xml.js +++ b/src/pages/sitemap/brands.xml.js @@ -7,7 +7,10 @@ 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 sitemap = create('urlset', { encoding: 'utf-8' }).att( + 'xmlns', + 'http://www.sitemaps.org/schemas/sitemap/0.9' + ) const date = new Date() brands.manufactures.forEach((brand) => { -- cgit v1.2.3 From 8bf81ed018dfd89b30f887c09689442881bb4872 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Thu, 4 May 2023 14:08:38 +0700 Subject: fixing sitemap --- src/pages/sitemap/brands.xml.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/pages/sitemap/brands.xml.js') diff --git a/src/pages/sitemap/brands.xml.js b/src/pages/sitemap/brands.xml.js index bfd21dba..c85c40e9 100644 --- a/src/pages/sitemap/brands.xml.js +++ b/src/pages/sitemap/brands.xml.js @@ -1,6 +1,4 @@ -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' @@ -18,7 +16,7 @@ export async function getServerSideProps({ res }) { 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') + url.ele('priority', '0.6') }) res.setHeader('Content-Type', 'text/xml') -- cgit v1.2.3