diff options
| -rw-r--r-- | src/pages/sitemap/blogs.xml.js | 31 | ||||
| -rw-r--r-- | src/pages/sitemap/brands.xml.js | 4 | ||||
| -rw-r--r-- | src/pages/sitemap/categories.xml.js | 4 |
3 files changed, 33 insertions, 6 deletions
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() { |
