From 563de6cd65b2ff81fc26a5f92aef55c2f54219c2 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Thu, 27 Apr 2023 17:10:16 +0700 Subject: sitemap product detail --- src/pages/sitemap/products/[id].xml.js | 32 -------------------------------- src/pages/sitemap/products/[page].js | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 32 deletions(-) delete mode 100644 src/pages/sitemap/products/[id].xml.js create mode 100644 src/pages/sitemap/products/[page].js (limited to 'src/pages/sitemap') diff --git a/src/pages/sitemap/products/[id].xml.js b/src/pages/sitemap/products/[id].xml.js deleted file mode 100644 index 98c2bf40..00000000 --- a/src/pages/sitemap/products/[id].xml.js +++ /dev/null @@ -1,32 +0,0 @@ -import productSearchApi from '@/lib/product/api/productSearchApi' -import { create } from 'xmlbuilder' -import _ from 'lodash-contrib' -import { createSlug } from '@/core/utils/slug' - -export async function getServerSideProps({ res }) { - const baseUrl = process.env.SELF_HOST + '/shop/product' - const limit = 2500 - const query = { limit } - const products = await productSearchApi({ query: _.toQuery(query) }) - console.log(products) - // const sitemap = create('urlset', { encoding: 'UTF-8' }) - - // const date = new Date() - // pages.forEach((page) => { - // const url = sitemap.ele('url') - // url.ele('loc', createSlug(baseUrl, '', '')) - // 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 <> -} diff --git a/src/pages/sitemap/products/[page].js b/src/pages/sitemap/products/[page].js new file mode 100644 index 00000000..6acddbaa --- /dev/null +++ b/src/pages/sitemap/products/[page].js @@ -0,0 +1,32 @@ +import productSearchApi from '@/lib/product/api/productSearchApi' +import { create } from 'xmlbuilder' +import _ from 'lodash-contrib' +import { createSlug } from '@/core/utils/slug' + +export async function getServerSideProps({ query, res }) { + const baseUrl = process.env.SELF_HOST + '/shop/product/' + const { page } = query + const limit = 2500 + const queries = { limit, page: page.replace('.xml', '') } + const products = await productSearchApi({ query: _.toQuery(queries) }) + const sitemap = create('urlset', { encoding: 'UTF-8' }) + + const date = new Date() + products.response.products.forEach((product) => { + const url = sitemap.ele('url') + url.ele('loc', createSlug(baseUrl, product.name, product.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 <> +} -- cgit v1.2.3 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 +++++++++++++++++++++++++++ src/pages/sitemap/categories.xml.js | 40 ++++++++++++++++++++++++++++++++++++ src/pages/sitemap/products/[page].js | 2 +- 3 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 src/pages/sitemap/brands.xml.js create mode 100644 src/pages/sitemap/categories.xml.js (limited to 'src/pages/sitemap') 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 } -- 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 ++++- src/pages/sitemap/categories.xml.js | 5 ++++- src/pages/sitemap/products/[page].js | 5 ++++- 3 files changed, 12 insertions(+), 3 deletions(-) (limited to 'src/pages/sitemap') 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) => { diff --git a/src/pages/sitemap/categories.xml.js b/src/pages/sitemap/categories.xml.js index 676e7443..d9a11d71 100644 --- a/src/pages/sitemap/categories.xml.js +++ b/src/pages/sitemap/categories.xml.js @@ -6,7 +6,10 @@ 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' }) + const sitemap = create('urlset', { encoding: 'utf-8' }).att( + 'xmlns', + 'http://www.sitemaps.org/schemas/sitemap/0.9' + ) categories.forEach((category) => { addUrlToSitemap(sitemap, category.name, category.id) diff --git a/src/pages/sitemap/products/[page].js b/src/pages/sitemap/products/[page].js index e465f0f5..2f9c3198 100644 --- a/src/pages/sitemap/products/[page].js +++ b/src/pages/sitemap/products/[page].js @@ -9,7 +9,10 @@ export async function getServerSideProps({ query, res }) { const limit = 2500 const queries = { limit, page: page.replace('.xml', '') } const products = await productSearchApi({ query: _.toQuery(queries) }) - 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() products.response.products.forEach((product) => { -- cgit v1.2.3 From 64a60cc9c6a836cc574036bd4998f16ea945f3c2 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Thu, 4 May 2023 10:56:21 +0700 Subject: fix product sitemap --- src/pages/sitemap/products.xml.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/pages/sitemap') diff --git a/src/pages/sitemap/products.xml.js b/src/pages/sitemap/products.xml.js index e5fc8029..a2067308 100644 --- a/src/pages/sitemap/products.xml.js +++ b/src/pages/sitemap/products.xml.js @@ -9,7 +9,10 @@ export async function getServerSideProps({ res }) { const products = await productSearchApi({ query: _.toQuery(query) }) const pageCount = Math.ceil(products.response.numFound / limit) const pages = Array.from({ length: pageCount }, (_, i) => i + 1) - const sitemapIndex = create('sitemapindex', { encoding: 'UTF-8' }) + const sitemapIndex = create('sitemapindex', { encoding: 'UTF-8' }).att( + 'xmlns', + 'http://www.sitemaps.org/schemas/sitemap/0.9' + ) const date = new Date() pages.forEach((page) => { -- 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/blogs.xml.js | 31 +++++++++++++++++++++++++++++++ src/pages/sitemap/brands.xml.js | 4 +--- src/pages/sitemap/categories.xml.js | 4 +--- 3 files changed, 33 insertions(+), 6 deletions(-) create mode 100644 src/pages/sitemap/blogs.xml.js (limited to 'src/pages/sitemap') diff --git a/src/pages/sitemap/blogs.xml.js b/src/pages/sitemap/blogs.xml.js new file mode 100644 index 00000000..7f41ad0f --- /dev/null +++ b/src/pages/sitemap/blogs.xml.js @@ -0,0 +1,31 @@ +import { createSlug } from '@/core/utils/slug' +import blogsApi from '@/lib/blog/api/blogsApi' +import { create } from 'xmlbuilder' + +export async function getServerSideProps({ res }) { + const baseUrl = process.env.SELF_HOST + '/blog/' + const blogs = await blogsApi({ limit: 0, offset: 0 }) + const sitemap = create('urlset', { encoding: 'utf-8' }).att( + 'xmlns', + 'http://www.sitemaps.org/schemas/sitemap/0.9' + ) + + const date = new Date() + blogs.blogs.forEach((blog) => { + const url = sitemap.ele('url') + url.ele('loc', createSlug(baseUrl, blog.title, blog.id)) + url.ele('lastmod', date.toISOString().slice(0, 10)) + url.ele('changefreq', 'weekly') + url.ele('priority', '0.6') + }) + + 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/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') diff --git a/src/pages/sitemap/categories.xml.js b/src/pages/sitemap/categories.xml.js index d9a11d71..1c684576 100644 --- a/src/pages/sitemap/categories.xml.js +++ b/src/pages/sitemap/categories.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' @@ -35,7 +33,7 @@ function addUrlToSitemap(sitemap, name, id) { url.ele('loc', createSlug(baseUrl, name, id)) url.ele('lastmod', date.toISOString().slice(0, 10)) url.ele('changefreq', 'weekly') - url.ele('priority', '0.8') + url.ele('priority', '0.6') } export default function SitemapProducts() { -- cgit v1.2.3